Beispiel #1
0
        public void Notify()
        {
            try
            {
                LogWrite("Notify");

                resHandler = new ClientResponseHandler(HttpContext.Current);

                LogWrite("isTenpaySign");

                if (this.resHandler.isTenpaySign())
                {
                    string  opstate = "-1";
                    int     status  = 4;
                    string  msg     = "支付失败";
                    decimal result  = 0M;

                    if (int.Parse(resHandler.getParameter("status").ToString())
                        == 0 && int.Parse(resHandler.getParameter("result_code").ToString()) == 0)
                    {
                        //Utils.writeFile("接口回调", resParam);
                        //此处可以在添加相关处理业务

                        if (decimal.TryParse(resHandler.getParameter("total_fee").ToString(), out result))
                        {
                            msg     = "支付成功";
                            opstate = "0";
                            status  = 2;
                        }
                    }

                    OrderBankUtils.SuppNotify(SuppId
                                              , resHandler.getParameter("out_trade_no").ToString()
                                              , resHandler.getParameter("transaction_id").ToString()
                                              , status
                                              , opstate
                                              , msg
                                              , result / 100M
                                              , 0M, "success", "failure");
                }
            }
            catch (Exception exception)
            {
                ExceptionHandler.HandleException(exception);
            }
        }
Beispiel #2
0
        protected override string OnNotify(System.Web.HttpContext context)
        {
            var handler = new ResponseHandler(context);

            handler.setKey(key);
            if (handler.isTenpaySign())
            {
                ///通知id
                string notify_id = handler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财富通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(context);
                queryReq.init();
                queryReq.setKey(key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/verifynotifyid.xml");
                queryReq.setParameter("partner", 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(key);

                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign() && queryRes.getParameter("retcode") == "0" && queryRes.getParameter("trade_state") == "0" && queryRes.getParameter("trade_mode") == "1")
                    {
                        string out_trade_no = queryRes.getParameter("out_trade_no");
                        //财富通订单号
                        string transaction_id = queryRes.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = queryRes.getParameter("total_fee");

                        PayHistory order = OnlinePayBusiness.Instance.GetOrder(out_trade_no, ThisCompanyType);
                        if (order == null)
                        {
                            CoreHelper.EventLog.Log(string.Format("在线支付确认时找不到订单{0} 订单号{1}", ThisCompanyType, out_trade_no), true);
                            //context.Response.Write("fail");
                            return("fail");
                        }
                        order.SpBillno = transaction_id;
                        decimal fee = Convert.ToDecimal(total_fee);

                        lock (thisLock)
                        {
                            Confirm(order, GetType(), fee / 100);
                        }
                        //context.Response.Write("success");
                        return("success");
                    }
                }
            }
            //context.Response.Write("fail");
            return("fail");
        }
