protected void Page_Load(object sender, EventArgs e) { if (Request.RequestType == "POST") { try { StreamReader reader = new StreamReader(Request.InputStream); String xmlData = reader.ReadToEnd(); helper.ReceivePostXmlData(xmlData); LogUtil.WriteLog("Notify_接收post来的xmlData=" + xmlData); if (helper.CheckSign()) { Dictionary <string, string> dicBack = helper.GetParameter();//获取所有参数 if (dicBack != null && dicBack.Keys.Contains("return_code")) { if (dicBack["return_code"] == "SUCCESS") { LogUtil.WriteLog("return_code=SUCCESS"); if (dicBack["result_code"] == "SUCCESS") { LogUtil.WriteLog("result_code=SUCCESS"); string out_trade_no = dicBack["out_trade_no"];//商品订单号 LogUtil.WriteLog("out_trade_no=" + out_trade_no); //string attach_no = dicBack["attach"];//订单id //1.验证商户订单号是否被处理 //2.处理过直接返回成功,否则返回 //此处根据out_trade_no 处理业务数据 //attach 订单id string pid = dicBack["attach"]; LogUtil.WriteLog("待处理订单id=" + pid); or.UpdateOrderPay(pid, "微信支付", 2); //Response.Redirect("order-detail.aspx?id=" + pid); //处理业务数据结束 LogUtil.WriteLog("Notify_验证签名成功"); helper.SetReturnParameter("return_code", "SUCCESS"); helper.SetReturnParameter("return_msg", ""); } } if (dicBack["return_code"] == "FAIL") { LogUtil.WriteLog("Notify_验证签名成功"); helper.SetReturnParameter("return_code", "SUCCESS"); helper.SetReturnParameter("return_msg", dicBack["return_msg"]); } } } else { LogUtil.WriteLog("Notify_验证签名失败"); helper.SetReturnParameter("return_code", "FAIL"); helper.SetReturnParameter("return_msg", "签名失败"); } string xmlStr = helper.GetReturnXml(); LogUtil.WriteLog("Notify_返回xml=" + xmlStr); Response.ContentType = "text/xml"; Response.Clear(); Response.Write(xmlStr); // Response.End(); //Response.Redirect("order-detail.aspx?id=69"); } catch (Exception ex) { LogUtil.WriteLog("Notify_异常了" + ex); } finally { Response.End(); } } }
public static string Sign = ""; //为了获取预支付ID的签名 protected void Page_Load(object sender, EventArgs e) { //1.接受微信平台post 过来的XML信息 //2.验证签名,从XML中获取ProductID,获取产品信息 //2.1设置out_trade_no,total_fee,notify_url,trade_type,product_id 参数,提交统一接口 //3.提交统一接口后获取PrepayId //4.将PrepayId 和return 根据参数拼接生xml信息(其中包含生成的package参数)输出 if (Request.RequestType == "POST") { try { StreamReader reader = new StreamReader(Request.InputStream); String xmlData = reader.ReadToEnd(); helper.ReceivePostXmlData(xmlData); LogUtil.WriteLog("接收post来的xmlData=" + xmlData); if (helper.CheckSign()) { LogUtil.WriteLog("签名验证通过"); string proId = helper.GetXMLNode("product_id"); LogUtil.WriteLog("产品id=" + proId); string sql = " select * from ML_Order where nID=" + proId; DataTable dt = her.ExecuteDataTable(sql); if (dt.Rows.Count > 0) { int pri = Convert.ToInt32((Convert.ToDouble(dt.Rows[0]["OrderPrice"]) * 100)); #region 业务处理 helper.SetParameter("body", "马赛特酒品"); helper.SetParameter("out_trade_no", dt.Rows[0]["OrderCode"].ToString()); helper.SetParameter("total_fee", pri.ToString());//这里单位是分 helper.SetParameter("notify_url", "http://masetchina.com.cn/Web/NativeNotify.aspx"); helper.SetParameter("trade_type", "NATIVE"); helper.SetParameter("attach", proId); /*<xml><appid><![CDATA[wx657cc528349e9b62]]></appid> * <openid><![CDATA[oQq_ejvnwWaCWi8-xyV_dgyIu6XE]]></openid> * <mch_id><![CDATA[1232858102]]></mch_id> * <is_subscribe><![CDATA[Y]]></is_subscribe> * <nonce_str><![CDATA[Mpc7gr1JEXA41Yj4]]></nonce_str> * <product_id><![CDATA[85]]></product_id> * <body><![CDATA[马赛特酒品]]></body> * <out_trade_no><![CDATA[M20150410015830803]]></out_trade_no> * <total_fee><![CDATA[1]]></total_fee> * <notify_url><![CDATA[http://masetchina.com.cn/Web/NativeNotify.aspx]]></notify_url> * <trade_type><![CDATA[NATIVE]]></trade_type> * <sign><![CDATA[6950D2527F9F740BE65651CE72970BD2]]></sign> * </xml>*/ string prepay_id = helper.GetPrepayId(); LogUtil.WriteLog("prepay_id=" + prepay_id); if (!string.IsNullOrEmpty(prepay_id)) { helper.SetReturnParameter("return_code", "SUCCESS"); helper.SetReturnParameter("result_code", "SUCCESS"); helper.SetReturnParameter("prepay_id", prepay_id); helper.SetReturnParameter("appid", helper.GetAppId); helper.SetReturnParameter("mch_id", helper.GetMch_Id); helper.SetReturnParameter("nonce_str", WpPCHelper.TenpayUtil.getNoncestr()); } else { helper.SetReturnParameter("return_code", "SUCCESS"); //返回状态码 helper.SetReturnParameter("result_code", "FAIL"); //业务结果 helper.SetReturnParameter("err_code_des", "预订单生产失败"); LogUtil.WriteLog("预订单生产失败"); } #endregion } else { helper.SetReturnParameter("return_code", "SUCCESS"); //返回状态码 helper.SetReturnParameter("result_code", "FAIL"); //业务结果 helper.SetReturnParameter("err_code_des", "此订单无效"); //业务结果 LogUtil.WriteLog("订单数据获取失败"); } } else { helper.SetReturnParameter("return_code", "FAIL"); helper.SetReturnParameter("return_msg", "签名失败"); LogUtil.WriteLog("签名验证没有通过"); } string xmlStr = helper.GetReturnXml(); LogUtil.WriteLog("返回xml=" + xmlStr); Response.ContentType = "text/xml"; Response.Clear(); Response.Write(xmlStr); // Response.End(); } catch (Exception ex) { LogUtil.WriteLog("异常了" + ex); } finally { Response.End(); } } }