Esempio n. 1
0
        public override BaseResult VerifyCallBack(HttpRequest request)
        {
            var result = new AlipayResult();

            var coll = (string.IsNullOrEmpty(request.Form["out_trade_no"]) ? request.QueryString : request.Form);

            result.TradeNum   = coll["out_trade_no"];
            result.Amount     = Convert.ToDecimal(coll["total_fee"]);
            result.BuyerEmail = coll["buyer_email"];

            //支付宝ATN验证
            var verifyUrl = string.Format(Configs.VerifyUrl + "&partner={0}&notify_id={1}", Configs.GetPartnerId(),
                                          coll["notify_id"]);
            var responseText = Utils.GetHttp(verifyUrl, 120 * 1000);

            if (responseText != "true")
            {
                result.State  = false;
                result.ErrMsg = "支付宝ATN验证无效!";
                return(result);
            }

            //签名验证 Start...

            int i;

            // Get names of all forms into a string array.
            String[] requestarr = coll.AllKeys;

            //进行排序;
            string[] sortedstr = Digest.BubbleSort(requestarr);

            //构造待md5摘要字符串 ;

            var prestr = new StringBuilder();

            for (i = 0; i < sortedstr.Length; i++)
            {
                var noIn = new[] { "subdomain", "urlpath", "param", "sign", "sign_type" };
                if (!string.IsNullOrEmpty(coll[sortedstr[i]]) && !noIn.Contains(sortedstr[i]))
                {
                    if (i == sortedstr.Length - 1)
                    {
                        prestr.Append(sortedstr[i] + "=" + coll[sortedstr[i]]);
                    }
                    else
                    {
                        prestr.Append(sortedstr[i] + "=" + coll[sortedstr[i]] + "&");
                    }
                }
            }
            prestr.Append(Configs.GetKey());

            //生成Md5摘要;
            var ourSign = Digest.GetMd5(prestr.ToString(), Configs.Charset);
            //*******加密签名程序结束*******

            var sign = coll["sign"];

            if (sign != ourSign)
            {
                result.State  = false;
                result.ErrMsg = "签名验证失败-" + sign + " | " + ourSign;
            }
            var state = new[] { "TRADE_FINISHED", "TRADE_SUCCESS" };

            result.TradeStatus = coll["trade_status"];
            if (!state.Contains(result.TradeStatus))
            {
                result.State  = false;
                result.ErrMsg = "支付状态失败!";
            }
            else
            {
                result.State = true;
            }
            return(result);
        }
Esempio n. 2
0
        public override BaseResult VerifyCallBack(HttpRequest request)
        {
            var result = new AlipayResult();

            var coll = (string.IsNullOrEmpty(request.Form["out_trade_no"]) ? request.QueryString : request.Form);

            result.TradeNum = coll["out_trade_no"];
            result.Amount = Convert.ToDecimal(coll["total_fee"]);
            result.BuyerEmail = coll["buyer_email"];

            //支付宝ATN验证
            var verifyUrl = string.Format(Configs.VerifyUrl + "&partner={0}&notify_id={1}", Configs.GetPartnerId(),
                                          coll["notify_id"]);
            var responseText = Utils.GetHttp(verifyUrl, 120*1000);
            if (responseText != "true")
            {
                result.State = false;
                result.ErrMsg = "支付宝ATN验证无效!";
                return result;
            }

            //签名验证 Start...

            int i;

            // Get names of all forms into a string array.
            String[] requestarr = coll.AllKeys;

            //进行排序;
            string[] sortedstr = Digest.BubbleSort(requestarr);

            //构造待md5摘要字符串 ;

            var prestr = new StringBuilder();

            for (i = 0; i < sortedstr.Length; i++)
            {
                var noIn = new[] {"subdomain", "urlpath", "param", "sign", "sign_type"};
                if (!string.IsNullOrEmpty(coll[sortedstr[i]]) && !noIn.Contains(sortedstr[i]))
                {
                    if (i == sortedstr.Length - 1)
                    {
                        prestr.Append(sortedstr[i] + "=" + coll[sortedstr[i]]);
                    }
                    else
                    {
                        prestr.Append(sortedstr[i] + "=" + coll[sortedstr[i]] + "&");
                    }
                }
            }
            prestr.Append(Configs.GetKey());

            //生成Md5摘要;
            var ourSign = Digest.GetMd5(prestr.ToString(), Configs.Charset);
            //*******加密签名程序结束*******

            var sign = coll["sign"];

            if (sign != ourSign)
            {
                result.State = false;
                result.ErrMsg = "签名验证失败-" + sign + " | " + ourSign;
            }
            var state = new[] {"TRADE_FINISHED", "TRADE_SUCCESS"};
            result.TradeStatus = coll["trade_status"];
            if (!state.Contains(result.TradeStatus))
            {
                result.State = false;
                result.ErrMsg = "支付状态失败!";
            }
            else
                result.State = true;
            return result;
        }