Beispiel #3
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 = queryRes.getParameter("out_trade_no");
                    //财付通订单号
                    string transaction_id = queryRes.getParameter("transaction_id");
                    //金额,以分为单位
                    string total_fee = queryRes.getParameter("total_fee");
                    //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                    string discount = queryRes.getParameter("discount");
                    //支付结果
                    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))
                            {
                                //------------------------------
                                //即时到账处理业务开始
                                //------------------------------

                                //处理数据库逻辑
                                //注意交易单不要重复处理
                                //注意判断返回金额

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

                                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                Response.Write("success");
                            }
                            else
                            {
                                Response.Write("即时到账支付失败");
                            }
                        }
                        else if ("2".Equals(trade_mode))
                        { //中介担保
                          //------------------------------
                          //中介担保处理业务开始
                          //------------------------------
                          //处理数据库逻辑
                          //注意交易单不要重复处理
                          //注意判断返回金额

                            int iStatus = Convert.ToInt32(trade_state);
                            switch (iStatus)
                            {
                            case 0:             //付款成功

                                break;

                            case 1:             //交易创建

                                break;

                            case 2:             //收获地址填写完毕

                                break;

                            case 4:             //卖家发货成功

                                break;

                            case 5:             //买家收货确认,交易成功

                                break;

                            case 6:             //交易关闭,未完成超时关闭

                                break;

                            case 7:             //修改交易价格成功

                                break;

                            case 8:             //买家发起退款

                                break;

                            case 9:             //退款成功

                                break;

                            case 10:            //退款关闭

                                break;
                            }


                            //------------------------------
                            //中介担保处理业务开始
                            //------------------------------


                            //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                            Response.Write("success");
                        }
                    }
                    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)
    {
        //商户号
        string partner = "1900000109";


        //密钥
        string key = "8934e7d15453e97507ef794cf7b0519d";

        //创建请求对象
        RequestHandler reqHandler = new RequestHandler(Context);

        //通信对象
        TenpayHttpClient httpClient = new TenpayHttpClient();

        //应答对象
        ClientResponseHandler resHandler = new ClientResponseHandler();

        //-----------------------------
        //设置请求参数
        //-----------------------------
        reqHandler.init();
        reqHandler.setKey(key);
        reqHandler.setGateUrl("https://gw.tenpay.com/gateway/normalrefundquery.xml");


        reqHandler.setParameter("partner", partner);
        //out_trade_no和transaction_id、out_refund_no、refund_id至少一个必填,同时存在时以优先级高为准,
        //优先级为:refund_id>out_refund_no>transaction_id>out_trade_no
        //reqHandler.setParameter("refund_id", "1144357708");
        //reqHandler.setParameter("out_refund_no", "1144357708");
        reqHandler.setParameter("transaction_id", "1900000109201103020030626316");
        //reqHandler.setParameter("out_trade_no", "1144357708");

        string requestUrl = reqHandler.getRequestURL();

        httpClient.setCertInfo("c:\\key\\1900000107.pfx", "1900000107");
        //设置请求内容
        httpClient.setReqContent(requestUrl);
        //设置超时
        httpClient.setTimeOut(10);

        string rescontent = "";

        //后台调用

        if (httpClient.call())
        {
            //获取结果
            rescontent = httpClient.getResContent();

            resHandler.setKey(key);
            //设置结果参数
            resHandler.setContent(rescontent);

            //判断签名及结果
            if (resHandler.isTenpaySign() && resHandler.getParameter("retcode") == "0")
            {
                //商户订单号
                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");

                int refund_count = int.Parse(resHandler.getParameter("refund_count"));
                Response.Write("refund_count=" + refund_count + "<br>");
                for (int i = 0; i < refund_count; i++)
                {
                    string refund_state = resHandler.getParameter("refund_state_" + i);
                    string refund_id    = resHandler.getParameter("refund_id_" + i);

                    Response.Write("OK,refund " + i + ",transaction_id=" + resHandler.getParameter("transaction_id") + ", refund_id=" + refund_id + ", refund_state=" + refund_state + "<br>");
                }
            }
            else
            {
                //错误时,返回结果未签名。
                //如包格式错误或未确认结果的,请使用原来订单号重新发起,确认结果,避免多次操作
                Response.Write("业务错误信息或签名错误:" + resHandler.getParameter("retcode") + "," + resHandler.getParameter("retmsg") + "<br>");
            }
        }
        else
        {
            //后台调用通信失败
            Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
            //有可能因为网络原因,请求已经处理,但未收到应答。
        }


        //获取debug信息,建议把请求、应答内容、debug信息,通信返回码写入日志,方便定位问题

        /*
         * Response.Write("http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + "<br>");
         * Response.Write("req url:" + requestUrl + "<br/>");
         * Response.Write("req debug:" + reqHandler.getDebugInfo() + "<br/>");
         * Response.Write("res content:" + Server.HtmlEncode(rescontent) + "<br/>");
         * Response.Write("res debug:" + Server.HtmlEncode(resHandler.getDebugInfo()) + "<br/>");
         */
    }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取访问的商户COMID
            if (Domain_def.Domain_yanzheng(RequestUrl))//如果符合shop101.etown.cn的格式,则从多微信商户基本信息表中获取comid
            {
                comid = Int32.Parse(Domain_def.Domain_Huoqu(RequestUrl));
            }
            else
            {
                B2b_company_info companyinfo = B2bCompanyData.GetComId(RequestUrl);
                if (companyinfo != null)
                {
                    comid = companyinfo.Com_id;
                }
            }
            #region 获得财付通支付参数 tenpay_id,tenpay_key
            //根据产品判断商家是否含有自己的财付通支付:
            //a.含有的话支付到商家;
            //b.没有的话支付到平台财付通账户(易城账户,公司id=106)
            string tenpay_id          = "";
            string tenpay_key         = "";
            B2b_finance_paytype model = new B2b_finance_paytypeData().GetFinancePayTypeByComid(comid);
            if (model != null)
            {
                //商家财付通支付的所有参数都存在
                if (model.Tenpay_id != "" && model.Tenpay_key != "")
                {
                    tenpay_id  = model.Tenpay_id;
                    tenpay_key = model.Tenpay_key;
                }
                else
                {
                    model = new B2b_finance_paytypeData().GetFinancePayTypeByComid(106);
                    if (model == null)
                    {
                        Response.Write("商户财付通信息设置不完全!");
                        Response.End();
                        return;
                    }
                    else
                    {
                        //商家财付通支付的所有参数都存在
                        if (model.Tenpay_id != "" && model.Tenpay_key != "")
                        {
                            tenpay_id  = model.Tenpay_id;
                            tenpay_key = model.Tenpay_key;
                        }
                        else
                        {
                            Response.Write("商户财付通信息设置不完全!!");
                            Response.End();
                            return;
                        }
                    }
                }
            }
            else
            {
                model = new B2b_finance_paytypeData().GetFinancePayTypeByComid(106);
                if (model == null)
                {
                    Response.Write("商户财付通信息设置不完全!");
                    Response.End();
                    return;
                }
                else
                {
                    //商家财付通支付的所有参数都存在
                    if (model.Tenpay_id != "" && model.Tenpay_key != "")
                    {
                        tenpay_id  = model.Tenpay_id;
                        tenpay_key = model.Tenpay_key;
                    }
                    else
                    {
                        Response.Write("商户财付通信息设置不完全!!");
                        Response.End();
                        return;
                    }
                }
            }

            #endregion


            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);
            resHandler.setKey(tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(tenpay_key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", tenpay_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(tenpay_key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //取结果参数做业务处理
                        string out_trade_no = queryRes.getParameter("out_trade_no");
                        //财付通订单号
                        string transaction_id = queryRes.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = queryRes.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = queryRes.getParameter("discount");
                        //支付结果
                        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))
                                {
                                    //------------------------------
                                    //即时到账处理业务开始
                                    //------------------------------

                                    //处理数据库逻辑
                                    //注意交易单不要重复处理
                                    //注意判断返回金额

                                    //------------------------------
                                    //即时到账处理业务完毕
                                    //------------------------------
                                    string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(notify_id, Int32.Parse(out_trade_no), total_fee.ConvertTo <decimal>(), "TRADE_SUCCESS");

                                    //对分销充值订单支付返回,对绑定订单进行处理确认
                                    var handdata = OrderJsonData.agentorderpay_Hand(Int32.Parse(out_trade_no));


                                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("即时到账支付失败");
                                }
                            }
                            else if ("2".Equals(trade_mode))
                            { //中介担保
                              //------------------------------
                              //中介担保处理业务开始
                              //------------------------------
                              //处理数据库逻辑
                              //注意交易单不要重复处理
                              //注意判断返回金额

                                int iStatus = Convert.ToInt32(trade_state);
                                switch (iStatus)
                                {
                                case 0:                 //付款成功

                                    break;

                                case 1:                 //交易创建

                                    break;

                                case 2:                 //收获地址填写完毕

                                    break;

                                case 4:                 //卖家发货成功

                                    break;

                                case 5:                 //买家收货确认,交易成功

                                    break;

                                case 6:                 //交易关闭,未完成超时关闭

                                    break;

                                case 7:                 //修改交易价格成功

                                    break;

                                case 8:                 //买家发起退款

                                    break;

                                case 9:                 //退款成功

                                    break;

                                case 10:        //退款关闭

                                    break;
                                }


                                //------------------------------
                                //中介担保处理业务开始
                                //------------------------------


                                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                Response.Write("success");
                            }
                        }
                        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();
        }
        /// <summary>
        /// 通知页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Notify()
        {
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(HttpContext);

            resHandler.setKey(TenpayUtil.tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(HttpContext);
                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 = queryRes.getParameter("out_trade_no");
                        //财付通订单号
                        string transaction_id = queryRes.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = queryRes.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = queryRes.getParameter("discount");
                        //支付结果
                        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))
                                {
                                    //------------------------------
                                    //即时到账处理业务开始
                                    //------------------------------

                                    #region 订单完成逻辑
                                    psv.FinishOrder(out_trade_no, transaction_id, FeeType.TenPay);


                                    #endregion

                                    //处理数据库逻辑
                                    //注意交易单不要重复处理
                                    //注意判断返回金额

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

                                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                    //Response.Write("success");

                                    return(RedirectToAction("Success"));
                                }
                                else
                                {
                                    return(Content("即时到账支付失败"));
                                }
                            }
                        }
                        else
                        {
                            return(Content("查询验证签名失败或id验证失败"));
                        }
                        #endregion
                    }
                    else
                    {
                        return(Content("通知ID查询签名验证失败"));
                    }
                }
                else
                {
                    return(Content("后台调用通信失败"));
                }
            }
            else
            {
                return(Content("签名验证失败"));
            }

            return(Content("支付失败"));
        }
