protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sArrary = GetRequestGet(); ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的////////////////////// ZoomLa.BLL.B_PayPlat payBLL = new ZoomLa.BLL.B_PayPlat(); DataTable pay = payBLL.GetPayPlatByClassid(12); ZoomLa.Model.M_Alipay_config con = new ZoomLa.Model.M_Alipay_config(); if (pay == null || pay.Rows.Count < 1) { function.WriteErrMsg("请先配置支付平台信息!![系统设置-->支付平台-->在线支付平台]"); } string partner = pay.Rows[0]["AccountID"].ToString(); string key = pay.Rows[0]["MD5Key"].ToString(); string input_charset = con.Input_charset; string sign_type = con.Sign_type; string transport = con.Transport; ////////////////////////////////////////////////////////////////////////////////////////////// if (sArrary.Count > 0)//判断是否有带返回参数 { B_Alipay_notify aliNotify = new B_Alipay_notify(sArrary, Request.QueryString["notify_id"], partner, key, input_charset, sign_type, transport); //AlipayNotify aliNotify = new AlipayNotify(sArrary, Request.QueryString["notify_id"], partner, key, input_charset, sign_type, transport); string responseTxt = aliNotify.ResponseTxt; //获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求 string sign = Request.QueryString["sign"]; //获取支付宝反馈回来的sign结果 string mysign = aliNotify.Mysign; //获取通知返回后计算后(验证)的签名结果 //写日志记录(若要调试,请取消下面两行注释) //string sWord = "responseTxt=" + responseTxt + "\n return_url_log:sign=" + Request.QueryString["sign"] + "&mysign=" + mysign + "\n return回来的参数:" + aliNotify.PreSignStr; //AlipayFunction.log_result(Server.MapPath("log/" + DateTime.Now.ToString().Replace(":", "")) + ".txt",sWord); //判断responsetTxt是否为ture,生成的签名结果mysign与获得的签名结果sign是否一致 //responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 //mysign与sign不等,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 if (responseTxt == "true" && sign == mysign)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 string trade_no = Request.QueryString["trade_no"]; //支付宝交易号 string order_no = Request.QueryString["out_trade_no"]; //获取订单号 string total_fee = Request.QueryString["total_fee"]; //获取总金额 string subject = Request.QueryString["subject"]; //商品名称、订单名称 string body = Request.QueryString["body"]; //商品描述、订单备注、描述 string buyer_email = Request.QueryString["buyer_email"]; //买家支付宝账号 //string receive_name = Request["receive_name"]; //收货人姓名 //string receive_address = Request["receive_address"];//收货人地址 //string receive_zip = Request["receive_zip"]; //收货人邮编 //string receive_phone = Request["receive_phone"]; //收货人电话 //string receive_mobile = Request["receive_mobile"]; //收货人手机 string trade_status = Request.QueryString["trade_status"]; //交易状态 //打印页面 lbTrade_no.Text = trade_no; lbOut_trade_no.Text = order_no; lbTotal_fee.Text = total_fee; lbSubject.Text = subject; lbBody.Text = body; lbBuyer_email.Text = buyer_email; lbTrade_status.Text = trade_status; lbVerify.Text = "验证成功"; if (Request.QueryString["trade_status"] == "WAIT_SELLER_SEND_GOODS" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")//买家已经付款,等待卖家发货 { M_Payment payMod = payBll.SelModelByPayNo(order_no); M_OrderList omod = orderBll.SelModelByOrderNo(payMod.PaymentNum.Split(',')[0]); LbName.Text = omod.Receiver; LbAddress.Text = omod.Jiedao; LbZip.Text = omod.ZipCode; LbPhone.Text = omod.Phone; LbMobile.Text = omod.Mobile.ToString(); FinalStep(omod); } else if (Request.QueryString["trade_status"] == "TRADE_FINISHED")//交易成功结束 { lbVerify.Text = "该交易已经成功结束!"; } else { Response.Write("trade_status=" + Request.QueryString["trade_status"]); } } else//验证失败 { lbVerify.Text = "验证失败"; } } else { lbVerify.Text = "无返回参数"; } }
protected void Page_Load(object sender, EventArgs e) { //DataTable pay = payPlatBll.GetPayPlatByClassid(12); M_PayPlat platMod = payPlatBll.SelModelByClass(M_PayPlat.Plat.Alipay_Instant); SortedDictionary <string, string> sArrary = GetRequestPost(); ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的////////////////////// ZoomLa.Model.M_Alipay_config con = new ZoomLa.Model.M_Alipay_config(); string partner = platMod.AccountID; string key = platMod.MD5Key; string input_charset = con.Input_charset; string sign_type = con.Sign_type; string transport = con.Transport; ////////////////////////////////////////////////////////////////////////////////////////////// if (sArrary.Count > 0)//判断是否有带返回参数 { ZoomLa.BLL.B_Alipay_notify aliNotify = new ZoomLa.BLL.B_Alipay_notify(sArrary, Request.Form["notify_id"], partner, key, input_charset, sign_type, transport); string responseTxt = aliNotify.ResponseTxt; //获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求 string sign = Request.Form["sign"]; string mysign = aliNotify.Mysign; //获取通知返回后计算后(验证)的签名结果 //判断responsetTxt是否为ture,生成的签名结果mysign与获得的签名结果sign是否一致 //responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 //mysign与sign不等,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 string order_no = Request.Form["out_trade_no"]; //获取订单号 ZLLog.L(ZLEnum.Log.pay, PayPlat + aliNotify.ResponseTxt + ":" + order_no + ":" + Request.Form["buyer_email"] + ":" + Request.Form["trade_status"] + ":" + Request.Form["price"] + ":" + Request.Form["subject"]); if (responseTxt == "true" && sign == mysign) //验证成功 { //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取通知返回参数,可参考技术文档中服务器异步通知参数列表 string trade_no = Request.Form["trade_no"]; //交易号 string total_fee = Request.Form["price"]; //获取总金额 string subject = Request.Form["subject"]; //商品名称、 string body = Request.Form["body"]; //商品描述、订单备注、描述 string buyer_email = Request.Form["buyer_email"]; //买家账号 string trade_status = Request.Form["trade_status"]; //交易状态 if (Request.Form["trade_status"] == "WAIT_BUYER_PAY") //没有付款 { } else if (trade_status.Equals("WAIT_SELLER_SEND_GOODS"))//付款成功,但是卖家没有发货 { } else if (trade_status.Equals("TRADE_SUCCESS"))//付款成功 { try { M_Payment pinfo = payBll.SelModelByPayNo(order_no); if (pinfo.Status != (int)M_Payment.PayStatus.NoPay) { return; } pinfo.Status = (int)M_Payment.PayStatus.HasPayed; pinfo.PlatformInfo = PayPlat; //平台反馈信息 pinfo.SuccessTime = DateTime.Now; //交易成功时间 pinfo.CStatus = true; //处理状态 pinfo.AlipayNO = trade_no; //保存支付宝交易号 pinfo.MoneyTrue = Convert.ToDouble(total_fee); payBll.Update(pinfo); DataTable orderDT = orderBll.GetOrderbyOrderNo(pinfo.PaymentNum); foreach (DataRow dr in orderDT.Rows) { M_Order_PayLog paylogMod = new M_Order_PayLog(); M_OrderList orderMod = orderBll.SelModelByOrderNo(dr["OrderNo"].ToString()); OrderHelper.FinalStep(pinfo, orderMod, paylogMod); orderCOM.SendMessage(orderMod, paylogMod, "payed"); } Response.Write("success"); ZLLog.L(ZLEnum.Log.pay, PayPlat + "成功!支付单:" + order_no); } catch (Exception ex) { ZLLog.L(ZLEnum.Log.pay, new M_Log() { Action = "支付回调报错", Message = PayPlat + ",支付单:" + order_no + ",原因:" + ex.Message }); } } else if (Request.Form["trade_status"] == "WAIT_BUYER_CONFIRM_GOODS")//卖家已经发货,等待买家确认 { } else if (Request.Form["trade_status"] == "TRADE_FINISHED") { } else//其他状态判断。普通即时到帐中,其他状态不用判断,直接打印success。 { ZLLog.L(PayPlat + "付款未成功截获,单号:[" + trade_status + "]"); } } else//验证失败 { ZLLog.L(ZLEnum.Log.pay, new M_Log() { Action = "支付验证失败", Message = PayPlat + ",支付单:" + order_no }); Response.Write("fail"); } } else { Response.Write("success"); } }
protected void Page_Load(object sender, EventArgs e) { Call.SetBreadCrumb(Master, "<li>商城管理</li><li>店铺订单</li><li>订单详情</li>"); B_PayPlat paybll = new B_PayPlat(); DataTable pay = paybll.GetPayPlatByClassid(1); ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的//////////////////////////// ZoomLa.Model.M_Alipay_config con = new ZoomLa.Model.M_Alipay_config(); string input_charset = con.Input_charset; string sign_type = con.Sign_type; ///////////////////////请求参数///////////////////////////////////////////////////////////////////// //--------------必填参数-------------- //支付宝交易号。它是登录支付宝网站在交易管理中查询得到,一般以8位日期开头的纯数字(如:20100419XXXXXXXXXX) string trade_no = Request.QueryString["trade_no"]; //物流公司名称 string logistics_name = Request.QueryString["logistics_name"]; //物流发货单号 string invoice_no = Request.QueryString["invoice_no"]; //物流发货时的运输类型,三个值可选:POST(平邮)、EXPRESS(快递)、EMS(EMS) string transport_type = Request.QueryString["transport_type"]; int id = Convert.ToInt32(Request.QueryString["id"] + ""); String Email = Request.QueryString["email"]; //卖家本地电脑IP地址 string seller_ip = ""; //构造请求函数 B_Alipay_shipments_service aliService = new B_Alipay_shipments_service( pay.Rows[0]["AccountID"].ToString(), trade_no, logistics_name, invoice_no, transport_type, seller_ip, pay.Rows[0]["MD5Key"].ToString(), input_charset, sign_type); /***********************含XML远程解析***********************/ //注意:远程解析XML出错,与IIS服务器配置有关 string url = aliService.Create_url(); XmlTextReader Reader = new XmlTextReader(url); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Reader); //解析XML,获取XML返回的数据,如:请求处理是否成功、商家网站唯一订单号、支付宝交易号、发货时间等 string nodeIs_success = xmlDoc.SelectSingleNode("/alipay/is_success").InnerText; string nodeOut_trade_no = ""; string nodeTrade_no = ""; string nodeTrade_status = ""; string nodeLast_modified_time = ""; string nodeError = ""; if (nodeIs_success == "T") { nodeOut_trade_no = xmlDoc.SelectSingleNode("/alipay/response/tradeBase/out_trade_no").InnerText; nodeTrade_no = xmlDoc.SelectSingleNode("/alipay/request").ChildNodes[2].InnerText; nodeTrade_status = xmlDoc.SelectSingleNode("/alipay/response/tradeBase/trade_status").InnerText; nodeLast_modified_time = xmlDoc.SelectSingleNode("/alipay/response/tradeBase/last_modified_time").InnerText; fahuo(id, Email); } else { nodeError = xmlDoc.SelectSingleNode("/alipay/error").InnerText; } //打印页面 StringBuilder sbHtml = new StringBuilder(); sbHtml.Append("<table boder='2' class=border width=350 cellpadding=5 cellspacing=0>"); sbHtml.Append("<tr><td align=center colspan=2>发货结果</td></tr>"); String successInfo = nodeIs_success == "T" ? "成功" : "失败"; sbHtml.Append("<tr><td align=right>请求处理是否成功:</td><td = align=left>" + successInfo + "</td></tr>"); if (nodeIs_success == "T") { sbHtml.Append("<tr><td align=right>商户网站订单号:</td><td class=font_content align=left>" + nodeOut_trade_no + "</td></tr>"); sbHtml.Append("<tr><td align=right>交易状态:</td><td = align=left>" + nodeTrade_status + "</td></tr>"); sbHtml.Append("<tr><td align=right>发货时间等:</td><td = align=left>" + nodeLast_modified_time + "</td></tr>"); } else { String errorInfo = String.Empty; switch (nodeError) { case "ILLEGAL_ARGUMENT": errorInfo = @"参数不正确:<br> 1)、承运公司名称(logistics_name)长度1到64,承运单号码(invoice_no)长度1到32。<br> 2)、IP不正确。<br> 3)、货运方式(transport_type),交易创建时的货运方式(create_transport_type)错误。<br> 4)、交易号(trade_no)不能为空<br>。 5)、物流名称(logistics_name)错误。"; break; case "TRADE_NOT_EXIST": errorInfo = @"外部交易不存在:<br> 1)、交易号不正确。<br> 2)、非平台商的交易。"; break; case "GENERIC_FAILURE": errorInfo = "执行命令错误"; break; default: errorInfo = "未知错误"; break; } sbHtml.Append("<tr><td align=right valign=top>错误:</td><td align=left>" + errorInfo + "</td></tr>"); } sbHtml.Append("</table>"); LblXml.Text = sbHtml.ToString(); //////////////////////////////////////////////////////////////////////////////////////////////////// //请在此处编写商户发货成功后的业务逻辑程序代码,以便把商户网站里的该笔订单与支付宝的订单信息同步。 /////////////////////////////////////////////////////////////////////////////////////////////////// }