Beispiel #1
0
        //微信
        private string WxPay(string uid, decimal money)
        {
            UserFinancialManager ufm    = new UserFinancialManager();
            Hashtable            hashuf = new Hashtable();

            hashuf["ID"]            = CommonHelper.GetGuid;
            hashuf["UserID"]        = uid;
            hashuf["OrderNum"]      = SiteHelper.GenerateOrderNum();
            hashuf["OrderPayID"]    = SiteHelper.GeneratePayID();
            hashuf["ChangesAmount"] = money;
            hashuf["ChangesTime"]   = SiteHelper.GetWebServerCurrentTime();
            hashuf["ChangesType"]   = (int)UserFinancialChangesType.Recharge;
            hashuf["Remark"]        = "用户充值";
            hashuf["Operator"]      = uid;
            hashuf["OperatorType"]  = (int)UserFinancialOperatorType.User;
            hashuf["OperatorWay"]   = (int)UserFinancialOperatorWay.WeixinPubPay;
            hashuf["State"]         = (int)UserFinancialState.NewSubmit;
            bool isSuccess = ufm.AddOrEditUserFinancialInfo(hashuf, null);

            if (isSuccess)
            {
                Hashtable uf = ufm.GetUserFinancialPayInfoByPayID(hashuf["OrderPayID"].ToString());
                if (uf == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
                }
                else
                {
                    WxUtil wxUtil = new WxUtil();
                    string prepayid = "", sign = "";
                    prepayid = wxUtil.GetPrepayId(hashuf["OrderPayID"].ToString(), "余额充值", money, weixinNotifyUrl, ip, openID);
                    Hashtable result = new Hashtable();
                    result["PayWay"]    = payway;
                    result["appId"]     = WxConfig.AppId;
                    result["timeStamp"] = wxUtil.genTimeStamp();
                    result["nonceStr"]  = wxUtil.genNonceStr();
                    result["package"]   = "prepay_id=" + prepayid;
                    result["signType"]  = "MD5";

                    SortedDictionary <string, string> dic = new SortedDictionary <string, string>();
                    dic.Add("appId", result["appId"].ToString());
                    dic.Add("timeStamp", result["timeStamp"].ToString());
                    dic.Add("nonceStr", result["nonceStr"].ToString());
                    dic.Add("package", result["package"].ToString());
                    dic.Add("signType", result["signType"].ToString());
                    sign = wxUtil.getSign(dic);

                    result["sign"] = sign;
                    Logger.Info("RechargePay,WxPay prepayId:" + result["prepayId"]);
                    return(SiteHelper.GetJsonFromHashTable(result, "success", "生成支付订单成功", "RechargePay"));
                }
            }
            else
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 支付订单检测
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                DateTime begintime = DateTime.Now.Date;
                DateTime endtime   = begintime.AddHours(24);

                List <string> saasList = ConfigHelper.GetSaasList();
                foreach (string saas in saasList)
                {
                    try
                    {
                        MyWorkerRequest.CreateHttpContext(saas, "", "");

                        UserFinancialManager ufm = new UserFinancialManager();
                        UserInfoManager      uim = new UserInfoManager();
                        DataTable            dt  = ufm.GetUserFinancialList(null, begintime, endtime, Asiasofti.SmartVehicle.Common.Enum.UserFinancialState.NewSubmit, null);
                        foreach (DataRow dr in dt.Rows)
                        {
                            string  financial_id   = dr["ID"].ToString();
                            string  user_id        = dr["UserID"].ToString();
                            string  order_num      = dr["OrderNum"].ToString();
                            decimal changes_amount = 0.00m;
                            decimal.TryParse(dr["ChangesAmount"].ToString(), out changes_amount);
                            changes_amount = Math.Abs(changes_amount);
                            string order_payid  = dr["OrderPayID"].ToString();
                            string operator_way = dr["OperatorWay"].ToString();
                            string changes_type = dr["ChangesType"].ToString();
                            if (changes_type == UserFinancialChangesType.Deposit.GetHashCode().ToString())
                            {
                                DepositPay(user_id, financial_id, changes_amount, order_payid, operator_way);
                            }
                            else if (changes_type == UserFinancialChangesType.Recharge.GetHashCode().ToString())
                            {
                                RechargePay(user_id, financial_id, changes_amount, order_payid, operator_way);
                            }
                            else if (changes_type == UserFinancialChangesType.Consumption.GetHashCode().ToString())
                            {
                                OrderPay(user_id, financial_id, order_num, changes_amount, order_payid, operator_way);
                            }
                        }
                    }
                    catch
                    {
                        Logger.Info("支付订单检测任务(OrderPayQuery:" + saas + ")失败");
                    }
                }
            }
            catch
            {
                Logger.Info("支付订单检测任务(OrderPayQuery)失败");
            }
        }