Beispiel #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TenpayUtil xmlConfig = new TenpayUtil();
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(xmlConfig.key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(xmlConfig.key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", xmlConfig.partner);
                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(xmlConfig.key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //取结果参数做业务处理
                        string order_no = resHandler.getParameter("out_trade_no").ToUpper();
                        //财付通订单号
                        string trade_no = resHandler.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = resHandler.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = resHandler.getParameter("discount");
                        //支付结果
                        string trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即时到帐 2中介担保
                        string trade_mode = resHandler.getParameter("trade_mode");

                        //判断签名及结果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            if ("1".Equals(trade_mode))
                            {
                                #region 即时到账处理方法====================================
                                if ("0".Equals(trade_state))
                                {
                                    if (order_no.StartsWith("R")) //充值订单
                                    {
                                        BLL.user_recharge   bll   = new BLL.user_recharge();
                                        Model.user_recharge model = bll.GetModel(order_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.status == 1) //已成功
                                        {
                                            Response.Write("success");
                                            return;
                                        }
                                        if (model.amount != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        bool result = bll.Confirm(order_no);
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                    }
                                    else if (order_no.StartsWith("B")) //商品订单
                                    {
                                        BLL.orders   bll   = new BLL.orders();
                                        Model.orders model = bll.GetModel(order_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.payment_status == 2) //已付款
                                        {
                                            Response.Write("success");
                                            return;
                                        }
                                        if (model.order_amount != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        bool result = bll.UpdateField(order_no, "trade_no='" + trade_no + "',status=2,payment_status=2,payment_time='" + DateTime.Now + "'");
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                        new CMS.API.ClsDll.buyersite().Add(model);

                                        //扣除积分
                                        if (model.point < 0)
                                        {
                                            new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no, false);
                                        }
                                    }
                                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("即时到账支付失败");
                                }
                                #endregion
                            }
                            else if ("2".Equals(trade_mode)) //担保交易
                            {
                                #region 担保交易处理方法====================================
                                if ("0".Equals(trade_state))      //付款成功
                                {
                                    if (order_no.StartsWith("R")) //充值订单
                                    {
                                        BLL.user_recharge   bll   = new BLL.user_recharge();
                                        Model.user_recharge model = bll.GetModel(order_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.status == 1) //已成功
                                        {
                                            Response.Write("success");
                                            return;
                                        }
                                        if (model.amount != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        bool result = bll.Confirm(order_no);
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                    }
                                    else if (order_no.StartsWith("B")) //商品订单
                                    {
                                        BLL.orders   bll   = new BLL.orders();
                                        Model.orders model = bll.GetModel(order_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.payment_status == 2) //已付款
                                        {
                                            Response.Write("success");
                                            return;
                                        }
                                        if (model.order_amount != (decimal.Parse(total_fee) / 100))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        bool result = bll.UpdateField(order_no, "trade_no='" + trade_no + "',status=2,payment_status=2,payment_time='" + DateTime.Now + "'");
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                        new CMS.API.ClsDll.buyersite().Add(model);

                                        //扣除积分
                                        if (model.point < 0)
                                        {
                                            new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no, false);
                                        }
                                    }
                                }
                                else if ("5".Equals(trade_state)) //买家收货确认,交易成功
                                {
                                    if (order_no.StartsWith("B")) //商品订单
                                    {
                                        BLL.orders   bll   = new BLL.orders();
                                        Model.orders model = bll.GetModel(order_no);
                                        if (model == null)
                                        {
                                            Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.status > 2) //订单状态已经完成结束
                                        {
                                            Response.Write("success");
                                            return;
                                        }
                                        if (model.order_amount != decimal.Parse(total_fee))
                                        {
                                            Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        bool result = bll.UpdateField(order_no, "status=3,complete_time='" + DateTime.Now + "'");
                                        if (!result)
                                        {
                                            Response.Write("修改订单状态失败");
                                            return;
                                        }
                                        //给会员增加积分检查升级
                                        if (model.user_id > 0 && model.point > 0)
                                        {
                                            new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "购物获得积分,订单号:" + model.order_no, true);
                                        }
                                    }
                                }
                                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                Response.Write("success");
                                #endregion
                            }
                        }
                        else
                        {
                            Response.Write("查询验证签名失败或id验证失败");
                        }
                    }
                    else
                    {
                        Response.Write("通知ID查询签名验证失败");
                    }
                }
                else
                {
                    Response.Write("后台调用通信失败");
                }
            }
            else
            {
                Response.Write("签名验证失败");
            }
            Response.End();
        }
Beispiel #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TenpayUtil      tenpayUtil      = new TenpayUtil();
            ResponseHandler responseHandler = new ResponseHandler(this.Context);

            responseHandler.setKey(tenpayUtil.key);
            if (responseHandler.isTenpaySign())
            {
                string         parameter1     = responseHandler.getParameter("notify_id");
                RequestHandler requestHandler = new RequestHandler(this.Context);
                requestHandler.init();
                requestHandler.setKey(tenpayUtil.key);
                requestHandler.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                requestHandler.setParameter("partner", tenpayUtil.partner);
                requestHandler.setParameter("notify_id", parameter1);
                TenpayHttpClient tenpayHttpClient = new TenpayHttpClient();
                tenpayHttpClient.setTimeOut(5);
                tenpayHttpClient.setReqContent(requestHandler.getRequestURL());
                if (tenpayHttpClient.call())
                {
                    ClientResponseHandler clientResponseHandler = new ClientResponseHandler();
                    clientResponseHandler.setContent(tenpayHttpClient.getResContent());
                    clientResponseHandler.setKey(tenpayUtil.key);
                    if (clientResponseHandler.isTenpaySign())
                    {
                        string upper      = responseHandler.getParameter("out_trade_no").ToUpper();
                        string parameter2 = responseHandler.getParameter("transaction_id");
                        string parameter3 = responseHandler.getParameter("total_fee");
                        responseHandler.getParameter("discount");
                        string parameter4 = responseHandler.getParameter("trade_state");
                        string parameter5 = responseHandler.getParameter("trade_mode");
                        if ("0".Equals(clientResponseHandler.getParameter("retcode")))
                        {
                            if ("1".Equals(parameter5))
                            {
                                if ("0".Equals(parameter4))
                                {
                                    if (upper.StartsWith("R"))
                                    {
                                        Rain.BLL.user_recharge   userRecharge = new Rain.BLL.user_recharge();
                                        Rain.Model.user_recharge model        = userRecharge.GetModel(upper);
                                        if (model == null)
                                        {
                                            this.Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.status == 1)
                                        {
                                            this.Response.Write("success");
                                            return;
                                        }
                                        if (model.amount != Decimal.Parse(parameter3) / new Decimal(100))
                                        {
                                            this.Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        if (!userRecharge.Confirm(upper))
                                        {
                                            this.Response.Write("修改订单状态失败");
                                            return;
                                        }
                                    }
                                    else if (upper.StartsWith("B"))
                                    {
                                        Rain.BLL.orders   orders = new Rain.BLL.orders();
                                        Rain.Model.orders model  = orders.GetModel(upper);
                                        if (model == null)
                                        {
                                            this.Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.payment_status == 2)
                                        {
                                            this.Response.Write("success");
                                            return;
                                        }
                                        if (model.order_amount != Decimal.Parse(parameter3) / new Decimal(100))
                                        {
                                            this.Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        if (!orders.UpdateField(upper, "trade_no='" + parameter2 + "',status=2,payment_status=2,payment_time='" + (object)DateTime.Now + "'"))
                                        {
                                            this.Response.Write("修改订单状态失败");
                                            return;
                                        }
                                        if (model.point < 0)
                                        {
                                            new Rain.BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no, false);
                                        }
                                    }
                                    this.Response.Write("success");
                                }
                                else
                                {
                                    this.Response.Write("即时到账支付失败");
                                }
                            }
                            else if ("2".Equals(parameter5))
                            {
                                if ("0".Equals(parameter4))
                                {
                                    if (upper.StartsWith("R"))
                                    {
                                        Rain.BLL.user_recharge   userRecharge = new Rain.BLL.user_recharge();
                                        Rain.Model.user_recharge model        = userRecharge.GetModel(upper);
                                        if (model == null)
                                        {
                                            this.Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.status == 1)
                                        {
                                            this.Response.Write("success");
                                            return;
                                        }
                                        if (model.amount != Decimal.Parse(parameter3) / new Decimal(100))
                                        {
                                            this.Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        if (!userRecharge.Confirm(upper))
                                        {
                                            this.Response.Write("修改订单状态失败");
                                            return;
                                        }
                                    }
                                    else if (upper.StartsWith("B"))
                                    {
                                        Rain.BLL.orders   orders = new Rain.BLL.orders();
                                        Rain.Model.orders model  = orders.GetModel(upper);
                                        if (model == null)
                                        {
                                            this.Response.Write("该订单号不存在");
                                            return;
                                        }
                                        if (model.payment_status == 2)
                                        {
                                            this.Response.Write("success");
                                            return;
                                        }
                                        if (model.order_amount != Decimal.Parse(parameter3) / new Decimal(100))
                                        {
                                            this.Response.Write("订单金额和支付金额不相符");
                                            return;
                                        }
                                        if (!orders.UpdateField(upper, "trade_no='" + parameter2 + "',status=2,payment_status=2,payment_time='" + (object)DateTime.Now + "'"))
                                        {
                                            this.Response.Write("修改订单状态失败");
                                            return;
                                        }
                                        if (model.point < 0)
                                        {
                                            new Rain.BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no, false);
                                        }
                                    }
                                }
                                else if ("5".Equals(parameter4) && upper.StartsWith("B"))
                                {
                                    Rain.BLL.orders   orders = new Rain.BLL.orders();
                                    Rain.Model.orders model  = orders.GetModel(upper);
                                    if (model == null)
                                    {
                                        this.Response.Write("该订单号不存在");
                                        return;
                                    }
                                    if (model.status > 2)
                                    {
                                        this.Response.Write("success");
                                        return;
                                    }
                                    if (model.order_amount != Decimal.Parse(parameter3))
                                    {
                                        this.Response.Write("订单金额和支付金额不相符");
                                        return;
                                    }
                                    if (!orders.UpdateField(upper, "status=3,complete_time='" + (object)DateTime.Now + "'"))
                                    {
                                        this.Response.Write("修改订单状态失败");
                                        return;
                                    }
                                    if (model.user_id > 0 && model.point > 0)
                                    {
                                        new Rain.BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "购物获得积分,订单号:" + model.order_no, true);
                                    }
                                }
                                this.Response.Write("success");
                            }
                        }
                        else
                        {
                            this.Response.Write("查询验证签名失败或id验证失败");
                        }
                    }
                    else
                    {
                        this.Response.Write("通知ID查询签名验证失败");
                    }
                }
                else
                {
                    this.Response.Write("后台调用通信失败");
                }
            }
            else
            {
                this.Response.Write("签名验证失败");
            }
            this.Response.End();
        }
