Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //读取站点配置信息
            Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(DTKeys.FILE_SITE_XML_CONFING);

            string order_type = DTRequest.GetFormString("pay_order_type"); //订单类型
            string order_no = DTRequest.GetFormString("pay_order_no");
            decimal order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0);
            string subject = DTRequest.GetFormString("pay_subject");
            if (order_no == "" || order_amount == 0 )
            {
                Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("对不起,您提交的参数有误!"));
                return;
            }
            //检查是否已登录
            Model.users userModel = new Web.UI.BasePage().GetUserInfo();
            if (userModel == null)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "login")); //尚未登录
                return;
            }
            if (userModel.amount < order_amount)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "recharge")); //账户的余额不足
                return;
            }

            if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //购买商品
            {
                BLL.orders bll = new BLL.orders();
                Model.orders model = bll.GetModel(order_no);
                if (model == null)
                {
                    Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("对不起,商品订单号不存在!"));
                    return;
                }
                //执行扣取账户金额
                int result = new BLL.amount_log().Add(userModel.id, userModel.user_name, DTEnums.AmountTypeEnum.BuyGoods.ToString(), order_no, model.payment_id, -1 * order_amount, subject, 1);
                if (result > 0)
                {
                    //更改订单状态
                    bool result1 = bll.UpdateField(order_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                    if (!result1)
                    {
                        Response.Redirect(new Web.UI.BasePage().linkurl("payment", "error"));
                        return;
                    }
                    //扣除积分
                    if (model.point < 0)
                    {
                        new BLL.point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no);
                    }
                    //支付成功
                    Response.Redirect(new Web.UI.BasePage().linkurl("payment1", "succeed", order_type, order_no));
                    return;
                }
            }
            Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("对不起,找不到需要支付的订单类型!"));
            return;
        }
Beispiel #2
0
        private void RptBind(string _strWhere, string _orderby)
        {
            this.page = DTRequest.GetQueryInt("page", 1);
            this.txtKeywords.Text = this.keywords;
            BLL.amount_log bll = new BLL.amount_log();
            this.rptList.DataSource = bll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
            this.rptList.DataBind();

            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("amount_log.aspx", "keywords={0}&page={1}",
                this.keywords, "__id__");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
Beispiel #3
0
        public void AddAmount(decimal price)
        {
            BLL.amount_log   bllog = new BLL.amount_log();
            Model.amount_log log   = new Model.amount_log();
            int Uid = WEBUserCurrent.UserID;

            log.user_id = Uid;
            log.value   = price;
            //log.user_name = orderNo;
            log.order_no   = hideNo.Value;
            log.payment_id = Utils.StringToNum(ddlzhifu.SelectedValue);
            log.status     = 0;

            int n = bllog.Add(log);
        }
Beispiel #4
0
 //批次刪除
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     //ChkAdminLevel("amount_log", DTEnums.ActionEnum.Delete.ToString()); //檢查許可權
     BLL.amount_log bll = new BLL.amount_log();
     for (int i = 0; i < rptList.Items.Count; i++)
     {
         int      id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
         CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
         if (cb.Checked)
         {
             bll.Delete(id);
         }
     }
     //JscriptMsg("批次刪除成功!", Utils.CombUrlTxt("amount_log.aspx", "keywords={0}", this.keywords), "Success");
 }
Beispiel #5
0
        private void RptBind(string _strWhere, string _orderby)
        {
            this.page             = DTRequest.GetQueryInt("page", 1);
            this.txtKeywords.Text = this.keywords;
            BLL.amount_log bll = new BLL.amount_log();
            this.rptList.DataSource = bll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
            this.rptList.DataBind();

            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("amount_log.aspx", "keywords={0}&page={1}",
                                              this.keywords, "__id__");

            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
Beispiel #6
0
 //批量删除
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     ChkAdminLevel("amount_log", DTEnums.ActionEnum.Delete.ToString()); //检查权限
     BLL.amount_log bll = new BLL.amount_log();
     for (int i = 0; i < rptList.Items.Count; i++)
     {
         int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
         CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
         if (cb.Checked)
         {
             bll.Delete(id);
         }
     }
     JscriptMsg("批量删除成功啦!", Utils.CombUrlTxt("amount_log.aspx", "keywords={0}", this.keywords), "Success");
 }