Beispiel #3
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["CurrentPage"] == null || res["PageNum"] == null ||
                res["UID"].ToString().Trim().Length <= 0 || res["CurrentPage"].ToString().Trim().Length <= 0 ||
                res["PageNum"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                try
                {
                    uid         = res["UID"].ToString().Trim();
                    pagenum     = int.Parse(res["PageNum"].ToString().Trim());
                    currentpage = int.Parse(res["CurrentPage"].ToString().Trim());
                }
                catch
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "数据格式不正确"));
                }
                UserFinancialManager ufm = new UserFinancialManager();
                DataTable            dt  = ufm.GetUserFinancialInfoByUser(uid, currentpage, pagenum);
                foreach (DataRow dr in dt.Rows)
                {
                    string changetype = dr["ChangesType"].ToString().Trim();
                    if (dr["ChangesAmount"] == null || dr["ChangesAmount"].ToString().Trim().Length <= 0)
                    {
                        dr["ChangesAmount"] = "0";
                    }
                    else
                    {
                        if (changetype == UserFinancialChangesType.Recharge.GetHashCode().ToString() || changetype == UserFinancialChangesType.PlatAdd.GetHashCode().ToString())
                        {
                            dr["ChangesAmount"] = Math.Abs(decimal.Parse(dr["ChangesAmount"].ToString())).ToString();
                        }
                        else if (changetype == UserFinancialChangesType.Consumption.GetHashCode().ToString() || changetype == UserFinancialChangesType.PlatMinus.GetHashCode().ToString())
                        {
                            dr["ChangesAmount"] = (-Math.Abs(decimal.Parse(dr["ChangesAmount"].ToString()))).ToString();
                        }
                    }
                }
                if (dt == null || dt.Rows.Count <= 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "没有数据了"));
                }
                else
                {
                    return(JsonHelper.DataTableToJson("success", "获取数据成功", dt, "UserFinancialInfo"));
                }
            }
        }