Beispiel #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //商户号
            string bargainor_id = ConfigurationManager.AppSettings["bargainor_id"].ToString();

            //密钥
            string key = ConfigurationManager.AppSettings["tenpay_key"].ToString();


            //创建请求对象
            RequestHandler reqHandler = new RequestHandler(Context);

            //通信对象
            TenpayHttpClient httpClient = new TenpayHttpClient();

            //应答对象
            ClientResponseHandler resHandler = new ClientResponseHandler();


            //当前时间 yyyyMMdd
            string domain_url    = ConfigurationManager.AppSettings["domain_url"].ToString();
            string date          = DateTime.Now.ToString("yyyyMMdd");
            string sp_billno     = Request["order_no"];
            string product_name  = Request["product_name"];
            string order_price   = Request["order_price"];;
            string remarkexplain = Request["remarkexplain"];
            double money         = 0;

            if (null == Request["order_price"])
            {
                Response.End();
                return;
            }
            try
            {
                money = Convert.ToDouble(order_price);
            }
            catch
            {
                //Response.Write("支付金额格式错误!");
                //Response.End();
                //return;
            }
            if (null == sp_billno)
            {
                //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            }
            else
            {
                sp_billno = Request["order_no"].ToString();
            }


            reqHandler.init();
            //设置密钥
            reqHandler.setKey(key);
            reqHandler.setGateUrl("https://wap.tenpay.com/cgi-bin/wappayv2.0/wappay_init.cgi");



            //-----------------------------
            //设置支付初始化参数
            //-----------------------------
            reqHandler.setParameter("ver", "2.0");
            reqHandler.setParameter("charset", "1");
            reqHandler.setParameter("bank_type", "0");
            reqHandler.setParameter("desc", "订单" + sp_billno);
            reqHandler.setParameter("bargainor_id", bargainor_id);
            reqHandler.setParameter("sp_billno", sp_billno);
            reqHandler.setParameter("total_fee", (money * 100).ToString());
            reqHandler.setParameter("fee_type", "1");
            reqHandler.setParameter("notify_url", domain_url + "/PayRetrun/ZFPay/tenpay/payNotifyUrl.aspx");
            reqHandler.setParameter("callback_url", domain_url + "/PayRetrun/ZFPay/tenpay/payCallbackUrl.aspx");
            reqHandler.setParameter("attach", "attach");

            string initRequestUrl = reqHandler.getRequestURL();

            //设置请求内容
            httpClient.setReqContent(initRequestUrl);
            //设置超时
            httpClient.setTimeOut(5);

            string rescontent    = "";
            string payRequestUrl = "";

            //后台调用
            if (httpClient.call())
            {
                //获取结果
                rescontent = httpClient.getResContent();

                //设置结果参数
                resHandler.setContent(rescontent);

                string token_id = resHandler.getParameter("token_id");

                //成功,则token_id有只
                if (token_id != "")
                {
                    //生成支付请求
                    payRequestUrl = "https://wap.tenpay.com/cgi-bin/wappayv2.0/wappay_gate.cgi?token_id=" + TenpayUtil.UrlEncode(token_id, Request.ContentEncoding.BodyName);

                    //Get的实现方式
                    string a_link = "<script type='text/javascript'>window.location = '" + payRequestUrl + "';</script>";
                    Response.Write(a_link);
                }
                else
                {
                    //获取token_id调用失败 ,显示错误 页面
                    Response.Write("支付初始化错误:" + resHandler.getParameter("err_info") + "<br>");
                }
            }
            else
            {
                //后台调用通信失败
                Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
                //有可能因为网络原因,请求已经处理,但未收到应答。
            }


            //获取debug信息,建议把请求、应答内容、debug信息,通信返回码写入日志,方便定位问题

            /*
             * Response.Write("http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + "<br>");
             * Response.Write("req url:" + initRequestUrl + "<br/>");
             * Response.Write("req debug:" + reqHandler.getDebugInfo() + "<br/>");
             * Response.Write("res content:" + Server.HtmlEncode(rescontent) + "<br/>");
             * Response.Write("res debug:" + Server.HtmlEncode(resHandler.getDebugInfo()) + "<br/>");
             * Response.Write("pay req url:" + payRequestUrl + "<br/>");
             */
        }
