AW.Pay.Core.AliPay.Verify C# (CSharp) Method

Verify() private method

private Verify ( System.Web.HttpRequestBase request, NameValueCollection requestVal, AliPayReturnModel &model ) : bool
request System.Web.HttpRequestBase
requestVal System.Collections.Specialized.NameValueCollection
model AW.Pay.Core.Model.AliPayReturnModel
return bool
        private bool Verify(HttpRequestBase request, NameValueCollection requestVal, out AliPayReturnModel model)
        {
            bool result = false;
            SortedDictionary<string, string> sortedDic = new SortedDictionary<string, string>();
            foreach (var item in requestVal.AllKeys)
            {
                if (item.ToLower() != "sign" && item.ToLower() != "sign_type" && !string.IsNullOrEmpty(item))
                    sortedDic.Add(item, requestVal[item]);
            }

            string requestSign = requestVal["sign"];
            string requestSigntype = requestVal["sign_type"];
            string param = CreateURLParamString(sortedDic);

            EnumSignType signType = requestSigntype == "MD5" ? EnumSignType.MD5
                                    : requestSigntype == "RSA" ? EnumSignType.RSA
                                    : EnumSignType.MD5;

            if (signType == EnumSignType.MD5)
            {
                string sign = BuildRequestsign(param, signType);
                if (requestSign.Equals(sign))
                    result = true;
            }
            else
                result = RSAFromPkcs8.verify(param, requestSign, AlipayConfig.ALIPay_RSA_ALI_PUBLICKEY, "utf-8");

            string responseText = GetResponseTxt(requestVal["notify_id"]);

            bool resultVal = result && responseText == "true";
            if (resultVal)
            {
                model = new AliPayReturnModel()
                {
                    OutTradeNo = request.Form["out_trade_no"],
                    TradeNo = request.Form["trade_no"],
                    TradeStatus = request.Form["trade_status"]
                };

                decimal total_fee;
                decimal.TryParse(request.Form["total_fee"], out total_fee);
                model.TotalFee = total_fee;
            }
            else
                model = null;

            return resultVal;
        }