Ejemplo n.º 1
0
        /// <summary>
        /// 充值成功更新充值记录
        /// </summary>
        /// <param name="rech"></param>
        /// <returns></returns>
        public string UpdateRechargeForPay(recharge.RechargeModel rech)
        {
            DbParameter[] parms = {
                                      GenerateInParam("@out_trade_no", SqlDbType.VarChar, 50, rech.Out_trade_no),
                                      GenerateInParam("@trade_no", SqlDbType.VarChar, 50, rech.Trade_no),
                                      GenerateInParam("@paytime", SqlDbType.VarChar, 30, rech.Paytime),
                                      GenerateInParam("@total_fee", SqlDbType.Decimal, 25, rech.Total_fee)
                                    };
            string commandText = string.Format(@"
begin try
if exists(select 1 from [{0}rechargeinfo] where out_trade_no=@out_trade_no)
begin
UPDATE [{0}rechargeinfo]
   SET trade_no = @trade_no,paytime=@paytime,total_fee=@total_fee
where out_trade_no=@out_trade_no

select '修改成功' state
end
else
begin
select '充值记录已被删除' state
end
end try
begin catch
select ERROR_MESSAGE() state
end catch
",
                                                RDBSHelper.RDBSTablePre);
            return RDBSHelper.ExecuteScalar(CommandType.Text, commandText, parms).ToString();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 充值成功后续处理
        /// </summary>
        /// <param name="total_fee">总金额</param>
        /// <param name="out_trade_no">系统订单号(标识)</param>
        /// <param name="time_end">支付完成时间</param>
        /// <param name="trade_no">支付宝/微信交易号</param>
        /// <returns></returns>
        public static string UpdateRecharge(string total_fee, string out_trade_no, string time_end, string trade_no)
        {
            /*
             * 1、充值成功,更新充值记录信息
             */
            //更新充值记录
            OWZX.Model.RechargeModel rech = new OWZX.Model.RechargeModel {
                Out_trade_no = out_trade_no, Paytime = time_end, Total_fee = decimal.Parse(total_fee), Trade_no = trade_no
            };
            bool recres = Recharge.UpdateRechargeForPay(rech);

            if (recres)
            {
                //string type = string.Empty;(1:充话费 2:升级充值)
                List <RechargeModel> rchlist = Recharge.GetRechargeList(1, 1, " where out_trade_no='" + out_trade_no + "'");
                if (rchlist.Count == 0)
                {
                    return("fail");
                }
                RechargeModel rch = rchlist[0];
                return("success");
            }
            else
            {
                Logs.Write("更新充值记录失败!");
                return("error");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加充值记录
        /// </summary>
        /// <param name="rech"></param>
        /// <returns></returns>
        public string AddRecharge(recharge.RechargeModel rech)
        {
            DbParameter[] parms = {
                                       
                                        GenerateInParam("@vossuiteid", SqlDbType.Int, 4, rech.SuiteId),
                                        GenerateInParam("@out_trade_no", SqlDbType.VarChar, 50, rech.Out_trade_no),
                                        GenerateInParam("@account", SqlDbType.VarChar, 20, rech.Account),
                                        GenerateInParam("@platform", SqlDbType.VarChar, 10, rech.PlatForm),
                                        GenerateInParam("@type", SqlDbType.Int, 4, rech.Type),
                                        GenerateInParam("@role", SqlDbType.Int, 4, rech.Role)
                                    };
            string commandText = string.Format(@"
begin try

INSERT INTO [{0}rechargeinfo]([account],[vossuiteid],[out_trade_no],platform,type,role)
     VALUES (@account,@vossuiteid,@out_trade_no,@platform,@type,@role)
select '添加成功' state
end try
begin catch
select ERROR_MESSAGE() state
end catch
",
                                                RDBSHelper.RDBSTablePre);
            return RDBSHelper.ExecuteScalar(CommandType.Text, commandText, parms).ToString();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新充值记录 
        /// </summary>
        /// <param name="rech"></param>
        /// <returns></returns>
        public string UpdateRecharge(recharge.RechargeModel rech)
        {

            return "";
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 支付
        /// </summary>
        public ActionResult Pay()
        {
            /*微信支付三步:统一下单》调起支付接口》支付结果通知*/
            string result = WebHelper.GetPostStr();
            NameValueCollection parmas = WebHelper.GetParmList(result);

            //if (parmas.Keys.Count < 5)
            //{
            //    return AjaxResult("error", "缺少请求参数");
            //}



            #region 支付操作============================

            #region 基本参数===========================
            //商户订单号
            string outTradeNo = "hmk" + DateTime.Now.ToString("yyMMdd") + Randoms.CreateRandomValue(6, true);
            //订单名称
            string subject = BSPConfig.ShopConfig.SiteTitle;
            //付款金额
            string totalFee = (double.Parse(parmas["totalfee"]) * 100).ToString();
            //时间戳
            string timeStamp = TenpayUtil.getTimestamp();
            //随机字符串
            string nonceStr = TenpayUtil.getNoncestr();
            //服务器异步通知页面路径
            string notifyUrl = string.Format("{0}/appwechat/notify", BSPConfig.ShopConfig.SiteUrl);


            //记录充值信息
            OWZX.Model.RechargeModel rech = new OWZX.Model.RechargeModel
            {
                Out_trade_no = outTradeNo,
                Account      = parmas["account"],
                SuiteId      = parmas["vossuiteid"],
                PlatForm     = "微信",
                Type         = int.Parse(parmas["type"]),
                Role         = int.Parse(parmas["role"])
            };
            bool addres = Recharge.AddRecharge(rech);
            if (!addres)
            {
                return(AjaxResult("error", "记录充值信息失败"));
            }

            //string access_token = "";
            //string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", PayConfig.AppId, PayConfig.AppSecret);
            //string returnStr = HttpUtil.Get_Http(url, 120000);
            //LogUtil.WriteLog("returnStr 页面  returnStr:" + returnStr);
            //if (!returnStr.Contains("access_token"))
            //{
            //    return Content("");
            //}
            //else
            //{
            //    string[] list = returnStr.Split(',');
            //    access_token = list[0].Split(':')[1].Trim('"');
            //}

            //LogUtil.WriteLog("access_token 页面  access_token:" + access_token);

            //创建支付应答对象
            RequestHandler packageReqHandler = new RequestHandler(System.Web.HttpContext.Current);
            //初始化
            packageReqHandler.init();

            //设置package订单参数  具体参数列表请参考官方pdf文档,请勿随意设置
            packageReqHandler.setParameter("appid", PayConfig.AppId);
            packageReqHandler.setParameter("body", subject); //商品信息 127字符
            packageReqHandler.setParameter("mch_id", PayConfig.MchId);
            packageReqHandler.setParameter("nonce_str", nonceStr.ToLower());
            packageReqHandler.setParameter("notify_url", notifyUrl);
            packageReqHandler.setParameter("out_trade_no", outTradeNo);                  //商家订单号
            packageReqHandler.setParameter("spbill_create_ip", Request.UserHostAddress); //用户的公网ip,不是商户服务器IP
            packageReqHandler.setParameter("total_fee", totalFee);                       //商品金额,以分为单位(money * 100).ToString()
            packageReqHandler.setParameter("trade_type", "APP");
            //if (!string.IsNullOrEmpty(this.Attach))
            //    packageReqHandler.setParameter("attach", this.Attach);//自定义参数 127字符

            #endregion

            #region sign===============================
            string sign = packageReqHandler.CreateMd5Sign("key", PayConfig.AppKey);
            #endregion

            #region 获取package包======================
            packageReqHandler.setParameter("sign", sign);

            string data = packageReqHandler.parseXML();

            string prepayXml = HttpUtil.Send(data, "https://api.mch.weixin.qq.com/pay/unifiedorder");
            //LogUtil.WriteLog("WeiPay 页面  prepayXml:" + prepayXml);
            //获取预支付ID
            string      prepayId = "";
            string      package  = "";
            XmlDocument xdoc     = new XmlDocument();
            xdoc.LoadXml(prepayXml);
            XmlNode     xn  = xdoc.SelectSingleNode("xml");
            XmlNodeList xnl = xn.ChildNodes;
            if (xnl.Count > 7)
            {
                prepayId = xnl[7].InnerText;
                package  = string.Format("prepay_id={0}", prepayId);
                //LogUtil.WriteLog("WeiPay 页面  package:" + package);
            }
            if (xnl[0].InnerText.Trim() == "FAIL")
            {
                return(AjaxResult("error", "微信下单失败 " + xnl[1].InnerText));
            }
            #endregion

            #region 设置支付参数 输出页面  该部分参数请勿随意修改 ==============

            nonceStr = TenpayUtil.getNoncestr();
            RequestHandler paySignReqHandler = new RequestHandler(System.Web.HttpContext.Current);
            paySignReqHandler.setParameter("appid", PayConfig.AppId);
            paySignReqHandler.setParameter("noncestr", nonceStr.ToLower());
            paySignReqHandler.setParameter("package", "Sign=WXPay");
            paySignReqHandler.setParameter("partnerid", PayConfig.MchId);
            paySignReqHandler.setParameter("prepayid", prepayId);
            paySignReqHandler.setParameter("timestamp", timeStamp);
            string paySign = paySignReqHandler.CreateMd5Sign("key", PayConfig.AppKey);

            //LogUtil.WriteLog("WeiPay 页面  paySign:" + paySign);
            #endregion
            #endregion

            return(AjaxResult("success", string.Format("{0}\"appId\":\"{1}\",\"partnerId\":\"{2}\",\"prepayId\":\"{3}\",\"package\":\"{4}\",\"nonceStr\":\"{5}\",\"timeStamp\":\"{6}\",\"sign\":\"{7}\"{8}",
                                                       "{",
                                                       PayConfig.AppId,
                                                       PayConfig.MchId,
                                                       prepayId,
                                                       "Sign=WXPay",
                                                       nonceStr.ToLower(),
                                                       timeStamp,
                                                       paySign,
                                                       "}"), true));
        }