protected void Page_Load(object sender, EventArgs e) { System.IO.Stream s = Request.InputStream; int count = 0; byte[] buffer = new byte[1024]; StringBuilder builder = new StringBuilder(); while ((count = s.Read(buffer, 0, 1024)) > 0) { builder.Append(Encoding.UTF8.GetString(buffer, 0, count)); } s.Flush(); s.Close(); s.Dispose(); PayLogHelper.WriteEvent(builder.ToString(), "扫呗支付"); //string testresponse = "{\"attach\":\"\",\"channel_trade_no\":\"4009262001201708186903067327\",\"end_time\":\"20170818160418\",\"key_sign\":\"b503c7c76e4df6379c6d43c5103595b9\",\"merchant_name\":\"45对接专用1号\",\"merchant_no\":\"852100210000005\",\"out_trade_no\":\"300508950021217081816035700005\",\"pay_type\":\"010\",\"receipt_fee\":\"10\",\"result_code\":\"01\",\"return_code\":\"01\",\"return_msg\":\"支付成功\",\"terminal_id\":\"30050895\",\"terminal_time\":\"20170818160255\",\"terminal_trace\":\"b609bfed0a8f4badaa5373d20b30a52c\",\"total_fee\":\"10\",\"user_id\":\"on9DrwJ7GgmOaxHBN_yIkSCeBZVo\"}"; JavaScriptSerializer jsonSerialize = new JavaScriptSerializer(); NotifyResponse ack = jsonSerialize.Deserialize <NotifyResponse>(builder.ToString()); //NotifyResponse ack = jsonSerialize.Deserialize<NotifyResponse>(testresponse); Response.ContentType = "application/json"; Response.HeaderEncoding = Encoding.UTF8; try { if (ack.CheckSign()) { if (ack.return_code == "01") { if (ack.result_code == "01") { string out_trade_no = ack.out_trade_no; decimal total_fee = Convert.ToDecimal(ack.total_fee); decimal payAmount = total_fee / 100; Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, SelttleType.LcswPay); } } Response.Write("{\"return_code\":\"01\",\"return_msg\":\"success\"}"); } else { Response.Write("{\"return_code\":\"02\",\"return_msg\":\"签名失败\"}"); } } catch (Exception ex) { Response.Write("{\"return_code\":\"02\",\"return_msg\":\"签名失败\"}"); PayLogHelper.WriteError(ex); } }
protected void Page_Load(object sender, EventArgs e) { System.IO.Stream s = Request.InputStream; int count = 0; byte[] buffer = new byte[1024]; StringBuilder builder = new StringBuilder(); while ((count = s.Read(buffer, 0, 1024)) > 0) { builder.Append(Encoding.GetEncoding("GBK").GetString(buffer, 0, count)); } s.Flush(); s.Close(); s.Dispose(); PayLogHelper.WriteEvent(builder.ToString(), "新大陆支付"); JavaScriptSerializer jsonSerialize = new JavaScriptSerializer(); PosStarCallback callback = jsonSerialize.Deserialize <PosStarCallback>(builder.ToString()); if (callback != null) { string out_trade_no = callback.TxnLogId; decimal total_fee = Convert.ToDecimal(callback.TxnAmt); decimal payAmount = total_fee / 100; Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, SelttleType.StarPos); #region MyRegion // Flw_Order order = Flw_OrderBusiness.GetOrderModel(out_trade_no); // if (order != null) // { // decimal PayCount = order.PayCount != null ? (decimal)order.PayCount * 100 : 0; //应付金额 // decimal FreePay = order.FreePay != null ? (decimal)order.FreePay * 100 : 0; //减免金额 // if (total_fee == PayCount - FreePay) // { // string payTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // string sql = string.Format("update Flw_Order set OrderStatus=2, RealPay='{0}', PayTime='{1}' where OrderID='{2}'", payAmount, payTime, out_trade_no); // XCCloudBLL.ExecuteSql(sql); // OrderPayNotify.AddOrderPayCache(out_trade_no, payAmount, payTime, 2); // sql = @"SELECT a.StoreID, SettleFee FROM Base_StoreInfo a // INNER JOIN Flw_Order b ON b.StoreID = a.StoreID // INNER JOIN Base_SettlePPOS c ON c.ID = a.SettleID // WHERE b.OrderID = '" + out_trade_no + "'"; // DataTable dt = XCCloudBLL.ExecuterSqlToTable(sql); // if (dt.Rows.Count > 0) // { // //获取当前结算费率,计算手续费 // double fee = Convert.ToDouble(dt.Rows[0]["SettleFee"]); // double d = Math.Round(Convert.ToDouble(payAmount) * fee, 2, MidpointRounding.AwayFromZero); //最小单位为0.01元 // if (d < 0.01) d = 0.01; // sql = "update Flw_Order set PayFee='" + d + "' where OrderID='" + out_trade_no + "'"; // XCCloudBLL.ExecuteSql(sql); // } // } // else // { // //支付异常 // //PayList.AddNewItem(out_trade_no, amount); // string sql = string.Format("update Flw_Order set OrderStatus=3, RealPay='{0}', PayTime=GETDATE() where OrderID='{1}'", payAmount, out_trade_no); // XCCloudBLL.ExecuteSql(sql); // } // } #endregion } Response.ContentType = "application/json"; Response.HeaderEncoding = Encoding.GetEncoding("GBK"); //string blank = ""; //blank = blank.PadLeft(64, ' '); //string responseWrite= string r = "{\"RspCode\":\"000000\",\"RspDes\":\"\"}"; //Response.Write(string.Format("{\"RspCode\":\"000000\",\"RspDes\":\"{0}\"}", blank)); Response.Write(r); }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestPost(); PayLogHelper.WriteEvent(Request.Form.ToString(), "支付宝支付"); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(AliPayConfig.charset, AliPayConfig.sign_type, AliPayConfig.pid, AliPayConfig.mapiUrl, AliPayConfig.alipay_public_key); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult && CheckParams())//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //商户订单号 string out_trade_no = Request.Form["out_trade_no"]; //支付宝交易号 string trade_no = Request.Form["trade_no"]; //获得支付总金额total_amount string total_amount = Request.Form["total_amount"]; //交易状态 //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,才是买家付款成功。 string trade_status = Request.Form["trade_status"]; //交易状态 if (trade_status == "TRADE_SUCCESS" || trade_status == "TRADE_FINISHED") { try { decimal amount = Convert.ToDecimal(total_amount); Flw_OrderBusiness.OrderPay(out_trade_no, amount, SelttleType.AliWxPay); } catch (Exception ex) { PayLogHelper.WriteError(ex); } Response.Write("success"); //请不要修改或删除 } else { Response.Write("fail"); } //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { //PayLogHelper.WriteEvent("支付宝验证失败"); Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
public WxPayData GetNotifyData() { //接收从微信后台POST过来的数据 System.IO.Stream s = Request.InputStream; int count = 0; byte[] buffer = new byte[1024]; StringBuilder builder = new StringBuilder(); while ((count = s.Read(buffer, 0, 1024)) > 0) { builder.Append(Encoding.UTF8.GetString(buffer, 0, count)); } s.Flush(); s.Close(); s.Dispose(); // string temp = @"<xml><appid><![CDATA[wx359e3843fe4c20e6]]></appid> //<bank_type><![CDATA[ABC_DEBIT]]></bank_type> //<cash_fee><![CDATA[1]]></cash_fee> //<device_info><![CDATA[100010_SC-201609020843]]></device_info> //<fee_type><![CDATA[CNY]]></fee_type> //<is_subscribe><![CDATA[Y]]></is_subscribe> //<mch_id><![CDATA[1264100601]]></mch_id> //<nonce_str><![CDATA[9551f570dc8b434a98c7fb5e95543664]]></nonce_str> //<openid><![CDATA[oaxaDv5ATDpyyTJjh03vl_x55a9I]]></openid> //<out_trade_no><![CDATA[03ad8b23b8554450b272b543bd5f9dbd]]></out_trade_no> //<result_code><![CDATA[SUCCESS]]></result_code> //<return_code><![CDATA[SUCCESS]]></return_code> //<sign><![CDATA[774AB611BAEF0D61B94AD5FD5DF3097D]]></sign> //<time_end><![CDATA[20170301141219]]></time_end> //<total_fee>1</total_fee> //<trade_type><![CDATA[NATIVE]]></trade_type> //<transaction_id><![CDATA[4009262001201703011791419767]]></transaction_id> //</xml>"; //转换数据格式并验证签名 WxPayData data = new WxPayData(); try { PayLogHelper.WriteEvent(builder.ToString(), "微信支付"); data.FromXml(builder.ToString()); string resule = data.GetValue("result_code").ToString(); if (resule == "SUCCESS") { string out_trade_no = data.GetValue("out_trade_no").ToString(); decimal total_fee = Convert.ToDecimal(data.GetValue("total_fee")); decimal payAmount = total_fee / 100; Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, SelttleType.AliWxPay); #region MyRegion //Flw_Order order = Flw_OrderBusiness.GetOrderModel(out_trade_no); //if (order != null) //{ // decimal PayCount = order.PayCount != null ? (decimal)order.PayCount * 100 : 0; //应付金额 // decimal FreePay = order.FreePay != null ? (decimal)order.FreePay * 100 : 0; //减免金额 // if (total_fee == PayCount - FreePay) // { // string payTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // string sql = string.Format("update Flw_Order set OrderStatus=2, RealPay='{0}', PayTime='{1}' where OrderID='{2}'", payAmount, payTime, out_trade_no); // XCCloudBLL.ExecuteSql(sql); // OrderPayNotify.AddOrderPayCache(out_trade_no, payAmount, payTime, 2); // sql = "SELECT SettleFee FROM Base_StoreInfo a, Base_SettleOrg b WHERE a.SettleID = b.ID AND a.StoreID = '" + order.StoreID + "'"; // DataTable dt = XCCloudBLL.ExecuterSqlToTable(sql); // if (dt.Rows.Count > 0) // { // //获取当前结算费率,计算手续费 // double fee = Convert.ToDouble(dt.Rows[0]["SettleFee"]); // double d = Math.Round(Convert.ToDouble(payAmount) * fee, 2, MidpointRounding.AwayFromZero); //最小单位为0.01元 // if (d < 0.01) d = 0.01; // sql = "update Flw_Order set PayFee='" + d + "' where OrderID='" + out_trade_no + "'"; // XCCloudBLL.ExecuteSql(sql); // } // } // else // { // //支付异常 // //PayList.AddNewItem(out_trade_no, amount); // string sql = string.Format("update Flw_Order set OrderStatus=3, RealPay='{0}', PayTime=GETDATE() where OrderID='{1}'", payAmount, out_trade_no); // XCCloudBLL.ExecuteSql(sql); // } //} #endregion } //data.FromXml(temp); } catch (WxPayException ex) { //若签名错误,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", ex.Message); Response.Write(res.ToXml()); Response.End(); } return(data); }