Esempio n. 1
0
        /// <summary>
        /// 获取响应结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="contentStr"></param>
        /// <returns></returns>
        protected T GetRespResult <T>(string contentStr) where T : WxPayBaseResp, new()
        {
            XmlDocument resultXml = null;
            var         dics      = XmlDicHelper.ChangXmlToDir(contentStr, ref resultXml);

            T t = new T {
                RespXml = resultXml
            };

            t.FromResContent(dics);

            if (dics.ContainsKey("sign"))
            {
                var encryptStr = string.Join("&", dics.Select(d =>
                {
                    if (d.Key != "sign" && !string.IsNullOrEmpty(d.Value))
                    {
                        return(string.Concat(d.Key, "=", d.Value));
                    }
                    return(string.Empty);
                }));
                var signStr = GetSign(encryptStr);

                if (signStr != t.sign)
                {
                    t.Ret     = (int)ResultTypes.ParaNotMeet;
                    t.Message = "返回的结果签名(sign)不匹配";
                }
            }
            return(t);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取响应结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="contentStr"></param>
        /// <returns></returns>
        protected T GetRespResult <T>(string contentStr) where T : WxPayBaseResp, new()
        {
            XmlDocument resultXml = null;
            var         dics      = XmlDicHelper.ChangXmlToDir(contentStr, ref resultXml);

            var t = new T {
                RespXml = resultXml
            };

            t.FromResContent(dics);

            if (dics.ContainsKey("sign"))
            {
                var sb    = new StringBuilder();
                var first = true;

                foreach (var d in dics.Where(d => d.Key != "sign" && !string.IsNullOrEmpty(d.Value)))
                {
                    if (first)
                    {
                        first = false;
                        sb.AppendFormat("{0}={1}", d.Key, d.Value);
                    }
                    else
                    {
                        sb.AppendFormat("&{0}={1}", d.Key, d.Value);
                    }
                }


                var encryptStr = sb.ToString();

                var signStr = GetSign(encryptStr);

                if (signStr != t.sign)
                {
                    t.ret     = (int)ResultTypes.ParaError;
                    t.message = "返回的结果签名(sign)不匹配";
                }
            }

            if (t.return_code.ToUpper() != "SUCCESS")
            {
                //通信结果处理,这个微信做的其实没意义,脱裤子放屁
                t.ret     = -1;
                t.message = t.return_msg;
            }
            else if (!t.IsSuccess())
            {
                //  请求数据结果处理
                t.message = GetErrMsg(t.err_code?.ToUpper());
            }

            return(t);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取响应结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="contentStr"></param>
        /// <returns></returns>
        protected T GetRespResult <T>(string contentStr) where T : WxPayBaseResp, new()
        {
            XmlDocument resultXml = null;
            var         dics      = XmlDicHelper.ChangXmlToDir(contentStr, ref resultXml);

            T t = new T {
                RespXml = resultXml
            };

            t.FromResContent(dics);

            if (dics.ContainsKey("sign"))
            {
                dics.Remove("sign");
                var encryptStr = string.Join("&", dics.Select(d =>
                {
                    if (!string.IsNullOrEmpty(d.Value))
                    {
                        return(string.Concat(d.Key, "=", d.Value));
                    }
                    return(string.Empty);
                }));
                var signStr = GetSign(encryptStr);

                if (signStr != t.sign)
                {
                    t.Ret     = (int)ResultTypes.ParaNotMeet;
                    t.Message = "返回的结果签名(sign)不匹配";
                }
            }

            if (t.return_code.ToUpper() != "SUCCESS")
            {
                //通信结果处理,这个其实没意义,脱裤子放屁
                t.Ret     = 0;
                t.Message = t.return_msg;
            }
            else if (!t.IsSuccess)
            {
                //  请求数据结果处理
                t.Message = GetErrMsg(t.err_code?.ToUpper());
            }

            return(t);
        }