Beispiel #4
0
        //支付宝
        private string AliPay(string uid, string ordernum)
        {
            OrdersManager om       = new OrdersManager();
            Hashtable     order_ht = om.GetOrderInfoByNum(ordernum);
            decimal       money    = 0.00m;

            decimal.TryParse(SiteHelper.GetHashTableValueByKey(order_ht, "PayMoney"), out money);

            UserFinancialManager ufm    = new UserFinancialManager();
            Hashtable            hashuf = new Hashtable();

            hashuf["ID"]            = CommonHelper.GetGuid;
            hashuf["UserID"]        = uid;
            hashuf["OrderNum"]      = ordernum;
            hashuf["OrderPayID"]    = SiteHelper.GeneratePayID();
            hashuf["ChangesAmount"] = -money;
            hashuf["ChangesTime"]   = SiteHelper.GetWebServerCurrentTime();
            hashuf["ChangesType"]   = (int)UserFinancialChangesType.Consumption;
            hashuf["Remark"]        = "订单支付";
            hashuf["Operator"]      = uid;
            hashuf["OperatorType"]  = (int)UserFinancialOperatorType.User;
            hashuf["OperatorWay"]   = (int)UserFinancialOperatorWay.Alipay;
            hashuf["State"]         = (int)UserFinancialState.NewSubmit;
            bool isSuccess = ufm.AddOrEditUserFinancialInfo(hashuf, null);

            if (isSuccess)
            {
                Hashtable uf = ufm.GetUserFinancialPayInfoByPayID(hashuf["OrderPayID"].ToString());
                if (uf == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
                }
                else
                {
                    Hashtable result = new Hashtable();
                    result["PayWay"]    = payway;
                    result["orderInfo"] = YR.Web.api.app.pay.alipay.Core.GetOrderInfo(hashuf["OrderPayID"].ToString(), "订单支付", string.Format("订单支付{0:N2}元", money), alipayNotifyUrl, money).Replace("\"", "\\\"");
                    Logger.Info("OrderPay,AliPay orderInfo:" + result["orderInfo"]);

                    ICache   cache = CacheFactory.GetCache();
                    DateTime dt    = DateTime.Now.AddSeconds(5);
                    cache.Set(cacheKey, uid, dt - DateTime.Now);
                    cache.Dispose();

                    return(SiteHelper.GetJsonFromHashTable(result, "success", "生成支付订单成功", "OrderPay"));
                }
            }
            else
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
            }
        }
Beispiel #5
0
        /// <summary>
        /// 绑定数据源
        /// </summary>
        private void DataBindGrid(bool isQuery = false)
        {
            UserFinancialManager userFinancialManager = new UserFinancialManager();
            int count     = 0;
            int pageIndex = isQuery ? 1 : PageControl1.PageIndex;
            KeyValuePair <StringBuilder, IList <SqlParam> > keyValue = InitCondition();

            DataTable dt = userFinancialManager.GetUserFinancialInfoPage(keyValue.Key, keyValue.Value, pageIndex, PageControl1.PageSize, ref count);

            ControlBindHelper.BindRepeaterList(dt, rp_Item);

            this.PageControl1.PageIndex   = pageIndex;
            this.PageControl1.RecordCount = Convert.ToInt32(count);
            this.PageControl1.PageChecking();
        }
Beispiel #6
0
        //支付宝
        private string AliPay(string uid, decimal money)
        {
            UserFinancialManager ufm    = new UserFinancialManager();
            Hashtable            hashuf = new Hashtable();

            hashuf["ID"]            = CommonHelper.GetGuid;
            hashuf["UserID"]        = uid;
            hashuf["OrderNum"]      = SiteHelper.GenerateOrderNum();
            hashuf["OrderPayID"]    = SiteHelper.GeneratePayID();
            hashuf["ChangesAmount"] = money;
            hashuf["ChangesTime"]   = SiteHelper.GetWebServerCurrentTime();
            hashuf["ChangesType"]   = (int)UserFinancialChangesType.Recharge;
            hashuf["Remark"]        = "用户充值";
            hashuf["Operator"]      = uid;
            hashuf["OperatorType"]  = (int)UserFinancialOperatorType.User;
            hashuf["OperatorWay"]   = (int)UserFinancialOperatorWay.Alipay;
            hashuf["State"]         = (int)UserFinancialState.NewSubmit;
            bool isSuccess = ufm.AddOrEditUserFinancialInfo(hashuf, null);

            if (isSuccess)
            {
                Hashtable uf = ufm.GetUserFinancialPayInfoByPayID(hashuf["OrderPayID"].ToString());
                if (uf == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
                }
                else
                {
                    Hashtable result = new Hashtable();
                    result["PayWay"]    = payway;
                    result["orderInfo"] = YR.Web.api.app.pay.alipay.Core.GetOrderInfo(hashuf["OrderPayID"].ToString(), "余额充值", string.Format("用户充值{0:N2}元", money), alipayNotifyUrl, money);
                    Logger.Info("RechargePay,AliPay orderInfo:" + result["orderInfo"]);

                    ICache   cache = CacheFactory.GetCache();
                    DateTime dt    = DateTime.Now.AddSeconds(5);
                    cache.Set(cacheKey, uid, dt - DateTime.Now);
                    cache.Dispose();

                    return(SiteHelper.GetJsonFromHashTable(result, "success", "生成支付订单成功", "RechargePay"));
                }
            }
            else
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
            }
        }