Beispiel #7
0
        private void user_point_convert(HttpContext context)
        {
            //检查系统是否启用兑换积分功能
            if (userConfig.pointcashrate == 0)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,网站已关闭兑换积分功能!\"}");
                return;
            }
            //检查用户是否登录
            Model.users model = new BasePage().GetUserInfo();
            if (model == null)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,用户没有登录或登录超时啦!\"}");
                return;
            }
            int amout = DTRequest.GetFormInt("txtAmount");
            string password = DTRequest.GetFormString("txtPassword");
            if (model.amount < 1)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,您账户上的余额不足!\"}");
                return;
            }
            if (amout < 1)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,最小兑换金额为1元!\"}");
                return;
            }
            if (amout > model.amount)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,您兑换的金额大于账户余额!\"}");
                return;
            }
            if (password == "")
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,请输入您账户的密码!\"}");
                return;
            }
            //验证密码
            if (DESEncrypt.Encrypt(password) != model.password)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,您输入的密码不正确!\"}");
                return;
            }
            //计算兑换后的积分值
            int convertPoint = (int)(Convert.ToDecimal(amout) * userConfig.pointcashrate);
            //扣除金额
            int amountNewId = new BLL.amount_log().Add(model.id, model.user_name, DTEnums.AmountTypeEnum.Convert.ToString(), amout * -1, "用户兑换积分", 1);
            //增加积分
            if (amountNewId < 1)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"转换过程中发生错误,请重新提交!\"}");
                return;
            }
            int pointNewId = new BLL.point_log().Add(model.id, model.user_name, convertPoint, "用户兑换积分");
            if (pointNewId < 1)
            {
                //返还金额
                new BLL.amount_log().Add(model.id, model.user_name, DTEnums.AmountTypeEnum.Convert.ToString(), amout, "用户兑换积分失败,返还金额", 1);
                context.Response.Write("{\"msg\":0, \"msgbox\":\"转换过程中发生错误,请重新提交!\"}");
                return;
            }

            context.Response.Write("{\"msg\":1, \"msgbox\":\"恭喜您,积分兑换成功啦!\"}");
            return;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary<string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify = new Notify();
                bool verifyResult = aliNotify.Verify(sPara, DTRequest.GetString("notify_id"), DTRequest.GetString("sign"));

                if (verifyResult)//验证成功
                {
                    string trade_no = DTRequest.GetString("trade_no"); //支付宝交易号
                    string order_no = DTRequest.GetString("out_trade_no"); //获取订单号
                    string total_fee = DTRequest.GetString("total_fee"); //获取总金额
                    string subject = DTRequest.GetString("subject"); //商品名称、订单名称
                    string body = DTRequest.GetString("body"); //商品描述、订单备注、描述
                    string buyer_email = DTRequest.GetString("buyer_email"); //买家支付宝账号
                    string trade_status = DTRequest.GetString("trade_status"); //交易状态
                    string order_type = DTRequest.GetString("extra_common_param"); //订单交易类别

                    if (DTRequest.GetString("trade_status") == "TRADE_FINISHED" || DTRequest.GetString("trade_status") == "TRADE_SUCCESS")
                    {
                        //修改支付状态、时间
                        if (order_type.ToLower() == DTEnums.AmountTypeEnum.Recharge.ToString().ToLower()) //在线充值
                        {
                            BLL.amount_log bll = new BLL.amount_log();
                            Model.amount_log model = bll.GetModel(order_no);
                            if (model == null)
                            {
                                Response.Write("该订单号不存在");
                                return;
                            }
                            if (model.value != decimal.Parse(total_fee))
                            {
                                Response.Write("订单金额和支付金额不相符");
                                return;
                            }
                            model.status = 1;
                            model.complete_time = DateTime.Now;
                            bool result = bll.Update(model);
                            if (!result)
                            {
                                Response.Write("修改订单状态失败");
                                return;
                            }
                        }
                        else
                            if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //购买商品
                            {
                                BLL.orders bll = new BLL.orders();
                                Model.orders model = bll.GetModel(order_no);
                                if (model == null)
                                {
                                    Response.Write("该订单号不存在");
                                    return;
                                }
                                if (model.order_amount != decimal.Parse(total_fee))
                                {
                                    Response.Write("订单金额和支付金额不相符");
                                    return;
                                }
                                bool result = bll.UpdateField(order_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                                if (!result)
                                {
                                    Response.Write("修改订单状态失败");
                                    return;
                                }
                                //扣除积分
                                if (model.point < 0)
                                {
                                    new BLL.point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no);
                                }
                            }
                    }

                    Response.Write("success"); //请不要修改或删除
                }
                else//验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);
            resHandler.setKey(TenpayUtil.tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(TenpayUtil.tenpay_key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", TenpayUtil.bargainor_id);
                queryReq.setParameter("notify_id", notify_id);

                //通信对象
                TenpayHttpClient httpClient = new TenpayHttpClient();
                httpClient.setTimeOut(5);
                //设置请求内容
                httpClient.setReqContent(queryReq.getRequestURL());
                //后台调用
                if (httpClient.call())
                {
                    //设置结果参数
                    ClientResponseHandler queryRes = new ClientResponseHandler();
                    queryRes.setContent(httpClient.getResContent());
                    queryRes.setKey(TenpayUtil.tenpay_key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //取结果参数做业务处理
                        string out_trade_no = resHandler.getParameter("out_trade_no");
                        //财付通订单号
                        string transaction_id = resHandler.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = resHandler.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = resHandler.getParameter("discount");
                        //订单类型
                        string order_type = resHandler.getParameter("attach");
                        //支付结果
                        string trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即时到帐 2中介担保
                        string trade_mode = resHandler.getParameter("trade_mode");
                        #region
                        //判断签名及结果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            //Response.Write("id验证成功");

                            if ("1".Equals(trade_mode))
                            {       //即时到账
                                if ("0".Equals(trade_state))
                                {
                                    //------------------------------
                                    //即时到账处理业务开始
                                    //------------------------------
                                    //处理数据库逻辑
                                    //注意交易单不要重复处理
                                    //注意判断返回金额

                                    //修改支付状态、时间
                                    if (order_type.ToLower() == DTEnums.AmountTypeEnum.Recharge.ToString().ToLower()) //在线充值
                                    {
                                        BLL.amount_log bll = new BLL.amount_log();
                                        Model.amount_log model = bll.GetModel(out_trade_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.value != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        model.status = 1;
                                        model.complete_time = DateTime.Now;
                                        bool result = bll.Update(model);
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                    }
                                    else if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //购买商品
                                    {
                                        BLL.orders bll = new BLL.orders();
                                        Model.orders model = bll.GetModel(out_trade_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.order_amount != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        bool result = bll.UpdateField(out_trade_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                        //扣除积分
                                        if (model.point < 0)
                                        {
                                            new BLL.point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no);
                                        }
                                    }

                                    //------------------------------
                                    //即时到账处理业务完毕
                                    //------------------------------

                                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("即时到账支付失败");
                                }
                            }
                        }
                        else
                        {
                            //错误时,返回结果可能没有签名,写日志trade_state、retcode、retmsg看失败详情。
                            //通知财付通处理失败,需要重新通知
                            Response.Write("查询验证签名失败或id验证失败");
                            Response.Write("retcode:" + queryRes.getParameter("retcode"));
                        }
                        #endregion
                    }
                    else
                    {
                        Response.Write("通知ID查询签名验证失败");
                    }
                }
                else
                {
                    //通知财付通处理失败,需要重新通知
                    Response.Write("后台调用通信失败");
                    //写错误日志
                    Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");

                }
            }
            else
            {
                Response.Write("签名验证失败");
            }
            Response.End();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sPara, DTRequest.GetString("notify_id"), DTRequest.GetString("sign"));

                if (verifyResult)                                                    //验证成功
                {
                    string trade_no     = DTRequest.GetString("trade_no");           //支付宝交易号
                    string order_no     = DTRequest.GetString("out_trade_no");       //获取订单号
                    string total_fee    = DTRequest.GetString("total_fee");          //获取总金额
                    string subject      = DTRequest.GetString("subject");            //商品名称、订单名称
                    string body         = DTRequest.GetString("body");               //商品描述、订单备注、描述
                    string buyer_email  = DTRequest.GetString("buyer_email");        //买家支付宝账号
                    string trade_status = DTRequest.GetString("trade_status");       //交易状态
                    string order_type   = DTRequest.GetString("extra_common_param"); //订单交易类别

                    if (DTRequest.GetString("trade_status") == "TRADE_FINISHED" || DTRequest.GetString("trade_status") == "TRADE_SUCCESS")
                    {
                        //修改支付状态、时间
                        if (order_type.ToLower() == DTEnums.AmountTypeEnum.Recharge.ToString().ToLower()) //在线充值
                        {
                            BLL.amount_log   bll   = new BLL.amount_log();
                            Model.amount_log model = bll.GetModel(order_no);
                            if (model == null)
                            {
                                Response.Write("该订单号不存在");
                                return;
                            }
                            if (model.value != decimal.Parse(total_fee))
                            {
                                Response.Write("订单金额和支付金额不相符");
                                return;
                            }
                            model.status        = 1;
                            model.complete_time = DateTime.Now;
                            bool result = bll.Update(model);
                            if (!result)
                            {
                                Response.Write("修改订单状态失败");
                                return;
                            }
                        }
                        else if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //购买商品
                        {
                            BLL.orders   bll   = new BLL.orders();
                            Model.orders model = bll.GetModel(order_no);
                            if (model == null)
                            {
                                Response.Write("该订单号不存在");
                                return;
                            }
                            if (model.order_amount != decimal.Parse(total_fee))
                            {
                                Response.Write("订单金额和支付金额不相符");
                                return;
                            }
                            bool result = bll.UpdateField(order_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                            if (!result)
                            {
                                Response.Write("修改订单状态失败");
                                return;
                            }
                            //扣除积分
                            if (model.point < 0)
                            {
                                new BLL.point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no);
                            }
                        }
                    }

                    Response.Write("success");  //请不要修改或删除
                }
                else//验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }
Beispiel #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(TenpayUtil.tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(TenpayUtil.tenpay_key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", TenpayUtil.bargainor_id);
                queryReq.setParameter("notify_id", notify_id);

                //通信对象
                TenpayHttpClient httpClient = new TenpayHttpClient();
                httpClient.setTimeOut(5);
                //设置请求内容
                httpClient.setReqContent(queryReq.getRequestURL());
                //后台调用
                if (httpClient.call())
                {
                    //设置结果参数
                    ClientResponseHandler queryRes = new ClientResponseHandler();
                    queryRes.setContent(httpClient.getResContent());
                    queryRes.setKey(TenpayUtil.tenpay_key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //取结果参数做业务处理
                        string out_trade_no = resHandler.getParameter("out_trade_no");
                        //财付通订单号
                        string transaction_id = resHandler.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = resHandler.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = resHandler.getParameter("discount");
                        //订单类型
                        string order_type = resHandler.getParameter("attach");
                        //支付结果
                        string trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即时到帐 2中介担保
                        string trade_mode = resHandler.getParameter("trade_mode");
                        #region
                        //判断签名及结果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            //Response.Write("id验证成功");

                            if ("1".Equals(trade_mode))
                            {       //即时到账
                                if ("0".Equals(trade_state))
                                {
                                    //------------------------------
                                    //即时到账处理业务开始
                                    //------------------------------
                                    //处理数据库逻辑
                                    //注意交易单不要重复处理
                                    //注意判断返回金额

                                    //修改支付状态、时间
                                    if (order_type.ToLower() == DTEnums.AmountTypeEnum.Recharge.ToString().ToLower()) //在线充值
                                    {
                                        BLL.amount_log   bll   = new BLL.amount_log();
                                        Model.amount_log model = bll.GetModel(out_trade_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.value != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        model.status        = 1;
                                        model.complete_time = DateTime.Now;
                                        bool result = bll.Update(model);
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                    }
                                    else if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //购买商品
                                    {
                                        BLL.orders   bll   = new BLL.orders();
                                        Model.orders model = bll.GetModel(out_trade_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.order_amount != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        bool result = bll.UpdateField(out_trade_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                        //扣除积分
                                        if (model.point < 0)
                                        {
                                            new BLL.point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no);
                                        }
                                    }

                                    //------------------------------
                                    //即时到账处理业务完毕
                                    //------------------------------

                                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("即时到账支付失败");
                                }
                            }
                        }
                        else
                        {
                            //错误时,返回结果可能没有签名,写日志trade_state、retcode、retmsg看失败详情。
                            //通知财付通处理失败,需要重新通知
                            Response.Write("查询验证签名失败或id验证失败");
                            Response.Write("retcode:" + queryRes.getParameter("retcode"));
                        }
                        #endregion
                    }
                    else
                    {
                        Response.Write("通知ID查询签名验证失败");
                    }
                }
                else
                {
                    //通知财付通处理失败,需要重新通知
                    Response.Write("后台调用通信失败");
                    //写错误日志
                    Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
                }
            }
            else
            {
                Response.Write("签名验证失败");
            }
            Response.End();
        }
