public string UpdateOrder(string id) { LogHelper.WriteLog("支付返回:" + id, LogHelper.LogType.Debug); if (id != "wxpay") { NameValueCollection collection = HttpContext.Current.Request.Form; String[] requestItem = HttpContext.Current.Request.Form.AllKeys; IDictionary <string, string> sArray = new Dictionary <string, string>(); for (int i = 0; i < requestItem.Length; i++) { sArray.Add(requestItem[i], collection[requestItem[i]]); } LogHelper.WriteLog("支付返回:" + JsonConvert.SerializeObject(sArray), LogHelper.LogType.Debug); var success = AlipaySignature.RSACheckV1(sArray, Ali_PUBLIC_KEY, CHARSET, "RSA2", false); if (!success) { return("fail"); } var orderno = sArray["out_trade_no"]; var trade_no = sArray["trade_no"]; var sign = bll.UpdateOrder(orderno, trade_no); return(sign.Success ? "success" : "fail"); } else { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context HttpRequestBase request = context.Request; //定义传统request对象 var verifyResult = "false"; var requestXml = WeiXinUtil.GetRequestXmlData(request); var dic = WeiXinUtil.FromXml(requestXml); LogHelper.WriteLog("支付返回:" + JsonConvert.SerializeObject(dic), LogHelper.LogType.Debug); var returnCode = WeiXinUtil.GetValueFromDic <string>(dic, "return_code"); if (!string.IsNullOrEmpty(returnCode) && returnCode == "SUCCESS")//通讯成功 { var result = WeiXinUtil.WePayNotifyValidation(dic); if (result) { var transactionid = WeiXinUtil.GetValueFromDic <string>(dic, "transaction_id"); if (!string.IsNullOrEmpty(transactionid)) { var queryXml = WeiXinUtil.BuildQueryRequest(transactionid, dic); var queryResult = WeiXinUtil.Post("https://api.mch.weixin.qq.com/pay/orderquery", queryXml); var queryReturnDic = WeiXinUtil.FromXml(queryResult); if (WeiXinUtil.ValidatonQueryResult(queryReturnDic))//查询成功 { verifyResult = "true"; var status = WeiXinUtil.GetValueFromDic <string>(dic, "result_code"); if (!string.IsNullOrEmpty(status) && status == "SUCCESS") { //var order = new Order() //{ // OrderNumber = WeiXinUtil.GetValueFromDic<string>(dic, "out_trade_no"), // TransactionId = transactionid, // ProductPrice = WeiXinUtil.GetValueFromDic<decimal>(dic, "total_fee") / 100, // TradeType = WeiXinUtil.GetValueFromDic<string>(dic, "trade_type"), // BankType = WeiXinUtil.GetValueFromDic<string>(dic, "bank_type"), // PayDate = DateTime.Parse(WeiXinUtil.GetValueFromDic<string>(dic, "time_end")), // StatusId = 1, // IsPresent = false, // AddDate = DateTime.Now, // IsDelete = false //}; //CURD.Add(order, ConfigHelper.WriteDB); var orderNo = WeiXinUtil.GetValueFromDic <string>(dic, "out_trade_no"); var sign = bll.UpdateOrder(orderNo, transactionid); return(WeiXinUtil.BuildReturnXml("SUCCESS", "成功")); } } else { return(WeiXinUtil.BuildReturnXml("FAIL", "订单查询失败")); } } else { return(WeiXinUtil.BuildReturnXml("FAIL", "支付结果中微信订单号不存在")); } } else { return(WeiXinUtil.BuildReturnXml("FAIL", "签名失败")); } } else { string returnmsg; dic.TryGetValue("return_msg", out returnmsg); throw new Exception("异步通知错误:" + returnmsg); } return(WeiXinUtil.BuildReturnXml("FAIL", "签名失败"));; } }