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) { 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("无通知参数"); } }