Beispiel #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            StreamReader reader  = new StreamReader(Request.InputStream);
            String       xmlData = reader.ReadToEnd();
            var          sPara   = GetRequestPostByXml(xmlData);

            if (sPara.Count <= 0)
            {
                throw new ArgumentNullException();
            }

            if (sPara["return_code"] == "SUCCESS" && sPara["result_code"] == "SUCCESS")
            {
                var sign = sPara["sign"];

                Dictionary <string, string> sPara2 = new Dictionary <string, string>();
                foreach (var item in sPara)
                {
                    if (item.Key != "sign")
                    {
                        sPara2.Add(item.Key, item.Value);
                    }
                }

                var  signValue = WxPayAPI.Sign(sPara2, WxConfig.PartnerKey);
                bool isVerify  = sign == signValue;
                if (isVerify)
                {
                    var out_trade_no   = sPara["out_trade_no"];
                    var transaction_id = sPara["transaction_id"];
                    var total_fee      = sPara["total_fee"];

                    decimal pay_money = decimal.Parse(total_fee) / 100;
                    Logger.Info(string.Format("用户订单,微信公众号支付通知,订单号{0},支付单号{1},支付金额{2}", out_trade_no, transaction_id, pay_money));

                    UserInfoManager      uim           = new UserInfoManager();
                    UserFinancialManager ufm           = new UserFinancialManager();
                    DataTable            userfinancial = ufm.GetUserFinancialInfoByPayId(out_trade_no);
                    if (userfinancial != null && userfinancial.Rows.Count == 1)
                    {
                        Hashtable hashufdb = DataTableHelper.DataRowToHashTable(userfinancial.Rows[0]);
                        Hashtable hashuf   = new Hashtable();
                        hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(hashufdb, "ID");
                        hashuf["OrderNum"] = SiteHelper.GetHashTableValueByKey(hashufdb, "OrderNum");
                        hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(hashufdb, "UserID");
                        hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                        hashuf["TradeNo"]  = transaction_id;
                        hashuf["TotalFee"] = pay_money;
                        hashuf["PayWay"]   = UserFinancialOperatorWay.WeixinPubPay;
                        decimal changesAmount = 0.00m;
                        decimal.TryParse(SiteHelper.GetHashTableValueByKey(hashufdb, "ChangesAmount"), out changesAmount);
                        bool isSuccess = false;
                        if (Math.Abs(changesAmount) == pay_money)
                        {
                            isSuccess = uim.OrderPayCallback(hashuf);
                        }
                        if (isSuccess)
                        {
                            sb.Append("<xml>");
                            sb.Append("<return_code>SUCCESS</return_code>");
                            sb.Append("<return_msg></return_msg>");
                            sb.Append("</xml>");
                        }
                        else
                        {
                            sb.Append("<xml>");
                            sb.Append("<return_code>FAIL</return_code>");
                            sb.Append("<return_msg>error</return_msg>");
                            sb.Append("</xml>");
                        }
                    }
                }
            }
            else
            {
                sb.Append("<xml>");
                sb.Append("<return_code>FAIL</return_code>");
                sb.Append("<return_msg>error</return_msg>");
                sb.Append("</xml>");
            }

            Response.Write(sb);
        }
