Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            ResponseHandler resHandler = new ResponseHandler(Context);
            RequestParam    param      = CommonUntils.DictionaryToClass <RequestParam>(resHandler.pairs);

            if (param == null)
            {
                param = new RequestParam();
            }
            if (String.IsNullOrEmpty(param.postMessage))
            {
                Response.Redirect("message.html?m=提交数据异常,请稍候再试.");
                return;
            }

            String postMessage = "";

            if (HttpContext.Current.Session != null && HttpContext.Current.Session[param.postMessage] != null)
            {
                postMessage = HttpContext.Current.Session[param.postMessage].ToString();
            }
            if (String.IsNullOrEmpty(postMessage))
            {
                Response.Redirect("message.html?m=提交数据异常,请稍候再试.");
                return;
            }
            postMessage = Base64.Decode(postMessage);
            if (String.IsNullOrEmpty(postMessage))
            {
                Response.Redirect("message.html?m=提交数据异常,请稍候再试.");
                return;
            }
            Dictionary <string, string> pay_params = postMessage.FromJsonString <Dictionary <string, string> >();

            if (pay_params == null || pay_params.Count == 0)
            {
                Response.Redirect("message.html?m=提交数据异常,请稍候再试.");
                return;
            }

            String dicKey = "remark";
            String mark   = "";

            if (pay_params.ContainsKey(dicKey))
            {
                mark = pay_params[dicKey];
                mark = Base64.Decode(mark);
            }
            Recharge recharge = mark.FromJsonString <Recharge>();

            if (recharge != null)
            {
                recharge.payStatus = 0;
                RechargeUtils.AddHistoryRecharge(recharge);
            }
            pay_params.Remove(dicKey);

            NameValueCollection data = new NameValueCollection();

            foreach (var item in pay_params)
            {
                data.Add(item.Key, item.Value);
            }

            String apiUrl        = ConfigUtils.payurl;
            String joinPostParam = String.Join("&", pay_params.Select(A => String.Format("{0}={1}", A.Key, A.Value)).ToList());

            FileLogUtils.Debug("RedirectAndPOST  Url", String.Format("{0}?{1}", apiUrl, joinPostParam), true);

            ApiLog log = new ApiLog();

            log.orderid = recharge.id;
            log.type    = 1;
            log.url     = apiUrl;
            log.datas   = pay_params.ToJsonString();
            ApiLogUntils.AddLog(log);

            HttpHelper.RedirectAndPOST(this.Page, apiUrl, data);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="param"></param>
        /// <param name="sessionCode"></param>
        /// <returns></returns>
        public static Result checkReturntParam(Dictionary <string, string> pairs, ref NotifyResult requestParam)
        {
            Result result = new Result();

            try
            {
                requestParam = CommonUntils.DictionaryToClass <NotifyResult>(pairs);
                if (requestParam == null)
                {
                    result.message = "数据解析异常.";
                    return(result);
                }
                result.data = requestParam.ToJsonString();

                if (String.IsNullOrEmpty(requestParam.pid) ||
                    String.IsNullOrEmpty(requestParam.trade_no) ||
                    String.IsNullOrEmpty(requestParam.out_trade_no) ||
                    String.IsNullOrEmpty(requestParam.money) ||
                    String.IsNullOrEmpty(requestParam.sign))
                {
                    result.message = "数据解析异常.";
                    return(result);
                }

                if (requestParam.pid.ToUpper() != ConfigUtils.pid.ToUpper())
                {
                    result.message = "商户号不匹配.";
                    return(result);
                }
                if (requestParam.trade_status.ToUpper() != "TRADE_SUCCESS")
                {
                    result.status  = "failed";
                    result.message = "支付失败.";
                    return(result);
                }

                double doubleMoney = 0;
                if (!double.TryParse(requestParam.money, out doubleMoney))
                {
                    result.status  = "failed";
                    result.message = "支付金额出现异常,请稍候再试.";
                    return(result);
                }
                if (doubleMoney <= 0)
                {
                    result.status  = "failed";
                    result.message = "支付金额出现异常,请稍候再试.";
                    return(result);
                }
                requestParam.resultMoney = doubleMoney;

                SortedDictionary <string, string> dicMap = new SortedDictionary <string, string>();
                dicMap.Add("pid", requestParam.pid);
                dicMap.Add("trade_no", requestParam.trade_no);
                dicMap.Add("out_trade_no", requestParam.out_trade_no);
                dicMap.Add("type", requestParam.type);
                dicMap.Add("name", requestParam.name);
                dicMap.Add("money", requestParam.money);
                dicMap.Add("trade_status", requestParam.trade_status);

                Boolean flag = CommonUntils.verifySign(dicMap, requestParam.sign);
                if (!flag)
                {
                    result.message = "身份校验异常.";
                    return(result);
                }

                result.status  = "1";
                result.message = "";
                return(result);
            }
            catch (Exception ex)
            {
                FileLogUtils.Error("getPostParam", ex.StackTrace);
                result.status  = "failed";
                result.message = "服务器出现异常,请稍候再试.";
                return(result);
            }
        }