public void AlipayNotify()
 {
     AliPayReturnModel payResult = new AliPayReturnModel();
     HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
     HttpRequestBase request = context.Request;//定义传统request对象
     var result = this._aliPay.VerfyNotify(request,out payResult);
 }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
 public bool VerfyNotify(HttpRequestBase request, out AliPayReturnModel model)
 {
     var requestVal = request.Form;
     return Verify(request, requestVal, out model);
 }
Ejemplo n.º 4
0
 public bool VerifyReturnURL(HttpRequestBase request, out AliPayReturnModel model)
 {
     var requestVal = request.QueryString;
     return Verify(request, requestVal, out model);
 }