Beispiel #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //創建ResponseHandler實例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(TenpayUtil.tenpay_key);

            //判斷簽名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通過通知ID查詢,確保通知來至財付通
                //創建查詢請求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(TenpayUtil.tenpay_key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", TenpayUtil.bargainor_id);
                queryReq.setParameter("notify_id", notify_id);

                //通信物件
                TenpayHttpClient httpClient = new TenpayHttpClient();
                httpClient.setTimeOut(5);
                //設置請求內容
                httpClient.setReqContent(queryReq.getRequestURL());
                //後臺調用
                if (httpClient.call())
                {
                    //設置結果參數
                    ClientResponseHandler queryRes = new ClientResponseHandler();
                    queryRes.setContent(httpClient.getResContent());
                    queryRes.setKey(TenpayUtil.tenpay_key);
                    //判斷簽名及結果
                    //只有簽名正確,retcode為0,trade_state為0才是付款成功
                    if (queryRes.isTenpaySign())
                    {
                        //取結果參數做業務處理
                        string out_trade_no = resHandler.getParameter("out_trade_no");
                        //財付通訂單號
                        string transaction_id = resHandler.getParameter("transaction_id");
                        //金額,以分為單位
                        string total_fee = resHandler.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原請求的total_fee
                        string discount = resHandler.getParameter("discount");
                        //訂單類型
                        string order_type = resHandler.getParameter("attach");
                        //付款結果
                        string trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即時到帳 2仲介擔保
                        string trade_mode = resHandler.getParameter("trade_mode");
                        #region
                        //判斷簽名及結果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            //Response.Write("id驗證成功");

                            if ("1".Equals(trade_mode))
                            {       //即時到賬
                                if ("0".Equals(trade_state))
                                {
                                    //------------------------------
                                    //即時到賬處理業務開始
                                    //------------------------------
                                    //處理資料庫邏輯
                                    //注意交易單不要重複處理
                                    //注意判斷返回金額

                                    //修改付款狀態、時間
                                    if (order_type.ToLower() == DTEnums.AmountTypeEnum.Recharge.ToString().ToLower()) //線上充值
                                    {
                                        BLL.amount_log   bll   = new BLL.amount_log();
                                        Model.amount_log model = bll.GetModel(out_trade_no);
                                        if (model == null)
                                        {
                                            Response.Write("該訂單號不存在");
                                            return;
                                        }
                                        if (model.value != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("訂單金額和付款金額不相符");
                                            return;
                                        }
                                        model.status        = 1;
                                        model.complete_time = DateTime.Now;
                                        bool result = bll.Update(model);
                                        if (!result)
                                        {
                                            Response.Write("修改訂單狀態失敗");
                                            return;
                                        }
                                    }
                                    else if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //購買商品
                                    {
                                        BLL.orders   bll   = new BLL.orders();
                                        Model.orders model = bll.GetModel(out_trade_no);
                                        if (model == null)
                                        {
                                            Response.Write("該訂單號不存在");
                                            return;
                                        }
                                        if (model.order_amount != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("訂單金額和付款金額不相符");
                                            return;
                                        }
                                        bool result = bll.UpdateField(out_trade_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                                        if (!result)
                                        {
                                            Response.Write("修改訂單狀態失敗");
                                            return;
                                        }
                                        //扣除積分
                                        if (model.point < 0)
                                        {
                                            new BLL.point_log().Add(model.user_id, model.user_name, model.point, "換購扣除積分,訂單號:" + model.order_no);
                                        }
                                    }

                                    //------------------------------
                                    //即時到賬處理業務完畢
                                    //------------------------------

                                    //給財付通系統發送成功資訊,財付通系統收到此結果後不再進行後續通知
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("即時到賬付款失敗");
                                }
                            }
                        }
                        else
                        {
                            //錯誤時,返回結果可能沒有簽名,寫日誌trade_state、retcode、retmsg看失敗詳情。
                            //通知財付通處理失敗,需要重新通知
                            Response.Write("查詢驗證簽名失敗或id驗證失敗");
                            Response.Write("retcode:" + queryRes.getParameter("retcode"));
                        }
                        #endregion
                    }
                    else
                    {
                        Response.Write("通知ID查詢簽名驗證失敗");
                    }
                }
                else
                {
                    //通知財付通處理失敗,需要重新通知
                    Response.Write("後臺調用通信失敗");
                    //寫錯誤日誌
                    Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
                }
            }
            else
            {
                Response.Write("簽名驗證失敗");
            }
            Response.End();
        }