Beispiel #10
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 #11
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            System.Web.HttpContext Context = System.Web.HttpContext.Current;

            //创建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 trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即时到帐 2中介担保
                        string trade_mode = resHandler.getParameter("trade_mode");
                        #region
                        //判断签名及结果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            if ("1".Equals(trade_mode) && "0".Equals(trade_state))
                            {
                                int      oid        = TypeHelper.StringToInt(queryRes.getParameter("out_trade_no"));  //商户订单号
                                string   tradeSN    = queryRes.getParameter("transaction_id");                        //财付通订单号
                                decimal  tradeMoney = TypeHelper.StringToDecimal(queryRes.getParameter("total_fee")); //金额,以分为单位
                                DateTime tradeTime  = DateTime.Now;                                                   //交易时间

                                OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                                if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                                {
                                    Orders.PayOrder(oid, OrderState.Confirming, tradeSN, DateTime.Now);
                                    OrderActions.CreateOrderAction(new OrderActionInfo()
                                    {
                                        Oid         = oid,
                                        Uid         = orderInfo.Uid,
                                        RealName    = "本人",
                                        AdminGid    = 1,
                                        AdminGTitle = "非管理员",
                                        ActionType  = (int)OrderActionType.Pay,
                                        ActionTime  = tradeTime,
                                        ActionDes   = "你使用财付通支付订单成功,财付通交易号为:" + tradeSN
                                    });
                                }

                                return(new EmptyResult());
                            }
                            else
                            {
                                return(Content("交易失败"));
                            }
                        }
                        else
                        {
                            return(Content("查询验证签名失败或id验证失败"));
                        }
                        #endregion
                    }
                    else
                    {
                        return(Content("通知ID查询签名验证失败"));
                    }
                }
                else
                {
                    return(Content("后台调用通信失败"));
                }
            }
            else
            {
                return(Content("签名验证失败"));
            }
        }
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
        /// <summary>
        /// 财付通支付接口
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(string id) //传入订单ID  输入订单价格等信息  订单必须是未支付状态
        {
            try
            {
                var order      = psv.GetOrderByOrderNo(id);
                var tenpay_id  = ConfigurationManager.AppSettings["tenpay_bargainor_id"]; //商户号
                var tenpay_key = ConfigurationManager.AppSettings["tenpay_key"];          //密钥
                //创建RequestHandler实例
                RequestHandler reqHandler = new RequestHandler(HttpContext);
                //通信对象
                TenpayHttpClient httpClient = new TenpayHttpClient();
                //应答对象
                ClientResponseHandler resHandler = new ClientResponseHandler();

                reqHandler.init();
                //设置密钥
                reqHandler.setKey(TenpayUtil.tenpay_key);
                reqHandler.setGateUrl("https://wap.tenpay.com/cgi-bin/wappayv2.0/wappay_init.cgi");


                //-----------------------------
                //设置支付初始化参数
                //-----------------------------
                reqHandler.setParameter("ver", "2.0");
                reqHandler.setParameter("charset", "1");
                reqHandler.setParameter("bank_type", "0");
                reqHandler.setParameter("desc", "蛋糕");          //订单描述
                reqHandler.setParameter("bargainor_id", tenpay_id);
                reqHandler.setParameter("sp_billno", order.No); //订单号
                reqHandler.setParameter("total_fee", (Convert.ToDouble(order.NeedPay) * 100).ToString());
                reqHandler.setParameter("fee_type", "1");
                reqHandler.setParameter("notify_url", ConfigurationManager.AppSettings["tenpay_notify"]);
                reqHandler.setParameter("callback_url", ConfigurationManager.AppSettings["tenpay_return"]);
                reqHandler.setParameter("attach", "attach");

                string initRequestUrl = reqHandler.getRequestURL();
                //设置请求内容
                httpClient.setReqContent(initRequestUrl);
                //设置超时
                httpClient.setTimeOut(5);

                string rescontent    = "";
                string payRequestUrl = "";

                //后台调用
                if (httpClient.call())
                {
                    //获取结果
                    rescontent = httpClient.getResContent();

                    //设置结果参数
                    resHandler.setContent(rescontent);

                    string token_id = resHandler.getParameter("token_id");

                    //成功,则token_id有只
                    if (token_id != "")
                    {
                        //生成支付请求
                        payRequestUrl = "https://wap.tenpay.com/cgi-bin/wappayv2.0/wappay_gate.cgi?token_id=" + TenpayUtil.UrlEncode(token_id, Request.ContentEncoding.BodyName);

                        return(Redirect(payRequestUrl));
                    }
                    else
                    {
                        return(Content("支付初始化错误:" + resHandler.getParameter("err_info") + "<br>"));
                    }
                }
                else
                {
                    return(Content("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>"));
                }
            }
            catch
            {
                return(Content("支付失败"));
            }
        }