Beispiel #8
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["UID"].ToString().Trim().Length <= 0 ||
                res["PayWay"] == null || res["PayWay"].ToString().Trim().Length <= 0 ||
                res["Money"] == null || res["Money"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                int.TryParse(res["PayWay"].ToString().Trim(), out payway);
                cacheKey += uid;
                decimal.TryParse(res["Money"].ToString().Trim(), out money);

                //在充值时进行身份验证
                UserFinancialManager ufm  = new UserFinancialManager();
                UserInfoManager      uim  = new UserInfoManager();
                Hashtable            user = uim.GetUserInfoByUserID(uid);
                if (user == null || user.Keys.Count <= 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "您不是有效会员"));
                }
                else
                {
                    //验证用户是否经过身份认证
                    if ("4".CompareTo(user["REALNAMECERTIFICATION"].ToString()) != 0)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前未完成实名认证,请完成实名认证后重试"));
                    }
                    //验证用户状态是否有效
                    if ("0".CompareTo(user["USERSTATE"].ToString()) == 0)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前已被禁用无法充值"));
                    }
                }
                //----------------------------------------------------------------------------------

                #region 检测前一笔未确认支付交易是否成功,成功则调用支付成功业务逻辑

                Hashtable financial_ht = ufm.GetLatestUserFinancialInfo(uid, UserFinancialState.NewSubmit, UserFinancialChangesType.Recharge);
                if (financial_ht != null && financial_ht.Keys.Count > 0)
                {
                    string order_payid  = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderPayID");
                    string operator_way = SiteHelper.GetHashTableValueByKey(financial_ht, "OperatorWay");
                    if (operator_way == UserFinancialOperatorWay.WeixinPay.GetHashCode().ToString())
                    {
                        WxOrderQuery     orderQuery  = new WxOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.WeixinPay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.RechargeCallBack(hashuf);
                            }
                        }
                    }
                    else if (operator_way == UserFinancialOperatorWay.Alipay.GetHashCode().ToString())
                    {
                        AlipayOrderQuery orderQuery  = new AlipayOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.Alipay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.RechargeCallBack(hashuf);
                            }
                        }
                    }
                }

                #endregion

                webRoot         = SiteHelper.GetWebRoot();
                weixinNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/wxpay/recharge_notify_url.aspx");
                alipayNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/alipay/recharge_notify_url.aspx");

                string result = "";
                ICache cache  = null;
                switch (payway)
                {
                case 1:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("充值支付宝支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = AliPay(uid, money);
                    break;

                case 2:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("充值微信支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = WxPay(uid, money);
                    break;

                default:
                    break;
                }
                return(result);
            }
        }
Beispiel #9
0
        //微信
        private string WxPay(string uid, decimal money)
        {
            UserFinancialManager ufm    = new UserFinancialManager();
            Hashtable            hashuf = new Hashtable();

            hashuf["ID"]            = CommonHelper.GetGuid;
            hashuf["UserID"]        = uid;
            hashuf["OrderNum"]      = SiteHelper.GenerateOrderNum();
            hashuf["OrderPayID"]    = SiteHelper.GeneratePayID();
            hashuf["ChangesAmount"] = money;
            hashuf["ChangesTime"]   = SiteHelper.GetWebServerCurrentTime();
            hashuf["ChangesType"]   = (int)UserFinancialChangesType.Recharge;
            hashuf["Remark"]        = "用户充值";
            hashuf["Operator"]      = uid;
            hashuf["OperatorType"]  = (int)UserFinancialOperatorType.User;
            hashuf["OperatorWay"]   = (int)UserFinancialOperatorWay.WeixinPay;
            hashuf["State"]         = (int)UserFinancialState.NewSubmit;
            bool isSuccess = ufm.AddOrEditUserFinancialInfo(hashuf, null);

            if (isSuccess)
            {
                Hashtable uf = ufm.GetUserFinancialPayInfoByPayID(hashuf["OrderPayID"].ToString());
                if (uf == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
                }
                else
                {
                    WxUtil wxUtil = new WxUtil();
                    string prepayid = "", sign = "";
                    prepayid = wxUtil.GetPrepayId(hashuf["OrderPayID"].ToString(), "余额充值", money, weixinNotifyUrl, HttpContext.Current.Request.UserHostAddress);
                    Hashtable result = new Hashtable();
                    result["PayWay"]       = payway;
                    result["appId"]        = pay.wxpay.WxConfig.AppId;
                    result["partnerId"]    = pay.wxpay.WxConfig.MchId;
                    result["prepayId"]     = prepayid;
                    result["packageValue"] = "Sign=WXPay";
                    result["nonceStr"]     = wxUtil.genNonceStr();
                    result["timeStamp"]    = wxUtil.genTimeStamp();

                    SortedDictionary <string, string> dic = new SortedDictionary <string, string>();
                    dic.Add("appid", result["appId"].ToString());
                    dic.Add("noncestr", result["nonceStr"].ToString());
                    dic.Add("package", result["packageValue"].ToString());
                    dic.Add("partnerid", result["partnerId"].ToString());
                    dic.Add("prepayid", result["prepayId"].ToString());
                    dic.Add("timestamp", result["timeStamp"].ToString());
                    sign = wxUtil.getSign(dic);

                    result["sign"] = sign;
                    Logger.Info("RechargePay,WxPay prepayId:" + result["prepayId"]);

                    ICache   cache = CacheFactory.GetCache();
                    DateTime dt    = DateTime.Now.AddSeconds(5);
                    cache.Set(cacheKey, uid, dt - DateTime.Now);
                    cache.Dispose();

                    return(SiteHelper.GetJsonFromHashTable(result, "success", "生成支付订单成功", "RechargePay"));
                }
            }
            else
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "生成支付订单失败"));
            }
        }
