/// <summary> /// 接收微信支付成功通知 /// </summary> /// <param name="xmlContent">微信通知内容</param> /// <returns>通知处理结果</returns> public string WechatOrderPayNotify(string xmlContent) { string return_code = "", return_msg = ""; try { WeChatApi weChatApi = new WeChatApi(); WechatPayNotifyResponse response = weChatApi.PayNotify(xmlContent); if (response.IsSuccess) { return_code = "SUCCESS"; return_msg = "OK"; } else { return_code = "FAIL"; return_msg = "FAIL"; } } catch (Exception) { return_code = "FAIL"; return_msg = "FAIL"; } //返回通知处理结果 return string.Format("<xml><return_code><![CDATA[{0}]]></return_code><return_msg><![CDATA[{1}]]></return_msg></xml>", return_code, return_msg); }
public WechatPayNotifyResponse PayNotify(string xmlContent) { WechatPayNotifyResponse response = new WechatPayNotifyResponse(); Yw_PayLog log = new Yw_PayLog(); try { BeginLog(log, 0, "", PayLogStepEnum.微信支付回调, xmlContent); Dictionary <string, string> notify = ParseXml(xmlContent); response.IsSuccess = false; response.ReturnCode = notify.ContainsKey("return_code") ? notify["return_code"] : ""; response.ReturnMsg = notify.ContainsKey("return_msg") ? notify["return_msg"] : ""; response.AppId = notify.ContainsKey("appid") ? notify["appid"] : ""; response.MchId = notify.ContainsKey("mch_id") ? notify["mch_id"] : ""; response.ResultCode = notify.ContainsKey("result_code") ? notify["result_code"] : ""; response.ErrCode = notify.ContainsKey("err_code") ? notify["err_code"] : ""; response.ErrCodeDes = notify.ContainsKey("err_code_des") ? notify["err_code_des"] : ""; response.TradeType = notify.ContainsKey("trade_type") ? notify["trade_type"] : ""; response.OpenId = notify.ContainsKey("openid") ? notify["openid"] : ""; response.TotalFee = int.Parse(notify["total_fee"]); response.TransactionId = notify.ContainsKey("transaction_id") ? notify["transaction_id"] : ""; response.OutTradeNo = notify.ContainsKey("out_trade_no") ? notify["out_trade_no"] : ""; BeginLog(log, 0, response.OutTradeNo, PayLogStepEnum.微信支付回调, xmlContent); if (CheckSign(notify)) { if (response.ReturnCode == "SUCCESS" && response.ResultCode == "SUCCESS") { StudentOrderBll bll = new StudentOrderBll(); bll.OrderPayCallback(response.OutTradeNo, response.TransactionId, CashPayTypeEnum.微信, (decimal)(response.TotalFee * 1.0 / 100)); response.IsSuccess = true; EndLog(log, "Success", 1); SaveLog(log); } return(response); } throw new AbhsException(ErrorCodeEnum.WechatPayNotifyError, AbhsErrorMsg.ConstWechatPayNotifyError, 0); } catch (Exception ex) { EndLog(log, "Fail," + ex.Message + "|" + ex.StackTrace, 0); SaveLog(log); throw; } }