Beispiel #14
0
        public override bool CheckOrder(PayHistory order, out string message)
        {
            //创建请求对象
            RequestHandler reqHandler = new RequestHandler(HttpContext.Current);

            //通信对象
            TenpayHttpClient httpClient = new TenpayHttpClient();

            //应答对象
            ClientResponseHandler resHandler = new ClientResponseHandler();

            //-----------------------------
            //设置请求参数
            //-----------------------------
            reqHandler.init();
            reqHandler.setKey(key);
            reqHandler.setGateUrl("https://gw.tenpay.com/gateway/normalorderquery.xml");

            reqHandler.setParameter("partner", bargainor_id);
            //out_trade_no和transaction_id至少一个必填,同时存在时transaction_id优先
            reqHandler.setParameter("out_trade_no", order.OrderId);
            //reqHandler.setParameter("transaction_id", "1900000109201103020030626316");

            string requestUrl = reqHandler.getRequestURL();

            //设置请求内容
            httpClient.setReqContent(requestUrl);
            //设置超时
            httpClient.setTimeOut(10);

            string rescontent = "";

            //后台调用
            if (httpClient.call())
            {
                //获取结果
                rescontent = httpClient.getResContent();

                resHandler.setKey(key);
                //设置结果参数
                resHandler.setContent(rescontent);

                //判断签名及结果
                if (resHandler.isTenpaySign() && resHandler.getParameter("retcode") == "0")
                {
                    //商户订单号
                    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 trade_state = resHandler.getParameter("trade_state");

                    //支付成功
                    if (trade_state == "0")
                    {
                        if (order.Status != OrderStatus.已确认)
                        {
                            Confirm(order, GetType(), order.Amount);
                        }
                        message = "成功";
                        return(true);
                    }
                }
                else
                {
                    message = "失败";
                    return(false);
                }
            }
            else
            {
                message = "服务器返回:" + httpClient.getResponseCode();
                return(false);
            }
            message = "失败";
            return(false);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        //商户号
        string partner = "1900000109";


        //密钥
        string key = "8934e7d15453e97507ef794cf7b0519d";

        //创建请求对象
        RequestHandler reqHandler = new RequestHandler(Context);

        //通信对象
        TenpayHttpClient httpClient = new TenpayHttpClient();

        //应答对象
        ClientResponseHandler resHandler = new ClientResponseHandler();

        //-----------------------------
        //设置请求参数
        //-----------------------------
        reqHandler.init();
        reqHandler.setKey(key);
        reqHandler.setGateUrl("https://mch.tenpay.com/refundapi/gateway/refund.xml");

        reqHandler.setParameter("partner", partner);
        //out_trade_no和transaction_id至少一个必填,同时存在时transaction_id优先
        //reqHandler.setParameter("out_trade_no", "1458268681");
        reqHandler.setParameter("transaction_id", "1900000109201103020030626316");
        reqHandler.setParameter("out_refund_no", "2011030201");
        reqHandler.setParameter("total_fee", "1");
        reqHandler.setParameter("refund_fee", "1");
        reqHandler.setParameter("refund_fee", "1");
        reqHandler.setParameter("op_user_id", "1900000109");
        reqHandler.setParameter("op_user_passwd", MD5Util.GetMD5("111111", "GBK"));
        reqHandler.setParameter("service_version", "1.1");

        string requestUrl = reqHandler.getRequestURL();

        httpClient.setCertInfo("c:\\key\\1900000109.pfx", "1900000109");
        //设置请求内容
        httpClient.setReqContent(requestUrl);
        //设置超时
        httpClient.setTimeOut(10);

        string rescontent = "";

        //后台调用
        if (httpClient.call())
        {
            //获取结果
            rescontent = httpClient.getResContent();

            resHandler.setKey(key);
            //设置结果参数
            resHandler.setContent(rescontent);

            //判断签名及结果
            if (resHandler.isTenpaySign() && resHandler.getParameter("retcode") == "0")
            {
                //商户订单号
                string out_trade_no = resHandler.getParameter("out_trade_no");
                //财付通订单号
                string transaction_id = resHandler.getParameter("transaction_id");



                //业务处理
                Response.Write("OK,transaction_id=" + resHandler.getParameter("transaction_id") + "<br>");
            }
            else
            {
                //错误时,返回结果未签名。
                //如包格式错误或未确认结果的,请使用原来订单号重新发起,确认结果,避免多次操作
                Response.Write("业务错误信息或签名错误:" + resHandler.getParameter("retcode") + "," + resHandler.getParameter("retmsg") + "<br>");
            }
        }
        else
        {
            //后台调用通信失败
            Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
            //有可能因为网络原因,请求已经处理,但未收到应答。
        }


        //获取debug信息,建议把请求、应答内容、debug信息,通信返回码写入日志,方便定位问题

        Response.Write("http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + "<br>");
        Response.Write("req url:" + requestUrl + "<br/>");
        Response.Write("req debug:" + reqHandler.getDebugInfo() + "<br/>");
        Response.Write("res content:" + Server.HtmlEncode(rescontent) + "<br/>");
        Response.Write("res debug:" + Server.HtmlEncode(resHandler.getDebugInfo()) + "<br/>");
    }
Beispiel #16
0
        /// <summary>
        /// 退款接口,可重复提交得到状态
        /// </summary>
        /// <param name="order"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public override bool RefundOrder(PayHistory order, out string message)
        {
            #region 退款
            RequestHandler reqHandler = new RequestHandler(HttpContext.Current);

            //通信对象
            TenpayHttpClient      httpClient = new TenpayHttpClient();
            ClientResponseHandler resHandler = new ClientResponseHandler();
            //-----------------------------
            //设置请求参数
            //-----------------------------
            reqHandler.init();
            reqHandler.setKey(key);
            reqHandler.setGateUrl("https://mch.tenpay.com/refundapi/gateway/refund.xml");

            reqHandler.setParameter("partner", bargainor_id);
            //out_trade_no和transaction_id至少一个必填,同时存在时transaction_id优先
            //reqHandler.setParameter("out_trade_no", order.OrderId);
            reqHandler.setParameter("transaction_id", order.OrderId);
            reqHandler.setParameter("out_refund_no", order.OrderId + "C");
            reqHandler.setParameter("total_fee", (order.Amount * 100).ToString());
            reqHandler.setParameter("refund_fee", (order.Amount * 100).ToString());
            reqHandler.setParameter("op_user_id", bargainor_id);
            reqHandler.setParameter("op_user_passwd", ChargeConfig.GetConfigKey(ThisCompanyType, ChargeConfig.DataType.PayPass));
            string requestUrl = reqHandler.getRequestURL();
            //证书和证书密码
            httpClient.setCertInfo(ChargeConfig.GetConfigKey(ThisCompanyType, ChargeConfig.DataType.CertFile), bargainor_id);
            //设置请求内容
            httpClient.setReqContent(requestUrl);
            //设置超时
            httpClient.setTimeOut(10);

            string rescontent = "";
            //后台调用
            if (!httpClient.call())
            {
                message = "接口调用失败";
                return(false);
            }
            //获取结果
            rescontent = httpClient.getResContent();

            resHandler.setKey(key);
            //设置结果参数
            resHandler.setContent(rescontent);
            message = resHandler.getParameter("retmsg");
            //Log("退款返回结果为:" + rescontent);
            //判断签名及结果
            if (!resHandler.isTenpaySign())
            {
                message = "返回签名验证错误";
                return(false);
            }
            if (resHandler.getParameter("retcode") != "0")
            {
                return(false);
            }

            //商户订单号
            string out_trade_no = resHandler.getParameter("out_trade_no");
            //财富通订单号
            string transaction_id = resHandler.getParameter("transaction_id");

            // 退款状态:
            //4,10:退款成功。
            //3,5,6:退款失败。
            //8,9,11:退款处理中。
            //1,2:未确定,需要商户原退款单号重新发起。
            //7:转入代发,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,资金回流到商户的现金帐号,需要商户人工干预,通过线下或者财富通转账的方式进行退款

            string refund_status = resHandler.getParameter("refund_status");

            if (refund_status == "4" || refund_status == "10")
            {
                string recv_user_id    = resHandler.getParameter("recv_user_id");
                string reccv_user_name = resHandler.getParameter("reccv_user_name");
                //Log("退款接收人信息为:" + recv_user_id + "  " + reccv_user_name);
                BaseRefundOrder(order);
                return(true);
            }
            if (refund_status == "8" || refund_status == "9" || refund_status == "11")
            {
                //todo 自动重复查询
                message = "退款处理中";
                return(true);
            }
            return(false);

            #endregion
        }
Beispiel #17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //商户号
        string partner = "1220201501";


        //密钥
        string key = "19ace89a7acd6e14ac3c66b2852f14d6";

        //创建请求对象
        RequestHandler reqHandler = new RequestHandler(Context);

        //通信对象
        TenpayHttpClient httpClient = new TenpayHttpClient();

        //应答对象
        ClientResponseHandler resHandler = new ClientResponseHandler();

        int otid = Convert.ToInt32(Request["orderid"].ToString());

        Cms.BLL.C_order   otBll       = new Cms.BLL.C_order();
        Cms.Model.C_order orderEntity = otBll.GetModel(otid);

        //-----------------------------
        //设置请求参数
        //-----------------------------
        reqHandler.init();
        reqHandler.setKey(key);
        reqHandler.setGateUrl("https://mch.tenpay.com/refundapi/gateway/refund.xml");

        reqHandler.setParameter("partner", partner);
        //out_trade_no和transaction_id至少一个必填,同时存在时transaction_id优先
        //reqHandler.setParameter("out_trade_no", "1458268681");
        reqHandler.setParameter("transaction_id", orderEntity.trade_no);
        reqHandler.setParameter("out_refund_no", orderEntity.order_num);
        reqHandler.setParameter("total_fee", ((int)(orderEntity.price_sum * 100)).ToString());//((int)(orderEntity.price_sum * 100)).ToString()
        reqHandler.setParameter("refund_fee", ((int)(orderEntity.price_sum * 100)).ToString());
        //reqHandler.setParameter("refund_fee", "100");
        reqHandler.setParameter("op_user_id", "1220201501");
        reqHandler.setParameter("op_user_passwd", MD5Util.GetMD5("dbezhifu1866", "GBK"));
        reqHandler.setParameter("service_version", "1.1");

        string requestUrl = reqHandler.getRequestURL();

        httpClient.setCertInfo("d:\\wwwroot\\anpurui\\wwwroot\\1220201501_20150203112358.pfx", "1220201501");
        //设置请求内容
        httpClient.setReqContent(requestUrl);
        //设置超时
        httpClient.setTimeOut(10);

        string rescontent = "";


        //后台调用
        if (httpClient.call())
        {
            //获取结果
            rescontent = httpClient.getResContent();



            resHandler.setKey(key);
            //设置结果参数
            resHandler.setContent(rescontent);

            //判断签名及结果
            if (resHandler.isTenpaySign() && resHandler.getParameter("retcode") == "0")
            {
                //商户订单号
                string out_trade_no = resHandler.getParameter("out_trade_no");
                //财付通订单号
                string transaction_id = resHandler.getParameter("transaction_id");

                DataTable dt = otBll.GetList("trade_no='" + transaction_id + "'").Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    int id = Convert.ToInt32(dt.Rows[0]["id"]);
                    Cms.Model.C_order orderModel = otBll.GetModel(id);
                    orderModel.is_refund = 3;
                    if (otBll.Update(orderModel))
                    {
                        JscriptMsg("退款成功!", "/shop/myOrder.aspx", "Success");
                    }
                }

                //业务处理
                //Response.Write("退款成功!" + out_trade_no + transaction_id);
            }
            else
            {
                //错误时,返回结果未签名。
                //如包格式错误或未确认结果的,请使用原来订单号重新发起,确认结果,避免多次操作
                //Response.Write("业务错误信息或签名错误:" + resHandler.getParameter("retcode") + "," + resHandler.getParameter("retmsg") + "<br>");
                JscriptMsg("退款失败!", "/shop/myOrder.aspx", "Error");
            }
        }
        else
        {
            //后台调用通信失败
            //Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
            JscriptMsg("退款失败!", "/shop/myOrder.aspx", "Error");
            //有可能因为网络原因,请求已经处理,但未收到应答。
        }


        //获取debug信息,建议把请求、应答内容、debug信息,通信返回码写入日志,方便定位问题

        //Response.Write("http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + "<br>");
        //Response.Write("req url:" + requestUrl + "<br/>");
        //Response.Write("req debug:" + reqHandler.getDebugInfo() + "<br/>");
        //Response.Write("res content:" + Server.HtmlEncode(rescontent) + "<br/>");
        //Response.Write("res debug:" + Server.HtmlEncode(resHandler.getDebugInfo()) + "<br/>");
    }