Beispiel #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //读取站点配置信息
            Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(DTKeys.FILE_SITE_XML_CONFING);

            string  order_type   = DTRequest.GetFormString("pay_order_type"); //订单类型
            string  order_no     = DTRequest.GetFormString("pay_order_no");
            decimal order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0);
            string  subject      = DTRequest.GetFormString("pay_subject");

            if (order_no == "" || order_amount == 0)
            {
                Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("对不起,您提交的参数有误!"));
                return;
            }
            //检查是否已登录
            Model.users userModel = new Web.UI.BasePage().GetUserInfo();
            if (userModel == null)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "login")); //尚未登录
                return;
            }
            if (userModel.amount < order_amount)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "recharge")); //账户的余额不足
                return;
            }

            if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //购买商品
            {
                BLL.orders   bll   = new BLL.orders();
                Model.orders model = bll.GetModel(order_no);
                if (model == null)
                {
                    Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("对不起,商品订单号不存在!"));
                    return;
                }
                //执行扣取账户金额
                int result = new BLL.amount_log().Add(userModel.id, userModel.user_name, DTEnums.AmountTypeEnum.BuyGoods.ToString(), order_no, model.payment_id, -1 * order_amount, subject, 1);
                if (result > 0)
                {
                    //更改订单状态
                    bool result1 = bll.UpdateField(order_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                    if (!result1)
                    {
                        Response.Redirect(new Web.UI.BasePage().linkurl("payment", "error"));
                        return;
                    }
                    //扣除积分
                    if (model.point < 0)
                    {
                        new BLL.point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no);
                    }
                    //支付成功
                    Response.Redirect(new Web.UI.BasePage().linkurl("payment1", "succeed", order_type, order_no));
                    return;
                }
            }
            Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("对不起,找不到需要支付的订单类型!"));
            return;
        }
