/// <summary> /// 微信支付通知 /// </summary> /// <returns></returns> public ActionResult PayNotify() { string successXml = "<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>"; string failXml = "<xml><return_code><![CDATA[FAIL]]></return_code></xml>"; try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Request.InputStream); //全部参数 SortedDictionary <string, string> parametersAll = new SortedDictionary <string, string>(); foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes) { string key = item.Name; string value = item.InnerText; if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value))) { parametersAll.Add(key, value); } } xmlDoc.Save(string.Format("E:\\WXPay\\{0}_Notify.xml", parametersAll["out_trade_no"]));//写入日志 if (MicroMessenger.CommonUtil.VerifySign(parametersAll, BLLConfig.Get("wx_mchsecret"))) { string orderNo = parametersAll["out_trade_no"].ToString(); if (orderNo.StartsWith("T")) { if (BLLNewsOrder.WXPaySuccess(orderNo, parametersAll["transaction_id"])) { return(Content(successXml)); } } else if (BLLNews.WXPaySuccess(orderNo, parametersAll["transaction_id"])) { return(Content(successXml)); } } } catch (Exception ex) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"E:\WXPay\Error.txt", true, Encoding.GetEncoding("UTF-8"))) { sw.WriteLine(ex.ToString()); } } return(Content(failXml)); }