Beispiel #10
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["UID"].ToString().Trim().Length <= 0 ||
                res["PayWay"] == null || res["PayWay"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                int.TryParse(res["PayWay"].ToString().Trim(), out payway);
                cacheKey += uid;
                UserFinancialManager ufm            = new UserFinancialManager();
                SysSettingManager    settingManager = new SysSettingManager();
                string depositMoney = settingManager.GetValueByKey("GoldDepositAmount");
                decimal.TryParse(depositMoney, out money);

                //在充值时进行身份验证
                UserInfoManager uim  = new UserInfoManager();
                Hashtable       user = uim.GetUserInfoByUserID(uid);
                if (user == null || user.Keys.Count <= 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "您不是有效会员"));
                }
                //----------------------------------------------------------------------------------

                //判断用户是否已缴纳押金
                decimal deposit = 0.00m;
                decimal.TryParse(user["DEPOSIT"].ToString(), out deposit);
                if (deposit > 0.00m)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前已缴纳用车押金"));
                }
                //-------------------------------------------------------------------------------------

                #region 检测前一笔未确认支付交易是否成功,成功则禁止重复支付

                Hashtable financial_ht = ufm.GetLatestUserFinancialInfo(uid, UserFinancialState.NewSubmit, UserFinancialChangesType.Deposit);
                if (financial_ht != null && financial_ht.Keys.Count > 0)
                {
                    //是否添加前一笔和当前时间差判断逻辑??????
                    string order_payid  = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderPayID");
                    string operator_way = SiteHelper.GetHashTableValueByKey(financial_ht, "OperatorWay");
                    if (operator_way == UserFinancialOperatorWay.WeixinPay.GetHashCode().ToString())
                    {
                        WxOrderQuery     orderQuery  = new WxOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.WeixinPay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.DepositCallBack(hashuf);
                            }
                            if (isSuccess)
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前已缴纳用车押金"));
                            }
                        }
                    }
                    else if (operator_way == UserFinancialOperatorWay.Alipay.GetHashCode().ToString())
                    {
                        AlipayOrderQuery orderQuery  = new AlipayOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.Alipay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.DepositCallBack(hashuf);
                            }
                            if (isSuccess)
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前已缴纳用车押金"));
                            }
                        }
                    }
                }

                #endregion

                webRoot         = SiteHelper.GetWebRoot();
                weixinNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/wxpay/deposit_notify_url.aspx");
                alipayNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/alipay/deposit_notify_url.aspx");

                string result = "";
                ICache cache  = null;
                switch (payway)
                {
                case 1:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("保证金支付宝支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = AliPay(uid, money);
                    break;

                case 2:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("保证金微信支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = WxPay(uid, money);
                    break;

                default:
                    break;
                }
                return(result);
            }
        }