Beispiel #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判斷是否有帶返回參數
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sPara, DTRequest.GetString("notify_id"), DTRequest.GetString("sign"));

                if (verifyResult)                                                    //驗證成功
                {
                    string trade_no     = DTRequest.GetString("trade_no");           //支付寶交易號
                    string order_no     = DTRequest.GetString("out_trade_no");       //獲取訂單號
                    string total_fee    = DTRequest.GetString("total_fee");          //獲取總金額
                    string subject      = DTRequest.GetString("subject");            //商品名稱、訂單名稱
                    string body         = DTRequest.GetString("body");               //商品描述、訂單備註、描述
                    string buyer_email  = DTRequest.GetString("buyer_email");        //買家支付寶帳號
                    string trade_status = DTRequest.GetString("trade_status");       //交易狀態
                    string order_type   = DTRequest.GetString("extra_common_param"); //訂單交易類別

                    if (DTRequest.GetString("trade_status") == "TRADE_FINISHED" || DTRequest.GetString("trade_status") == "TRADE_SUCCESS")
                    {
                        //修改付款狀態、時間
                        if (order_type.ToLower() == DTEnums.AmountTypeEnum.Recharge.ToString().ToLower()) //線上儲值
                        {
                            BLL.amount_log   bll   = new BLL.amount_log();
                            Model.amount_log model = bll.GetModel(order_no);
                            if (model == null)
                            {
                                Response.Write("該訂單號不存在");
                                return;
                            }
                            if (model.value != decimal.Parse(total_fee))
                            {
                                Response.Write("訂單金額和付款金額不相符");
                                return;
                            }
                            model.status        = 1;
                            model.complete_time = DateTime.Now;
                            bool result = bll.Update(model);
                            if (!result)
                            {
                                Response.Write("修改訂單狀態失敗");
                                return;
                            }
                        }
                        else if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //購買商品
                        {
                            BLL.orders   bll   = new BLL.orders();
                            Model.orders model = bll.GetModel(order_no);
                            if (model == null)
                            {
                                Response.Write("該訂單號不存在");
                                return;
                            }
                            if (model.order_amount != decimal.Parse(total_fee))
                            {
                                Response.Write("訂單金額和付款金額不相符");
                                return;
                            }
                            bool result = bll.UpdateField(order_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                            if (!result)
                            {
                                Response.Write("修改訂單狀態失敗");
                                return;
                            }
                            //扣除積分
                            if (model.point < 0)
                            {
                                new BLL.point_log().Add(model.user_id, model.user_name, model.point, "換購扣除積分,訂單號:" + model.order_no);
                            }
                        }
                    }

                    Response.Write("success");  //請不要修改或刪除
                }
                else//驗證失敗
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("無通知參數");
            }
        }
