Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            String writeString = "SUCCESS";

            if (IsPostBack)
            {
                Response.Write(writeString);
                Response.End();
                return;
            }

            ResponseHandler resHandler = new ResponseHandler(Context);

            FileLogUtils.Debug("PayResult.aspx", resHandler.pairs.ToJsonString(), false);

            if (resHandler.pairs.Count == 0)
            {
                Response.Write(writeString);
                return;
            }

            NotifyResult requestParam = new NotifyResult();
            Result       sdkResult    = SDK.checkReturntParam(resHandler.pairs, ref requestParam);

            FileLogUtils.Info("PayResult.aspx", sdkResult.ToJsonString());

            ApiLog log = new ApiLog();

            //log.apitype = 7;
            log.type    = 2;
            log.url     = "PayResult.aspx";
            log.datas   = resHandler.pairs.ToJsonString();
            log.orderid = requestParam.out_trade_no;
            ApiLogUntils.AddLog(log);

            if (sdkResult.status != "1")
            {
                Response.Redirect(String.Format("message.html?m={0}", Uri.EscapeDataString("支付失败. 订单号:" + requestParam.out_trade_no)));
                return;
            }

            Recharge recharge = new Recharge();

            recharge.id          = requestParam.out_trade_no;
            recharge.pay_orderid = requestParam.trade_no;
            recharge.pay_money   = requestParam.resultMoney;
            if (recharge != null && !String.IsNullOrEmpty(recharge.id))
            {
                recharge.payStatus = 1;
                RechargeUtils.UpdateRechargeState(recharge);
            }
            Response.Redirect(String.Format("message.html?m={0}", Uri.EscapeDataString("支付成功. 订单号:" + requestParam.out_trade_no)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新增历史订单信息
        /// </summary>
        /// <param name="recharge"></param>
        public static void AddHistoryRecharge(Recharge recharge)
        {
            if (recharge == null || String.IsNullOrWhiteSpace(recharge.id))
            {
                return;
            }

            String sql = String.Format("delete recharge_history where id = '{0}'", recharge.id);

            DBUtils.ExecuteNonQuery(sql);

            sql = String.Format("insert into recharge_history(id,`group`,accounts,time,money,agent,payState) values('{0}','{1}','{2}','{3}','{4}','{5}',{6})", recharge.id, recharge.group, recharge.accounts, recharge.time, recharge.money, recharge.agent, recharge.payStatus);
            DBUtils.ExecuteNonQuery(sql);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新历史订单信息(主要用于更新支付状态)
        /// </summary>
        /// <param name="recharge"></param>
        public static void UpdateRechargeState(Recharge recharge)
        {
            lock (LockObj)
            {
                if (recharge == null || String.IsNullOrWhiteSpace(recharge.id))
                {
                    FileLogUtils.Info("UpdateRechargeState", "订单参数异常:" + recharge.ToJsonString());
                    return;
                }
                Recharge recharge1 = GetHistoryInfo(recharge.id);
                if (recharge1 == null)
                {
                    FileLogUtils.Info("UpdateRechargeState", "历史订单不存在:" + recharge.ToJsonString());
                    return;
                }

                String sql = "";
                if (String.IsNullOrEmpty(recharge1.pay_orderid) && recharge1.pay_orderid != recharge.pay_orderid)
                {
                    sql = String.Format("update recharge_history set pay_orderid = '{0}' where id = '{1}' ", recharge.pay_orderid, recharge1.id);
                    DBUtils.ExecuteNonQuery(sql);
                    FileLogUtils.Info("UpdateRechargeState", "支付平台流水号已记录:" + recharge.ToJsonString());
                }
                if (recharge1.payStatus == 1)
                {
                    FileLogUtils.Info("UpdateRechargeState", "历史订单已处理:" + recharge.ToJsonString());
                    return;
                }
                sql = String.Format("update recharge_history set payState = {0}, pay_money={1}, pay_orderid='{2}' where id = '{3}' ", recharge.payStatus, recharge.pay_money, recharge.pay_orderid, recharge1.id);
                DBUtils.ExecuteNonQuery(sql);
                FileLogUtils.Info("UpdateRechargeState", "历史订单状态已变更:" + recharge.ToJsonString());

                if (recharge.payStatus == 1)
                {
                    recharge1.payStatus   = 1;
                    recharge1.money       = recharge.pay_money.Value;
                    recharge1.pay_orderid = recharge.pay_orderid;
                    AddRecharge(recharge1);
                }
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="recharge"></param>
        /// <returns></returns>
        public static QueryResult QueryOrder(Recharge recharge)
        {
            QueryResult queryResult = new QueryResult();

            queryResult.code = "0";
            if (recharge == null || String.IsNullOrEmpty(recharge.id))
            {
                return(queryResult);
            }

            SortedDictionary <string, string> param = new SortedDictionary <string, string>();

            param.Add("act", "order");
            param.Add("pid", ConfigUtils.pid);      //商户号
            param.Add("key", ConfigUtils.key);
            param.Add("out_trade_no", recharge.id); //订单号

            List <String> queryParam = param.Select(A => String.Format("{0}={1}", A.Key, A.Value)).ToList();
            String        queryUrl   = ConfigUtils.queryurl;

            queryUrl = String.Format("{0}?{1}", queryUrl, String.Join("&", queryParam));

            FileLogUtils.TaskContent("requet begin:" + queryUrl);
            String requestResult = HttpClientProxy.GetRequestString(queryUrl);

            FileLogUtils.TaskContent("requet end:" + requestResult);
            if (String.IsNullOrEmpty(requestResult))
            {
                queryResult.code = "0";
                return(queryResult);
            }

            ApiLog log = new ApiLog();

            log.orderid = recharge.id;
            log.type    = 3;
            log.url     = queryUrl;
            log.datas   = requestResult;
            ApiLogUntils.AddLog(log);

            queryResult = JsonProxy.FromJsonString <QueryResult>(requestResult);
            if (queryResult == null)
            {
                queryResult = new QueryResult();
            }
            if (queryResult.code != "1" || queryResult.status != "1")
            {
                queryResult.code = "0";
                return(queryResult);
            }
            if (queryResult.pid.ToUpper() != ConfigUtils.pid.ToUpper()) //商户号不匹配
            {
                queryResult.code = "0";
                return(queryResult);
            }
            if (recharge.id != queryResult.out_trade_no) //商户订单号不匹配
            {
                queryResult.code = "0";
                return(queryResult);
            }

            Double pay_money = 0;

            if (!Double.TryParse(queryResult.money, out pay_money))
            {
                queryResult.code = "0";
                return(queryResult);
            }

            Recharge newRecharge = new Recharge();

            newRecharge.id          = recharge.id;
            newRecharge.pay_orderid = queryResult.trade_no;
            newRecharge.pay_money   = pay_money;
            newRecharge.payStatus   = 1;
            RechargeUtils.UpdateRechargeState(newRecharge);

            return(queryResult);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static Result1 getPostParam(RequestParam param, String sessionCode)
        {
            Result1 result = new Result1();

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

                if (String.IsNullOrEmpty(sessionCode) ||
                    String.IsNullOrEmpty(param.code) ||
                    sessionCode.ToUpper() != param.code.ToUpper())
                {
                    result.status  = "failed";
                    result.message = "验证码错误,请重新输入.";
                    return(result);
                }
                if (String.IsNullOrWhiteSpace(param.pay_orderid) ||
                    String.IsNullOrWhiteSpace(param.pay_amount) ||
                    String.IsNullOrWhiteSpace(param.group) ||
                    String.IsNullOrWhiteSpace(param.pay_bankcode) ||
                    String.IsNullOrWhiteSpace(param.code))
                {
                    result.status  = "failed";
                    result.message = "提交数据出现异常,请稍候再试.";
                    return(result);
                }

                PayType payType = ConfigUtils.PayTypes.FirstOrDefault(A => A.Key == param.pay_bankcode);
                if (payType == null)
                {
                    result.status  = "failed";
                    result.message = "不支持该支付类型,请重新提交.";
                    return(result);
                }

                UserAccount userAccount = AccountUntils.GetInfo(param.accounts);
                if (userAccount == null)
                {
                    result.status  = "failed";
                    result.message = "充值账号不存在,请重新提交.";
                    return(result);
                }
                //if (String.IsNullOrEmpty(userAccount.agent))
                //{
                //    result.status = "failed";
                //    result.message = "代理不存在,无法充值.";
                //    return result;
                //}
                if (String.IsNullOrEmpty(userAccount.agent))
                {
                    userAccount.agent = "";
                }

                //写入历史订单表
                Recharge recharge = new Recharge();
                recharge.id        = param.pay_orderid;
                recharge.group     = param.group;
                recharge.accounts  = param.accounts;
                recharge.agent     = userAccount.agent;
                recharge.money     = Double.Parse(doubleMoney.ToString());
                recharge.time      = TimeUntils.GetNow();
                recharge.payStatus = 0;
                recharge.payType   = param.pay_bankcode;

                //Post参数
                SortedDictionary <string, string> pay_params = new SortedDictionary <string, string>();
                pay_params.Add("pid", ConfigUtils.pid);
                pay_params.Add("type", recharge.payType);            //平台分配商户号
                pay_params.Add("out_trade_no", recharge.id);         //订单号
                pay_params.Add("notify_url", ConfigUtils.notifyurl); //服务端返回地址(POST返回数据)
                pay_params.Add("return_url", ConfigUtils.returnurl); //页面跳转返回地址(POST返回数据)
                pay_params.Add("name", "充值");
                pay_params.Add("money", doubleMoney.ToString("F2")); //支付金额
                pay_params.Add("sitename", ConfigUtils.sitename);

                String sign = CommonUntils.getSign(pay_params);
                pay_params.Add("sign", sign);
                pay_params.Add("sign_type", "MD5");
                pay_params.Add("remark", Base64.Encode(recharge.ToJsonString()));

                String postMessage = pay_params.ToJsonString();
                postMessage = Base64.Encode(postMessage);

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