Beispiel #18
0
        public void Notify(HttpContext Context)
        {
            //商户号
            string partner = SuppAccount;
            //密钥
            string key = SuppKey;
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/verifynotifyid.xml");
                queryReq.setParameter("partner", partner);
                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(key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //取结果参数做业务处理
                        string out_trade_no = queryRes.getParameter("out_trade_no");
                        //财付通订单号
                        string transaction_id = queryRes.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = queryRes.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = queryRes.getParameter("discount");
                        //支付结果
                        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))
                            {
                                string opstate = "-1";
                                int    status  = 4;

                                //即时到账
                                if ("0".Equals(trade_state))
                                {
                                    status  = 2;
                                    opstate = "0";

                                    //------------------------------
                                    //即时到账处理业务开始
                                    //------------------------------

                                    //处理数据库逻辑
                                    //注意交易单不要重复处理
                                    //注意判断返回金额

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

                                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                    //Context.Response.Write("success");
                                }
                                else
                                {
                                    //Context.Response.Write("即时到账支付失败");
                                }

                                decimal tranAmt = decimal.Parse(total_fee) / 100M;

                                OrderBankUtils.SuppNotify(SuppId
                                                          , out_trade_no
                                                          , transaction_id
                                                          , status
                                                          , opstate
                                                          , string.Empty
                                                          , tranAmt, tranAmt
                                                          , Succflag
                                                          , Failflag);

                                //viviapi.BLL.OrderBank bll = new viviapi.BLL.OrderBank();
                                //bll.DoBankComplete(suppId, out_trade_no, transaction_id, status, opstate, string.Empty, decimal.Parse(total_fee) / 100M, 0M, true, false);
                            }
                            else if ("2".Equals(trade_mode))
                            { //中介担保
                              //------------------------------
                              //中介担保处理业务开始
                              //------------------------------
                              //处理数据库逻辑
                              //注意交易单不要重复处理
                              //注意判断返回金额

                                int iStatus = Convert.ToInt32(trade_state);
                                switch (iStatus)
                                {
                                case 0:                 //付款成功

                                    break;

                                case 1:                 //交易创建

                                    break;

                                case 2:                 //收获地址填写完毕

                                    break;

                                case 4:                 //卖家发货成功

                                    break;

                                case 5:                 //买家收货确认,交易成功

                                    break;

                                case 6:                 //交易关闭,未完成超时关闭

                                    break;

                                case 7:                 //修改交易价格成功

                                    break;

                                case 8:                 //买家发起退款

                                    break;

                                case 9:                 //退款成功

                                    break;

                                case 10:        //退款关闭

                                    break;
                                }


                                //------------------------------
                                //中介担保处理业务开始
                                //------------------------------


                                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                //Response.Write("success");
                            }
                        }
                        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 #19
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //商户号
        string partner = "1900000109";

        //密钥
        string key = "8934e7d15453e97507ef794cf7b0519d";


        //创建ResponseHandler实例
        ResponseHandler resHandler = new ResponseHandler(Context);

        resHandler.setKey(key);

        //判断签名
        if (resHandler.isTenpaySign())
        {
            ///通知id
            string notify_id = resHandler.getParameter("notify_id");

            //通过通知ID查询,确保通知来至财付通
            //创建查询请求
            RequestHandler queryReq = new RequestHandler(Context);
            queryReq.init();
            queryReq.setKey(key);
            queryReq.setGateUrl("https://gw.tenpay.com/gateway/verifynotifyid.xml");
            queryReq.setParameter("partner", partner);
            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(key);

                //判断签名及结果
                //只有签名正确,retcode为0,trade_state为0才是支付成功
                if (queryRes.isTenpaySign() && queryRes.getParameter("retcode") == "0" && queryRes.getParameter("trade_state") == "0" && queryRes.getParameter("trade_mode") == "1")
                {
                    //取结果参数做业务处理
                    string out_trade_no = queryRes.getParameter("out_trade_no");
                    //财付通订单号
                    string transaction_id = queryRes.getParameter("transaction_id");
                    //金额,以分为单位
                    string total_fee = queryRes.getParameter("total_fee");
                    //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                    string discount = queryRes.getParameter("discount");

                    //------------------------------
                    //处理业务开始
                    //------------------------------

                    //处理数据库逻辑
                    //注意交易单不要重复处理
                    //注意判断返回金额

                    //------------------------------
                    //处理业务完毕
                    //------------------------------
                    //通知财付通已经处理成功,无需重新通知
                    Response.Write("success");
                }
                else
                {
                    //错误时,返回结果可能没有签名,写日志trade_state、retcode、retmsg看失败详情。
                    //通知财付通处理失败,需要重新通知
                    Response.Write("fail");
                }

                //获取查询的debug信息,建议把请求、应答内容、debug信息,通信返回码写入日志,方便定位问题

                /*
                 * Response.Write("http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + "<br>");
                 * Response.Write("query req url:" + queryReq.getRequestURL() + "<br/>");
                 * Response.Write("query req debug:" + queryReq.getDebugInfo() + "<br/>");
                 * Response.Write("query res content:" + Server.HtmlEncode(httpClient.getResContent()) + "<br/>");
                 * Response.Write("query res debug:" + Server.HtmlEncode(queryRes.getDebugInfo()) + "<br/>");
                 */
            }
            else
            {
                //通知财付通处理失败,需要重新通知
                Response.Write("fail");
                //写错误日志
                Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
            }

            //获取debug信息,建议把debug信息写入日志,方便定位问题

            /*
             * string debuginfo = resHandler.getDebugInfo();
             * Response.Write("<br/>debuginfo:" + debuginfo + "<br/>");
             */
        }
    }