Beispiel #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Dictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify = new Notify();
                string notify_id = Request.Form["notify_id"]; //获取notify_id
                string sign      = Request.Form["sign"];      //获取sign
                Logger.Warn(string.Format("用户押金缴费,支付宝支付通知,结果{0}", JsonConvert.SerializeObject(sPara)));
                if (aliNotify.GetSignVeryfy(sPara, sign))
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码

                    //商户订单号
                    string out_trade_no = Request.Form["out_trade_no"];
                    //支付宝交易号
                    string trade_no = Request.Form["trade_no"];
                    //支付宝交易金额
                    string total_fee = Request.Form["total_amount"];

                    //支付宝用户号 支付宝账号对应的支付宝唯一用户号。以2088开头的纯16位数字
                    string buyer_id = Request.Form["buyer_id"];
                    //支付宝账号
                    string buyer_logon_id = Request.Form["buyer_logon_id"];

                    Logger.Warn(string.Format("用户押金缴费,支付宝支付通知,订单号{0},支付单号{1},支付金额{2},支付宝用户号{3},支付宝账号{4}", out_trade_no, trade_no, total_fee, buyer_id, buyer_logon_id));

                    //交易状态
                    string trade_status = Request.Form["trade_status"];
                    if (trade_status == "TRADE_SUCCESS" || trade_status == "TRADE_FINISHED")
                    {
                        UserInfoManager      uim           = new UserInfoManager();
                        UserFinancialManager ufm           = new UserFinancialManager();
                        DataTable            userfinancial = ufm.GetUserFinancialInfoByPayId(out_trade_no);
                        if (userfinancial != null && userfinancial.Rows.Count == 1)
                        {
                            Hashtable hashufdb = DataTableHelper.DataRowToHashTable(userfinancial.Rows[0]);
                            Hashtable hashuf   = new Hashtable();
                            hashuf["ID"]             = SiteHelper.GetHashTableValueByKey(hashufdb, "ID");
                            hashuf["UserID"]         = SiteHelper.GetHashTableValueByKey(hashufdb, "UserID");
                            hashuf["State"]          = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]        = trade_no;
                            hashuf["TotalFee"]       = total_fee;
                            hashuf["PayWay"]         = UserFinancialOperatorWay.Alipay;
                            hashuf["buyer_id"]       = buyer_id;
                            hashuf["buyer_logon_id"] = buyer_logon_id;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(hashufdb, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == decimal.Parse(total_fee))
                            {
                                isSuccess = uim.DepositCallBack(hashuf);
                            }
                            if (isSuccess)
                            {
                                Response.Write("success");
                            }
                            else
                            {
                                Response.Write("fail");
                            }
                        }
                        else
                        {
                        }
                    }
                    else//验证失败
                    {
                        Response.Write("fail");
                    }
                }
                else
                {
                    Response.Write("无通知参数");
                }
            }
        }