Beispiel #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //讀取網站配置資料
            Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(DTKeys.FILE_SITE_XML_CONFING);

            string  order_type   = DTRequest.GetFormString("pay_order_type"); //訂單類型
            string  order_no     = DTRequest.GetFormString("pay_order_no");
            decimal order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0);
            string  subject      = DTRequest.GetFormString("pay_subject");

            if (order_no == "" || order_amount == 0)
            {
                Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("對不起,您送出的參數有誤!"));
                return;
            }
            //檢查是否已登入
            Model.users userModel = new Web.UI.BasePage().GetUserInfo();
            if (userModel == null)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "login")); //尚未登入
                return;
            }
            if (userModel.amount < order_amount)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "recharge")); //帳戶的餘額不足
                return;
            }

            if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //購買商品
            {
                BLL.orders   bll   = new BLL.orders();
                Model.orders model = bll.GetModel(order_no);
                if (model == null)
                {
                    Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("對不起,商品訂單號不存在!"));
                    return;
                }
                if (model.payment_status == 1)
                {
                    //執行扣取帳戶金額
                    int result = new BLL.amount_log().Add(userModel.id, userModel.user_name, DTEnums.AmountTypeEnum.BuyGoods.ToString(), order_no, model.payment_id, -1 * order_amount, subject, 1);
                    if (result > 0)
                    {
                        //更改訂單狀態
                        bool result1 = bll.UpdateField(order_no, "payment_status=2,payment_time='" + DateTime.Now + "'");
                        if (!result1)
                        {
                            Response.Redirect(new Web.UI.BasePage().linkurl("payment", "error"));
                            return;
                        }
                        //扣除積分
                        if (model.point < 0)
                        {
                            new BLL.point_log().Add(model.user_id, model.user_name, model.point, "換購扣除積分,訂單號:" + model.order_no);
                        }
                    }
                    else
                    {
                        Response.Redirect(new Web.UI.BasePage().linkurl("payment", "error"));
                        return;
                    }
                }
                //付款成功
                Response.Redirect(new Web.UI.BasePage().linkurl("payment1", "succeed", order_type, order_no));
                return;
            }
            Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("對不起,找不到需要付款的訂單類型!"));
            return;
        }