Beispiel #20
0
        public string Notify <T>(PayMointor <T> proc) where T : class
        {
            //商户号
            string partner = TenpayUtil.bargainor_id;
            //密钥
            string key = TenpayUtil.tenpay_key;


            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(System.Web.HttpContext.Current);

            resHandler.setKey(key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");


                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(System.Web.HttpContext.Current);
                queryReq.init();
                queryReq.setKey(key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/verifynotifyid.xml");
                queryReq.setParameter("partner", partner);
                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(key);

                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign() && queryRes.getParameter("retcode") == "0" && queryRes.getParameter("trade_state") == "0" && queryRes.getParameter("trade_mode") == "1")
                    {
                        //取结果参数做业务处理
                        string out_trade_no = queryRes.getParameter("out_trade_no");
                        //财付通订单号
                        string transaction_id = queryRes.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = queryRes.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = queryRes.getParameter("discount");
                        //支付结果
                        string trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即时到帐 2中介担保
                        string trade_mode = resHandler.getParameter("trade_mode");

                        proc.Init(out_trade_no);


                        //判断签名及结果
                        if (queryRes.isTenpaySign() && "0".Equals(queryRes.getParameter("retcode")))
                        {
                            // Response.Write("id验证成功");

                            if ("1".Equals(trade_mode))
                            {       //即时到账
                                if ("0".Equals(trade_state))
                                {
                                    proc.PaidSuccess();

                                    return("Success");
                                }
                                else
                                {
                                    proc.PaidFail();
                                    //SetLogMessage("即时到账支付失败");
                                    return("即时到账支付失败");
                                }
                            }
                            else if ("2".Equals(trade_mode))
                            { //中介担保
                              //------------------------------
                              //中介担保处理业务开始
                              //------------------------------
                              //处理数据库逻辑
                              //注意交易单不要重复处理
                              //注意判断返回金额

                                int iStatus = 0;
                                switch (iStatus)
                                {
                                case 0:                 //付款成功

                                    break;

                                case 1:                 //交易创建

                                    break;

                                case 2:                 //收获地址填写完毕

                                    break;

                                case 4:                 //卖家发货成功

                                    break;

                                case 5:                 //买家收货确认,交易成功

                                    break;

                                case 6:                 //交易关闭,未完成超时关闭

                                    break;

                                case 7:                 //修改交易价格成功

                                    break;

                                case 8:                 //买家发起退款

                                    break;

                                case 9:                 //退款成功

                                    break;

                                case 10:        //退款关闭

                                    break;
                                }


                                //------------------------------
                                //中介担保处理业务开始
                                //------------------------------


                                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知

                                proc.PaidSuccess();
                                return("Success");
                            }
                        }
                        else
                        {
                            //错误时,返回结果可能没有签名,写日志trade_state、retcode、retmsg看失败详情。
                            //通知财付通处理失败,需要重新通知\



                            // SetLogMessage("查询验证签名失败或id验证失败\r\nretcode:" + queryRes.getParameter("retcode"));

                            proc.PaidFail();
                            return("查询验证签名失败或id验证失败retcode:" + queryRes.getParameter("retcode"));;
                        }
                    }
                    else
                    {
                        //通知财付通处理失败,需要重新通知

                        //SetLogMessage("后台调用通信失败\r\ncall err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");

                        proc.PaidFail();

                        return("后台调用通信失败call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
                    }
                }
                else
                {
                    proc.PaidFail();
                    return("通知签名验证失败");
                }
            }
            return("");
        }
Beispiel #21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int             site_payment_id = 0;                                                 //站点支付方式ID
            ResponseHandler resHandler      = new ResponseHandler(Context);                      //创建ResponseHandler实例
            string          order_no        = resHandler.getParameter("out_trade_no").ToUpper(); //商户订单号
            string          trade_no        = resHandler.getParameter("transaction_id");         //财付通订单号
            string          total_fee       = resHandler.getParameter("total_fee");              //金额,以分为单位
            string          discount        = resHandler.getParameter("discount");               //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
            string          trade_state     = resHandler.getParameter("trade_state");            //支付结果

            if (order_no.StartsWith("R"))                                                        //充值订单
            {
                site_payment_id = new BLL.user_recharge().GetPaymentId(order_no);
            }
            else if (order_no.StartsWith("B")) //商品订单
            {
                site_payment_id = new BLL.orders().GetPaymentId(order_no);
            }
            if (site_payment_id == 0)
            {
                Response.Write("该订单号不存在");
                return;
            }

            //找到站点支付方式ID开始验证
            TenpayUtil config = new TenpayUtil(site_payment_id);

            resHandler.setKey(config.key);
            //判断签名
            if (resHandler.isTenpaySign())
            {
                string         notify_id = resHandler.getParameter("notify_id"); //通知id
                RequestHandler queryReq  = new RequestHandler(Context);          //通过通知ID查询,确保通知来至财付通
                queryReq.init();
                queryReq.setKey(config.key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", config.partner);
                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(config.key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //判断签名及结果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            #region 即时到账处理方法====================================
                            if ("0".Equals(trade_state))
                            {
                                if (order_no.StartsWith("R")) //充值订单
                                {
                                    BLL.user_recharge   bll   = new BLL.user_recharge();
                                    Model.user_recharge model = bll.GetModel(order_no);
                                    if (model == null)
                                    {
                                        Response.Write("该订单号不存在");
                                        return;
                                    }
                                    if (model.status == 1) //已成功
                                    {
                                        Response.Write("success");
                                        return;
                                    }
                                    if (model.amount != (decimal.Parse(total_fee) / 100))
                                    {
                                        Response.Write("订单金额和支付金额不相符");
                                        return;
                                    }
                                    bool result = bll.Confirm(order_no);
                                    if (!result)
                                    {
                                        Response.Write("修改订单状态失败");
                                        return;
                                    }
                                }
                                else if (order_no.StartsWith("B")) //商品订单
                                {
                                    BLL.orders   bll   = new BLL.orders();
                                    Model.orders model = bll.GetModel(order_no);
                                    if (model == null)
                                    {
                                        Response.Write("该订单号不存在");
                                        return;
                                    }
                                    if (model.payment_status == 2) //已付款
                                    {
                                        Response.Write("success");
                                        return;
                                    }
                                    if (model.order_amount != (decimal.Parse(total_fee) / 100))
                                    {
                                        Response.Write("订单金额和支付金额不相符");
                                        return;
                                    }
                                    bool result = bll.UpdateField(order_no, "trade_no='" + trade_no + "',status=2,payment_status=2,payment_time='" + DateTime.Now + "'");
                                    if (!result)
                                    {
                                        Response.Write("修改订单状态失败");
                                        return;
                                    }
                                }
                                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                Response.Write("success");
                            }
                            else
                            {
                                Response.Write("即时到账支付失败");
                            }
                            #endregion
                        }
                        else
                        {
                            Response.Write("查询验证签名失败或id验证失败");
                        }
                    }
                    else
                    {
                        Response.Write("通知ID查询签名验证失败");
                    }
                }
                else
                {
                    Response.Write("后台调用通信失败");
                }
            }
            else
            {
                Response.Write("签名验证失败");
            }
            Response.End();
        }