Beispiel #12
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["UID"].ToString().Trim().Length <= 0 ||
                res["PayWay"] == null || res["PayWay"].ToString().Trim().Length <= 0 ||
                res["OrderNum"] == null || res["OrderNum"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                int.TryParse(res["PayWay"].ToString().Trim(), out payway);
                cacheKey += uid;
                string ordernum                    = res["OrderNum"].ToString().Trim();
                string couponID                    = "";
                UserFinancialManager ufm           = new UserFinancialManager();
                UserInfoManager      uim           = new UserInfoManager();
                OrdersManager        om            = new OrdersManager();
                UserCouponManager    couponManager = new UserCouponManager();
                Hashtable            order_ht      = om.GetOrderInfoByNum(ordernum);
                if (order_ht == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未找到订单数据,支付失败"));
                }
                int     payState   = int.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "PayState"));
                int     orderState = int.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "OrderState"));
                decimal payMoney   = decimal.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "PayMoney"));
                decimal totalMoney = decimal.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "TotalMoney"));

                if (OrderState.UnPay.GetHashCode() != orderState)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "订单支付失败"));
                }
                if (totalMoney <= 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未产生支付费用,无需进行支付操作"));
                }

                #region 检测前一笔未确认支付交易是否成功,成功则禁止重复支付

                Hashtable financial_ht = ufm.GetLatestUserFinancialInfo(uid, UserFinancialState.NewSubmit, UserFinancialChangesType.Consumption);
                if (financial_ht != null && financial_ht.Keys.Count > 0)
                {
                    string order_num    = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderNum");
                    string order_payid  = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderPayID");
                    string operator_way = SiteHelper.GetHashTableValueByKey(financial_ht, "OperatorWay");
                    if (operator_way == UserFinancialOperatorWay.WeixinPay.GetHashCode().ToString())
                    {
                        WxOrderQuery     orderQuery  = new WxOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["OrderNum"] = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderNum");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.WeixinPay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.OrderPayCallback(hashuf);
                            }
                            if (isSuccess && ordernum == order_num)
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前订单已成功支付"));
                            }
                        }
                    }
                    else if (operator_way == UserFinancialOperatorWay.Alipay.GetHashCode().ToString())
                    {
                        AlipayOrderQuery orderQuery  = new AlipayOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["OrderNum"] = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderNum");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.Alipay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.OrderPayCallback(hashuf);
                            }
                            if (isSuccess && ordernum == order_num)
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前订单已成功支付"));
                            }
                        }
                    }
                }

                #endregion

                if (res["CouponID"] != null && res["CouponID"].ToString().Trim().Length > 0)
                {
                    couponID = res["CouponID"].ToString().Trim();
                    Hashtable coupon_ht = couponManager.GetDataByID(couponID);
                    if (coupon_ht == null || coupon_ht.Keys.Count == 0)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    string  orderid     = SiteHelper.GetHashTableValueByKey(coupon_ht, "OrderID");
                    string  begintime   = SiteHelper.GetHashTableValueByKey(coupon_ht, "BeginTime");
                    string  endtime     = SiteHelper.GetHashTableValueByKey(coupon_ht, "EndTime");
                    string  userid      = SiteHelper.GetHashTableValueByKey(coupon_ht, "UserID");
                    decimal couponMoney = 0.00m;
                    decimal.TryParse(SiteHelper.GetHashTableValueByKey(coupon_ht, "Money"), out couponMoney);
                    if (userid != uid)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (!string.IsNullOrEmpty(orderid))
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (DateTime.Parse(begintime) > DateTime.Now || DateTime.Parse(endtime) < DateTime.Now)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (couponMoney > totalMoney)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }

                    Hashtable update_order_ht = new Hashtable();
                    update_order_ht["CouponID"]    = couponID;
                    update_order_ht["CouponMoney"] = couponMoney;
                    update_order_ht["PayMoney"]    = totalMoney - couponMoney;
                    bool rrr = om.AddOrEditOrdersInfo(update_order_ht, SiteHelper.GetHashTableValueByKey(order_ht, "ID"));
                }

                webRoot         = SiteHelper.GetWebRoot();
                weixinNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/wxpay/order_notify_url.aspx");
                alipayNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/alipay/order_notify_url.aspx");

                string result = "";
                ICache cache  = null;
                switch (payway)
                {
                case 1:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("订单支付宝支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = AliPay(uid, ordernum);
                    break;

                case 2:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("订单微信支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = WxPay(uid, ordernum);
                    break;

                case 3:
                    result = BalancePay(uid, ordernum);
                    break;

                default:
                    break;
                }
                return(result);
            }
        }