Example #1
0
        /// <summary>
        /// 微信支付通知(貌似比较臃肿,待优化)
        /// </summary>
        /// <returns></returns>
        public void Notify()
        {
            ReturnMessage returnMsg = new ReturnMessage()
            {
                Return_Code = "SUCCESS", Return_Msg = ""
            };
            string        xmlString = GetXmlString(Request);
            NotifyMessage message   = null;

            try
            {
                //此处应记录日志
                message = HttpClientHelper.XmlDeserialize <NotifyMessage>(xmlString);

                #region 验证签名并处理通知
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlString);

                Dictionary <string, string> dic = new Dictionary <string, string>();
                string sign = string.Empty;
                foreach (XmlNode node in doc.FirstChild.ChildNodes)
                {
                    if (node.Name.ToLower() != "sign")
                    {
                        dic.Add(node.Name, node.InnerText);
                    }
                    else
                    {
                        sign = node.InnerText;
                    }
                }

                UnifiedWxPayModel model = UnifiedWxPayModel.CreateUnifiedModel(WeiXinConst.AppId, WeiXinConst.PartnerId, WeiXinConst.PartnerKey);
                if (model.ValidateMD5Signature(dic, sign))
                {
                    //处理通知
                }
                else
                {
                    throw new Exception("签名未通过!");
                }

                #endregion
            }
            catch (Exception ex)
            {
                //此处记录异常日志
                returnMsg.Return_Code = "FAIL";
                returnMsg.Return_Msg  = ex.Message;
            }
            Response.Write(returnMsg.ToXmlString());
            Response.End();
        }
Example #2
0
        public override void VerifyNotify(int timeout, PayeeInfo payee, GatewayInfo gateway)
        {
            if (param.Count < 1 ||
                string.IsNullOrWhiteSpace(gateway.Data) ||
                gateway.DataList.Count < 4)
            {
                this.OnNotifyVerifyFaild();
                log.AppendFormat(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " YSWL.Payment.PaymentInterface.WeChat.v3.WeChatNotify CHECK GATEWAY DATA 验证失败:" + gateway.DataList.Count);
                Core.Globals.WriteText(log);
                return;
            }

            //if ((((notify_id == null) || (partner == null) || (trade_state == null)) || ((transaction_id == null) ||
            //    (total_fee == null))) || (((out_trade_no == null) || (trade_mode == null))))
            //{
            //    this.OnNotifyVerifyFaild();

            //}
            //else if (!trade_mode.Equals("1") || !trade_state.Equals("0"))
            //{
            //    this.OnNotifyVerifyFaild();
            //}

            try
            {
                UnifiedWxPayModel model = UnifiedWxPayModel.CreateUnifiedModel(gateway.DataList[3], payee.Partner, payee.PrimaryKey);
                if (!model.ValidateMD5Signature(param, sign))
                {
                    log.AppendFormat(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " YSWL.Payment.PaymentInterface.WeChat.v3.WeChatNotify.OnNotifyVerifyFaild 验证失败:" + param + "|sign:" + sign);
                    this.OnNotifyVerifyFaild();
                }
                else
                {
                    //log.AppendFormat(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " YSWL.Payment.PaymentInterface.WeChat.v3.WeChatNotify.OnPaidToMerchant 处理通知成功!");
                    //处理通知
                    this.OnPaidToMerchant();
                }
            }
            catch (Exception ex)
            {
                //此处记录异常日志
                log.AppendFormat(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " YSWL.Payment.PaymentInterface.WeChat.v3.WeChatNotify.VerifyNotify 验证失败:" + ex.Message);
            }
            this.OnNotifyVerifyFaild();
            if (log.Length > 0)
            {
                Core.Globals.WriteText(log);
            }
        }