Exemple #1
0
    /// <summary>
    /// 判断是否是线下支付类型
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public string Pretype(string type, string paymentid)
    {
        string str = string.Empty;

        Hi.Model.PAY_Payment payment = new Hi.BLL.PAY_Payment().GetModel(Convert.ToInt32(paymentid));
        //add by ggh 状态(1,确认;2,作废)
        int ostate = hidOstate.Value.ToInt(0);

        if (type == "线下支付" && ostate != 6 && ostate != 7)
        {
            if (!payment.vdef9.Equals("1"))
            {
                if (new Hi.BLL.DIS_Order().GetModel(Convert.ToInt32(payment.OrderID)).TotalAmount != new Hi.BLL.DIS_Order().GetModel(Convert.ToInt32(payment.OrderID)).PayedAmount)
                {
                    str += string.Format("<a href='#' onclick='TovoidPay({0},{1})'> 确认 </a>", paymentid, 1);
                }
            }
        }
        if (type == "线下支付" && ostate != 6 && ostate != 7)
        {
            if (payment.vdef9.Equals("1"))
            {
                //     if (new Hi.BLL.DIS_Order().GetModel(Convert.ToInt32(payment.OrderID)).TotalAmount != new Hi.BLL.DIS_Order().GetModel(Convert.ToInt32(payment.OrderID)).PayedAmount)
                str += string.Format("<a href='#' onclick='TovoidPay({0},{1})'> 作废 </a>", paymentid, 2);
            }
        }
        return(str);
    }
Exemple #2
0
 /// <summary>
 /// 绑定附件信息
 /// </summary>
 public void DataFileBind()
 {
     Hi.Model.PAY_Payment Pre = new Hi.BLL.PAY_Payment().GetModel(Convert.ToString(ViewState["paymentID"]).ToInt(0));
     if (Pre != null)
     {
         if (!string.IsNullOrEmpty(Pre.attach))
         {
             string[] files = Pre.attach.Split(new string[] { "&&" }, StringSplitOptions.RemoveEmptyEntries);
             foreach (string file in files)
             {
                 if (!string.IsNullOrEmpty(file))
                 {
                     LinkButton linkFile = new LinkButton();
                     linkFile.Click += new EventHandler(Download_Click);
                     if (file.LastIndexOf("_") != -1)
                     {
                         string text = file.Substring(0, file.LastIndexOf("_")) + Path.GetExtension(file);
                         if (text.Length < 6)
                         {
                             linkFile.Text = text;
                         }
                         else
                         {
                             linkFile.Text = text.Substring(0, 6) + "...";
                         }
                         linkFile.Attributes.Add("title", text);
                     }
                     else
                     {
                         string text = file.Substring(0, file.LastIndexOf("-")) + Path.GetExtension(file);
                         if (text.Length < 15)
                         {
                             linkFile.Text = text;
                         }
                         else
                         {
                             linkFile.Text = text.Substring(0, 15) + "...";
                         }
                         linkFile.Attributes.Add("title", text);
                     }
                     linkFile.Style.Add("margin-right", "8px");
                     linkFile.Style.Add("text-decoration", "underline");
                     linkFile.Attributes.Add("fileName", file);
                     HtmlGenericControl div = new HtmlGenericControl("div");
                     div.Controls.Add(linkFile);
                     //HtmlImage img = new HtmlImage();
                     //img.Src = "../../images/icon_del.png";
                     //img.Attributes.Add("title", "删除附件");
                     //img.Attributes.Add("onclick", "AnnexDel(this,'Dis'," + KeyID + ",'" + file + "')");
                     //div.Controls.Add(img);
                     DFile.Controls.Add(div);
                 }
             }
         }
     }
 }
Exemple #3
0
    /// <summary>
    /// 返回成功信息
    /// </summary>
    /// <param name="type">1,订单支付  2 ,账单支付  3,充值</param>
    /// <returns></returns>
    public string GetMessage(int type)
    {
        switch (type)
        {
        case 1:
            str        = "付款成功,已支付";
            url        = " 您可以<a href='../newOrder/orderdetail.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey) + "'>查看订单详情</a><a href='../OrderList.aspx'>返回订单管理</a>";
            lastmesage = "<a href='../newOrder/orderdetail.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey) + "' id='lblmessage'>5</a>";

            break;

        case 2:
            str        = "付款成功,已支付";
            url        = " 您可以<a href='../OrderZDInfo.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey) + "'>查看账单详情</a><a href='orderZDList.aspx'>返回我的账单</a>";
            lastmesage = " <a href='../OrderZDInfo.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey) + "' id='lblmessage'>5</a>";
            break;

        case 3:
            str = "交易成功,已支付";
            Hi.Model.PAY_Payment        payM     = new Hi.Model.PAY_Payment();
            List <Hi.Model.PAY_Payment> payMList = new Hi.BLL.PAY_Payment().GetList("", "orderid=" + KeyID, "");
            if (payMList.Count > 0)
            {
                payM = payMList[0];
            }
            this.PayedAmount.InnerHtml = payM.PayPrice.ToString("0.00");


            url = "可以点击回到<a href='PrePayList.aspx'>企业钱包查询</a>";

            lastmesage = "<a href='PrePayList.aspx' id='lblmessage'>5</a>";


            break;

        default:
            str = "付款失败!";
            url = "";
            break;
        }
        return(str);
    }
Exemple #4
0
    public void Bind()
    {
        decimal price = 0;

        Hi.Model.DIS_Order     orderM = new Hi.BLL.DIS_Order().GetModel(KeyID);
        Hi.Model.PAY_Payment   payM   = new Hi.BLL.PAY_Payment().GetModel(Pid);
        Hi.Model.PAY_Financing FinM   = new Hi.BLL.PAY_Financing().GetModel(Fid);
        if (payM != null)
        {
            price += payM.PayPrice;
        }
        Hi.Model.PAY_PrePayment prepayM = new Hi.BLL.PAY_PrePayment().GetModel(PPid);
        if (prepayM != null)
        {
            price += prepayM.price * -1;
        }
        if (FinM != null)
        {
            price += FinM.AclAmt;
        }
        this.PayedAmount.InnerHtml = price.ToString("0.00");
    }
Exemple #5
0
    public void Test(string Type)
    {
        ////本地日志记录
        LogManager.LogFielPrefix = "Order_time";
        LogManager.LogPath       = "D:/订单结算日志Order_log/";

        LogManager.WriteLog(LogFile.Trace.ToString(), DateTime.Now.ToString() + "-订单结算程序启动>>>>>>>>>>>...\r\n");

        string strMsg     = string.Empty;
        string pre_strMsg = string.Empty;
        string fw_strMsg  = string.Empty;
        string head       = "各位,您好!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + DateTime.Now.Year + "年" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日" + " 结算情况如下,请查看:";;

        string topMsg      = string.Empty;
        string pre_topMsg  = string.Empty;
        string fw_topMsg   = string.Empty;
        string downMsg     = string.Empty;
        string pre_downMsg = string.Empty;
        string fw_downMsg  = string.Empty;

        int ord_errornum = 0;         //记录订单支付错误的记录
        int pre_errornum = 0;         //记录企业钱包错误的记录
        int fw_errornum  = 0;         //记录服务错误的记录

        int    db_num = 0;            //担保支付记录
        string db_meg = string.Empty; //担保支付信息


        //订单结算方法
        if (Type == "Order")
        {
            string LocalSqlServer = SqlHelper.LocalSqlServer;

            int     compID        = 0;
            int     disID         = 0;
            long    price         = 0;                                                                      //金额
            int     ordID         = 0;                                                                      //订单Id
            string  ReceiptNo     = string.Empty;                                                           //订单号
            string  guid          = string.Empty;                                                           //流水号
            string  remark        = string.Empty;                                                           //订单备注
            int     paymentID     = 0;                                                                      //支付表ID
            int     Channel       = 0;                                                                      //支付渠道(1,快捷支付,2,银联支付 ,3,网银支付,4,B2B网银支付)
            decimal payment_zfsxf = 0;                                                                      //支付表计算的手续费
            int     Paymen_Type   = 0;                                                                      //支付类型
            int     OState        = 0;                                                                      //判断是否已确认到货
            int     jsxf_no       = 0;                                                                      //判断手续费是否结算成功
            string  hc_flag       = string.Empty;                                                           //结算回冲标准

            decimal Old_price = 0;                                                                          //原支付金额
            //-----银行信息
            string orgcode              = ConfigurationManager.AppSettings["PayOrgCode"].ToString().Trim(); // string.Empty;//机构代码
            int    accountType          = 0;                                                                //帐号类型
            string paymentaccountname   = string.Empty;                                                     //账户名称(支付平台账户 当 AccountType=20 时,该项必填)
            string paymentaccountnumber = string.Empty;                                                     //账户号码(支付平台账户 当 AccountType=20 时,该项必填)
            string bankaccount          = string.Empty;                                                     //收款方在银行开立的账户
            string bankId        = string.Empty;                                                            //银行ID
            string accountname   = string.Empty;                                                            //账户名称
            string accountnumber = string.Empty;                                                            //账户号码
            string branchname    = string.Empty;                                                            //开会行地址
            string province      = string.Empty;                                                            //开会所在省
            string city          = string.Empty;                                                            //开会所在市

            //结算接口日志表
            Hi.Model.PAY_PayLog paylogmodel = new Hi.Model.PAY_PayLog();
            Hi.BLL.PAY_PayLog   paylogbll   = new Hi.BLL.PAY_PayLog();
            int paylogID = 0;//接口日志返回ID



            #region 订单结算
            string sxfsq = "-1";

            DataTable dt_order = new Hi.BLL.PAY_PrePayment().GetdataTable(1, "", 1);
            if (dt_order.Rows.Count > 0)
            {
                foreach (DataRow dr in dt_order.Rows)
                {
                    compID        = 0;
                    disID         = 0;
                    price         = 0;                   //金额
                    ordID         = 0;                   //订单Id
                    ReceiptNo     = string.Empty;        //订单号
                    guid          = string.Empty;        //流水号
                    remark        = string.Empty;        //订单备注
                    paymentID     = 0;                   //支付表ID
                    Channel       = 0;                   //支付渠道(1,快捷支付,2,银联支付 ,3,网银支付,4,B2B网银支付)
                    payment_zfsxf = 0;                   //支付表计算的手续费
                    Paymen_Type   = 0;                   //支付类型
                    OState        = 0;                   //判断是否已确认到货
                    jsxf_no       = 0;                   //判断手续费是否结算成功
                    hc_flag       = string.Empty;        //结算回冲标准
                    Old_price     = 0;                   //原支付金额
                    //-----银行信息
                    accountType          = 0;            //帐号类型
                    paymentaccountname   = string.Empty; //账户名称(支付平台账户 当 AccountType=20 时,该项必填)
                    paymentaccountnumber = string.Empty; //账户号码(支付平台账户 当 AccountType=20 时,该项必填)
                    bankaccount          = string.Empty; //收款方在银行开立的账户
                    bankId        = string.Empty;        //银行ID
                    accountname   = string.Empty;        //账户名称
                    accountnumber = string.Empty;        //账户号码
                    branchname    = string.Empty;        //开会行地址
                    province      = string.Empty;        //开会所在省
                    city          = string.Empty;        //开会所在市


                    ////本地日志记录
                    LogManager.LogFielPrefix = "Order_time";
                    LogManager.LogPath       = "D:/订单结算日志Order_log/";
                    LogManager.WriteLog(LogFile.Trace.ToString(), DateTime.Now.ToString() + "-订单结算服务启动...");

                    try
                    {
                        compID = Convert.ToInt32(dr["CompID"]);
                        disID  = Convert.ToInt32(dr["DisID"]);
                        //原支付金额
                        Old_price = Convert.ToDecimal(dr["PayPrice"]) - Convert.ToDecimal(dr["vdef5"] + "" == "" ? "0" : dr["vdef5"]);


                        Channel       = Convert.ToInt32(dr["Channel"] + "" == "" ? "-1" : dr["Channel"]);
                        payment_zfsxf = Convert.ToDecimal(dr["vdef5"]);
                        jsxf_no       = Convert.ToInt32(dr["jsxf_no"]);
                        hc_flag       = dr["vdef6"] + "";

                        #region     计算支付手续费 start

                        decimal sxf    = 0;
                        long    js_sxf = 0;
                        //查询该企业的设置
                        List <Hi.Model.Pay_PaymentSettings> Sysl = new Hi.BLL.Pay_PaymentSettings().GetList("", " CompID=" + compID, "");
                        if (Sysl.Count > 0)
                        {
                            //手续费收取
                            sxfsq = Convert.ToString(Sysl[0].pay_sxfsq);

                            //支付方式--线上or线下
                            string zffs = Convert.ToString(Sysl[0].pay_zffs);

                            //免手续费支付次数
                            int mfcs = Convert.ToInt32(Sysl[0].Pay_mfcs);

                            //快捷支付比例
                            decimal kjzfbl    = Convert.ToDecimal(Sysl[0].pay_kjzfbl) / 1000;
                            decimal kjzfstart = Convert.ToDecimal(Sysl[0].pay_kjzfstart);
                            decimal kjzfend   = Convert.ToDecimal(Sysl[0].pay_kjzfend);

                            //银联支付比例
                            decimal ylzfbl    = Convert.ToDecimal(Sysl[0].pay_ylzfbl) / 1000;
                            decimal ylzfstart = Convert.ToDecimal(Sysl[0].pay_ylzfstart);
                            decimal ylzfend   = Convert.ToDecimal(Sysl[0].pay_ylzfend);

                            //B2c网银支付比例

                            decimal b2cwyzfbl    = Convert.ToDecimal(Sysl[0].pay_b2cwyzfbl) / 1000;
                            decimal b2cwyzfstart = Convert.ToDecimal(Sysl[0].vdef1);

                            //B2b网银支付比例

                            decimal b2bwyzfbl = Convert.ToDecimal(Sysl[0].pay_b2bwyzf);

                            //手续费收取方
                            if (sxfsq == "0")
                            {
                                sxf = 0;
                            }
                            else
                            {
                                //手续费 (没有免支付次数时,才计算手续费)
                                if (mfcs <= 0)
                                {
                                    switch (Channel)
                                    {
                                    case 1:    //快捷支付手续费
                                        sxf = Old_price * kjzfbl;
                                        // if (sxf <= kjzfstart)
                                        //     sxf = kjzfstart;
                                        // else if (sxf >= kjzfend)
                                        //     sxf = kjzfend;
                                        break;

                                    case 2:    //银联支付手续费
                                        sxf = Old_price * ylzfbl;
                                        //if (sxf <= ylzfstart)
                                        //    sxf = ylzfstart;
                                        //else if (sxf >= ylzfend)
                                        //   sxf = ylzfend;
                                        break;

                                    case 3:    //B2C网银支付手续费
                                        sxf = Old_price * b2cwyzfbl;
                                        //if (sxf <= b2cwyzfstart)
                                        //   sxf = b2cwyzfstart;
                                        break;

                                    case 8:    //信用卡支付手续费
                                        sxf = Old_price * b2cwyzfbl;
                                        break;

                                    case 4:    //B2B网银支付手续费
                                        sxf = b2bwyzfbl;
                                        break;
                                    }
                                }

                                //计算手续费
                                sxf = Math.Round(sxf, 2) * 100;//转化成分
                            }
                        }

                        #endregion  计算支付手续费 end

                        price = Convert.ToInt64(Old_price * 100);

                        bool sxf_fal = false;//判断结算时的手续费,是否和支付时手续费一致

                        #region  根据手续费收取方,判断清算金额 start

                        if (sxfsq == "1") // 1,代理商
                        {
                            if (sxf == payment_zfsxf * 100)
                            {
                                //price = price;//最终清算时的订单金额
                                js_sxf  = Convert.ToInt64(sxf);//最终清算时的手续费
                                sxf_fal = true;
                            }
                        }
                        else if (sxfsq == "2")             //2,企业
                        {
                            js_sxf = Convert.ToInt64(sxf); //最终清算时的手续费
                            // price = price;//最终清算时的订单金额
                            sxf_fal = true;
                        }
                        else
                        {
                            sxf_fal = true;
                        }

                        #endregion 根据手续费收取方,判断清算金额 end

                        if (sxf_fal)
                        {
                            ReceiptNo = Convert.ToString(dr["ReceiptNo"]);
                            //回冲操作处理重新生成Guid,paylog表通过createuserid字段和payment表关联
                            if ("1".Equals(hc_flag))
                            {
                                guid = Common.Number_repeat(Guid.NewGuid().ToString().Replace("-", ""));
                            }
                            else
                            {
                                guid = Convert.ToString(dr["GUID"]);
                            }

                            ordID     = Convert.ToInt32(dr["ID"]);
                            paymentID = Convert.ToInt32(dr["paymentID"]);

                            Paymen_Type = Convert.ToInt32(dr["Type"]);    //判断是否是担保支付
                            OState      = Convert.ToInt32(dr["OState"]);  //判断订单是否已确认到货
                            string disname = new Hi.BLL.BD_Distributor().GetModel(Convert.ToInt32(Common.GetOrderValue(ordID, "DisID"))).DisName;
                            remark = "订单结算-" + disname + "-" + ReceiptNo; // Convert.ToString(dr["Remark"]);



                            //支付类型为正常支付,或者支付类型是担保支付,但是已确认到货的订单,进行结算操作
                            if (Paymen_Type == 0 || (Paymen_Type == 1 && OState == 5))
                            {
                                DataTable dt_bank_comp = new Hi.BLL.PAY_PrePayment().GetdataTable(3, "  and Isno=1 and PAY_PaymentBank.CompID=" + compID, 0);//结算接口,银行信息--已企业为主,

                                if (dt_bank_comp.Rows.Count > 0)
                                {
                                    foreach (DataRow drcomp in dt_bank_comp.Rows)
                                    {
                                        accountType          = Convert.ToInt32(drcomp["type"]);     //帐号类型
                                        paymentaccountname   = Convert.ToString(drcomp["payName"]); //账户名称
                                        paymentaccountnumber = Convert.ToString(drcomp["PayCode"]); //账户号码
                                        //收款方在银行开立的账户
                                        bankId        = Convert.ToString(drcomp["BankID"]);;        //银行ID
                                        accountname   = Convert.ToString(drcomp["AccountName"]);    //账户名称
                                        accountnumber = Convert.ToString(drcomp["bankcode"]);       //账户号码
                                        branchname    = Convert.ToString(drcomp["bankAddress"]);    //开会行地址
                                        province      = Convert.ToString(drcomp["bankprivate"]);    //开会所在省
                                        city          = Convert.ToString(drcomp["bankcity"]);       //开会所在市
                                    }
                                }



                                //判断参数收款银行是否维护
                                if (accountType == 0)
                                {
                                    ord_errornum++;
                                    strMsg += "<br>订单结算无法进行收款,请维护收款帐号信息:" + DateTime.Now.ToString() + ";" + "错误流水Guid:" + guid + ";" + "企业ID:&nbsp;(" + new Hi.BLL.BD_Company().GetModel(compID).CompName + ")";
                                }
                                //个人账户、企业账户
                                else if ((accountType == 11 || accountType == 12) && bankId != "" && accountname != "" && accountnumber != "")
                                {
                                    //先插入日志表,
                                    paylogmodel.OrderId     = ordID;
                                    paylogmodel.Ordercode   = ReceiptNo;
                                    paylogmodel.number      = guid;
                                    paylogmodel.CompID      = compID;
                                    paylogmodel.OrgCode     = orgcode;
                                    paylogmodel.MarkName    = paymentaccountname;
                                    paylogmodel.MarkNumber  = paymentaccountnumber;
                                    paylogmodel.AccountName = accountname;
                                    paylogmodel.bankcode    = accountnumber;
                                    paylogmodel.bankAddress = branchname;
                                    paylogmodel.bankPrivate = province;
                                    paylogmodel.bankCity    = city;
                                    paylogmodel.Price       = price;
                                    paylogmodel.Remark      = remark;
                                    paylogmodel.CreateDate  = DateTime.Now;
                                    paylogmodel.CreateUser  = paymentID;//关联支付表
                                    paylogID = paylogbll.Add(paylogmodel);


                                    if (paylogID > 0)//日志插入成功
                                    {
                                        //调用中金接口,做结算处理-------------------------------
                                        try
                                        {
                                            string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
                                            PaymentEnvironment.Initialize(configPath);

                                            // 2.创建交易请求对象
                                            Tx1341Request tx1341Request = new Tx1341Request();
                                            tx1341Request.setInstitutionID(orgcode);
                                            tx1341Request.setSerialNumber(guid);
                                            tx1341Request.setOrderNo(ReceiptNo);
                                            tx1341Request.setAmount(price);
                                            tx1341Request.setRemark(remark);
                                            tx1341Request.setAccountType(accountType);
                                            tx1341Request.setPaymentAccountName(paymentaccountname);
                                            tx1341Request.setPaymentAccountNumber(paymentaccountnumber);

                                            BankAccount bankAccount = new BankAccount();
                                            bankAccount.setBankID(bankId);
                                            bankAccount.setAccountName(accountname);
                                            bankAccount.setAccountNumber(accountnumber);
                                            bankAccount.setBranchName(branchname);
                                            bankAccount.setProvince(province);
                                            bankAccount.setCity(city);
                                            tx1341Request.setBankAccount(bankAccount);

                                            // 3.执行报文处理
                                            tx1341Request.process();

                                            //2个信息参数
                                            HttpContext.Current.Items["txCode"] = "1341";
                                            HttpContext.Current.Items["txName"] = "市场订单结算(结算)";

                                            // 与支付平台进行通讯
                                            TxMessenger txMessenger = new TxMessenger();
                                            String[]    respMsg     = txMessenger.send(tx1341Request.getRequestMessage(), tx1341Request.getRequestSignature());// 0:message; 1:signature
                                            String      plaintext   = XmlUtil.formatXmlString(Encoding.UTF8.GetString(Convert.FromBase64String(respMsg[0])));
                                            Console.WriteLine("[message] = [" + respMsg[0] + "]");
                                            Console.WriteLine("[signature] = [" + respMsg[1] + "]");
                                            Console.WriteLine("[plaintext] = [" + plaintext + "]");

                                            Tx134xResponse tx134xResponse = new Tx134xResponse(respMsg[0], respMsg[1]);
                                            HttpContext.Current.Items["plainText"] = tx134xResponse.getResponsePlainText();
                                            string strs = tx134xResponse.getCode() + "," + tx134xResponse.getMessage();
                                            //消息提示
                                            //JScript.ShowAlert(this, strs);

                                            //日志记录 接口返回的信息
                                            paylogmodel.Start         = tx134xResponse.getCode();
                                            paylogmodel.ResultMessage = tx134xResponse.getMessage();
                                            paylogmodel.ID            = paylogID;
                                            bool payLog_update = paylogbll.Update(paylogmodel);

                                            #region  清算手续费 start
                                            bool bol = false;
                                            //收取代理商或企业手续费,并且手续费未结算的,且手续费大于0
                                            //if ((sxfsq == "1" || sxfsq == "2") && jsxf_no != 1 && js_sxf > 0)
                                            //    bol = JS_sxfWay(ordID, ReceiptNo, guid, compID, paymentID, js_sxf);
                                            //else
                                            bol = true;

                                            #endregion 清算手续费 end

                                            if ("2000".Equals(tx134xResponse.getCode()))
                                            {
                                                //查询该条订单相关的支付记录是否都已经结算
                                                DataTable dt    = new Hi.BLL.PAY_PrePayment().GetDate("ID", "PAY_Payment", "PrintNum=0 and IsAudit=1 and OrderID=" + ordID);
                                                int       n_row = dt.Rows.Count;


                                                SqlConnection con = new SqlConnection(LocalSqlServer);
                                                con.Open();
                                                SqlTransaction sqlTrans = con.BeginTransaction();

                                                int paymentnum = 0; //支付表修改记录
                                                int ordernum   = 0; //订单结算状态修改记录

                                                try
                                                {
                                                    //修改支付记录的结算状态
                                                    Hi.BLL.PAY_Payment paymentbll = new Hi.BLL.PAY_Payment();
                                                    if (bol)
                                                    {
                                                        paymentnum = paymentbll.updatePayState_JS(con, paymentID, sqlTrans);
                                                    }

                                                    //修改订单
                                                    Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(ordID);
                                                    if (orderModel.AuditAmount == orderModel.PayedAmount)
                                                    {
                                                        if (n_row == 1)
                                                        {
                                                            ordernum = paymentbll.UpdateOrderPaystate_JS(con, ordID, "1", sqlTrans);
                                                            if (ordernum > 0)
                                                            {
                                                                LogManager.WriteLog(LogFile.Trace.ToString(), "订单操作成功:" + DateTime.Now.ToString() + "----" + ReceiptNo);
                                                                //strMsg += "<br>订单结算操作成功:" + DateTime.Now.ToString() + "流水号:" + guid + " 订单号:" + ReceiptNo;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ordernum = paymentbll.UpdateOrderPaystate_JS(con, ordID, "2", sqlTrans);
                                                            if (ordernum > 0)
                                                            {
                                                                LogManager.WriteLog(LogFile.Trace.ToString(), "订单操作成功:" + DateTime.Now.ToString() + "----" + ReceiptNo);
                                                                //strMsg += "<br>订单结算操作成功:" + DateTime.Now.ToString() + "流水号:" + guid + " 订单号:" + ReceiptNo;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        //orderModel.vdef9 = "2";//部分结算
                                                        ordernum = paymentbll.UpdateOrderPaystate_JS(con, ordID, "2", sqlTrans);
                                                        if (ordernum > 0)
                                                        {
                                                            LogManager.WriteLog(LogFile.Trace.ToString(), "订单操作成功:" + DateTime.Now.ToString() + "----" + ReceiptNo);
                                                            // strMsg += "<br>订单结算操作成功:" + DateTime.Now.ToString() + "流水号:" + guid + " 订单号:" + ReceiptNo;
                                                        }
                                                    }

                                                    //执行修改成功后,提交事务,否则回滚
                                                    if (paymentnum > 0 && ordernum > 0)
                                                    {
                                                        sqlTrans.Commit();
                                                    }
                                                    else
                                                    {
                                                        sqlTrans.Rollback();
                                                    }
                                                }
                                                catch
                                                {
                                                    paymentnum = 0;
                                                    ordernum   = 0;
                                                    sqlTrans.Rollback();
                                                }
                                                finally
                                                {
                                                    con.Close();
                                                }
                                            }
                                            else
                                            {
                                                //清算出现问题,发送邮件通知
                                                strMsg += "<br><font color='red'>订单结算接口返回:</font>" + strs + "流水号:" + guid + "&nbsp;(" + new Hi.BLL.BD_Company().GetModel(compID).CompName + ")";
                                                ord_errornum++;

                                                LogManager.WriteLog(LogFile.Trace.ToString(), "订单结算接口返回非2000编码:" + strs + "\r\n" + "订单编号:" + ReceiptNo);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            LogManager.WriteLog(LogFile.Trace.ToString(), "订单调用中金结算接口出错:" + DateTime.Now.ToString() + "\r\n" + "订单编号:" + ReceiptNo);

                                            ord_errornum++;
                                            strMsg += "<br><font color='red'>订单调用中金结算接口出错:</font>" + DateTime.Now.ToString() + "流水号:" + guid + " 订单编号:" + ReceiptNo + "&nbsp;(" + new Hi.BLL.BD_Company().GetModel(compID).CompName + ")";
                                        }
                                    }
                                    else
                                    {
                                        LogManager.WriteLog(LogFile.Trace.ToString(), "订单结算接口日志表插入出错:" + DateTime.Now.ToString() + "\r\n" + "订单编号:" + ReceiptNo);
                                        ord_errornum++;
                                        strMsg += "<br><font color='red'>订单结算接口日志表插入出错:</font>" + DateTime.Now.ToString() + "流水号:" + guid + " 订单编号:" + ReceiptNo + "&nbsp;(" + new Hi.BLL.BD_Company().GetModel(compID).CompName + ")";
                                    }
                                }
                                else
                                {
                                    if (accountType == 11 || accountType == 12)
                                    {
                                        LogManager.WriteLog(LogFile.Trace.ToString(), "银行名称、持卡人名称、银行卡号不能为空!" + "\r\n");
                                    }
                                    else
                                    {
                                        LogManager.WriteLog(LogFile.Trace.ToString(), "中金账户名称、中金账户号码不能为空!" + "\r\n");
                                    }

                                    ord_errornum++;
                                    strMsg += "<br><font color='red'>订单结算银行名称、持卡人名称、银行卡号不能为空 或 中金账户名称、中金账户号码不能为空</font>&nbsp;(" + new Hi.BLL.BD_Company().GetModel(compID).CompName + ")";
                                }
                            }
                            else
                            {
                                db_num++;
                                db_meg = "担保支付需要代理商确认收货,才能进结算";
                            }
                        }
                        else
                        {
                            ord_errornum++;
                            strMsg += "<br><font color='red'>订单结算出错(结算手续费不一致):</font>" + DateTime.Now.ToString() + "流水号" + guid + "订单编号:" + ReceiptNo + "&nbsp;(" + new Hi.BLL.BD_Company().GetModel(compID).CompName + ")";
                            LogManager.WriteLog(LogFile.Trace.ToString(), "订单结算出错(结算手续费不一致):" + DateTime.Now.ToString() + "\r\n" + "订单编号:" + ReceiptNo);
                        }
                    }
                    catch (Exception ex)
                    {
                        ord_errornum++;
                        strMsg += "<br><font color='red'>订单结算出错:</font>" + DateTime.Now.ToString() + "流水号:" + guid + " 订单编号:" + ReceiptNo + "&nbsp;(" + new Hi.BLL.BD_Company().GetModel(compID).CompName + ")";
                        LogManager.WriteLog(LogFile.Trace.ToString(), "订单结算出错:" + DateTime.Now.ToString() + "\r\n" + "订单编号:" + ReceiptNo);
                    }
                    LogManager.WriteLog(LogFile.Trace.ToString(), "订单结算结束时间" + DateTime.Now.ToString() + "\r\n");
                }

                topMsg += "<br><strong>今天未清算订单共 " + dt_order.Rows.Count + "条,成功" + (dt_order.Rows.Count - ord_errornum - db_num) + "条,失败" + ord_errornum + "条</strong>";
                //担保支付信息记录(暂时不提示)
                if (!string.IsNullOrEmpty(db_meg))
                {
                    topMsg += "(" + db_num + " 条 " + db_meg + ")";
                }


                if (!string.IsNullOrEmpty(strMsg))
                {
                    strMsg += "<br>订单结算结束时间" + DateTime.Now.ToString() + "<br>===================================================<br>";
                }
            }
            else
            {
                downMsg = "<br>今天没有需要结算的订单;";
            }

            #endregion


            //最后输出
            string sum_mes = head;

            if (!string.IsNullOrEmpty(topMsg))
            {
                sum_mes += topMsg + strMsg;
            }
            else
            {
                sum_mes += downMsg;
            }

            if (!string.IsNullOrEmpty(fw_topMsg))
            {
                sum_mes += fw_topMsg + fw_strMsg;
            }
            else
            {
                sum_mes += fw_downMsg;
            }

            if (!string.IsNullOrEmpty(pre_topMsg))
            {
                sum_mes += pre_topMsg + pre_strMsg;
            }
            else
            {
                sum_mes += pre_downMsg;
            }

            PayInfoType.SendFinsh(sum_mes + @"谢谢!" + strDownMesg, ReceiptNo);

            #region 每天清算一次手续费
            string    orderNo       = WebConfigurationManager.AppSettings["OrgCode"] + DateTime.Now.ToString("yyyyMMdd");
            DataTable dt_sxf        = new Hi.BLL.PAY_PrePayment().GetdataTable_sxf(orderNo);
            long      price_sxf     = 0;
            string    receiptno_sxf = string.Empty;
            if (dt_sxf.Rows.Count > 0)
            {
                price_sxf     = Convert.ToInt64(Math.Round(Convert.ToDecimal(dt_sxf.Rows[0]["price_sumsxf"]), 2) * 100);
                receiptno_sxf = Convert.ToString(dt_sxf.Rows[0]["ReceiptNo"]);
                if (price_sxf > 0)
                {
                    bool fal_jssxf = JS_sxfWay(0, receiptno_sxf, Common.Number_repeat(""), 0, 0, price_sxf);
                    //if (fal_jssxf)
                    ///   resultMesage = resultMesage + "(手续费清算成功)";
                }
            }
            #endregion
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //ResultNotify resultNotify = new ResultNotify(this);
        //resultNotify.ProcessNotify();
        string resultFromWx = getPostStr();
        //设置支付参数
        var res = XDocument.Parse(resultFromWx);

        string return_code = res.Element("xml").Element("return_code").Value;

        string out_trade_no = res.Element("xml").Element("out_trade_no").Value;

        string result_code = res.Element("xml").Element("result_code").Value;

        string price = res.Element("xml").Element("total_fee").Value;

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //请在这里加上商户的业务逻辑程序代码
        //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
        //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

        if (return_code == "SUCCESS" || result_code == "SUCCESS")
        {
            //判断该笔订单是否在商户网站中已经做过处理
            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
            //如果有做过处理,不执行商户的业务程序

            string strWhere2 = string.Empty;
            if (out_trade_no != "")
            {
                strWhere2 += " number = '" + out_trade_no + "'";
            }
            Hi.Model.PAY_RegisterLog        regM = new Hi.Model.PAY_RegisterLog();
            List <Hi.Model.PAY_RegisterLog> regL = new Hi.BLL.PAY_RegisterLog().GetList("", strWhere2, "");
            if (regL == null || regL.Count <= 0)
            {
                //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                //return;
                Console.WriteLine("未找到对应的支付记录!");
            }
            regM = regL[0];
            string strWhere = string.Empty;
            if (out_trade_no != "")
            {
                strWhere += " guid = '" + out_trade_no + "'";
            }
            strWhere += " and isnull(dr,0)=0";
            Hi.Model.PAY_Payment        payM = new Hi.Model.PAY_Payment();
            List <Hi.Model.PAY_Payment> payL = new Hi.BLL.PAY_Payment().GetList("", strWhere, "");
            if (payL == null || payL.Count <= 0)
            {
                //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                // return;
                Console.WriteLine("未找到对应的支付记录!");
            }
            payM = payL[0];

            payM.PayDate = DateTime.Now;
            payM.ts      = DateTime.Now;
            payM.status  = 0;      //trade_status == "TRADE_FINISHED" ? 80 : 90;
            new Hi.BLL.PAY_Payment().Update(payM);
            regM.Start = "";       // trade_status;
            new Hi.BLL.PAY_RegisterLog().Update(regM);
            if (payM.IsAudit == 2) //该支付记录未修改成功进入,修改成功就不进入,请不要重复操作
            {
                //!!!支付成功 !!!
                decimal prepayPrice = 0;

                //企业钱包充值
                Hi.Model.PAY_PrePayment prepayMnew = new Hi.Model.PAY_PrePayment();
                string strWhere3 = string.Empty;
                if (out_trade_no != "")
                {
                    strWhere3 += " ID = " + payM.OrderID;
                }
                strWhere3 += " and isnull(dr,0)=0";
                List <Hi.Model.PAY_PrePayment> plist = new Hi.BLL.PAY_PrePayment().GetList("", strWhere3, "");
                if (plist.Count > 0)
                {
                    prepayMnew = plist[0];
                }

                //订单
                Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(payM.OrderID);
                if (orderModel != null)
                {
                    string strWhere1 = string.Empty;
                    strWhere1 += " vdef4 = '" + payM.ID + "'";
                    strWhere1 += " and isnull(dr,0)=0";
                    Hi.Model.PAY_PrePayment        prepayM = new Hi.Model.PAY_PrePayment();
                    List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", strWhere1, "");
                    if (prepayL != null && prepayL.Count > 0)
                    {
                        prepayM     = prepayL[0];
                        prepayPrice = prepayM.price * -1;
                    }

                    int           order  = 0;
                    int           prepay = 0;
                    int           pay    = 0;
                    decimal       prices = Convert.ToDecimal(price);
                    SqlConnection con    = new SqlConnection(LocalSqlServer);
                    con.Open();
                    SqlTransaction sqlTrans = con.BeginTransaction();
                    try
                    {
                        order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderModel.ID, payM.PayPrice + prepayPrice - Convert.ToDecimal(payM.vdef5), sqlTrans);
                        pay   = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);


                        if (prepayPrice > 0)
                        {
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                        }
                        else
                        {
                            prepay = 1;
                        }
                        sqlTrans.Commit();
                    }
                    catch
                    {
                        order  = 0;
                        prepay = 0;
                        pay    = 0;
                        sqlTrans.Rollback();
                    }
                    finally
                    {
                        con.Close();
                    }

                    if (order <= 0 || prepay <= 0 || pay <= 0)
                    {
                        Console.WriteLine("支付成功,但修改支付状态失败,请联系系统管理员,勿重复操作!");
                    }

                    try
                    {
                        //new Common().GetWxService("2", orderModel.ID.ToString(), "1");
                        if (orderModel.Otype != 9)
                        {
                            OrderInfoType.AddIntegral(orderModel.CompID, orderModel.DisID, "1", 1, orderModel.ID, (prepayPrice + prices), "订单支付", "", orderModel.CreateUserID);
                        }
                    }
                    catch { }
                    if (orderModel.Otype == (int)Enums.OType.推送账单)
                    {
                        Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "账单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(微信支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                    }
                    else
                    {
                        Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "订单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(微信支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                    }

                    //微信和安卓消息推送
                    try
                    {
                        new Common().GetWxService("2", orderModel.ID.ToString(), "1", prepayPrice + prices);
                    }
                    catch { }


                    Response.Write("success");  //请不要修改或删除
                }//钱包充值
                else if (prepayMnew != null)
                {
                    int           prepay = 0;
                    int           pay    = 0;
                    SqlConnection con    = new SqlConnection(LocalSqlServer);
                    con.Open();
                    SqlTransaction sqlTrans = con.BeginTransaction();
                    try
                    {
                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);
                        prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayMnew.ID, sqlTrans);
                        sqlTrans.Commit();
                    }
                    catch
                    {
                        pay    = 0;
                        prepay = 0;
                        sqlTrans.Rollback();
                    }
                    finally
                    {
                        con.Close();
                    }
                }
                else
                {
                    //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到该支付订单!", false);
                    //return;

                    Console.WriteLine("未找到该支付记录!");
                }
            }
            else
            {
                Console.WriteLine("success");
            }


            Response.Write("success");
        }
        else//验证失败
        {
            Response.Write("fail");
        }
    }
Exemple #7
0
    ///<summary>
    ///获取钱包充值流水号
    ///</summary>
    public List <string> Getpayidyfk(int UserID, int CompID, int DisID, string price)
    {
        int           prepayid = 0;
        int           payid    = 0;
        int           regid    = 0;
        List <string> list     = new List <string>();

        Hi.Model.PAY_PrePayment Prepay     = new Hi.Model.PAY_PrePayment();
        Hi.BLL.PAY_PrePayment   bll_prepay = new Hi.BLL.PAY_PrePayment();
        Hi.BLL.PAY_Payment      bll_pay    = new Hi.BLL.PAY_Payment();
        Hi.BLL.PAY_RegisterLog  bll_reg    = new Hi.BLL.PAY_RegisterLog();
        Hi.Model.BD_Distributor dis        = new Hi.BLL.BD_Distributor().GetModel(DisID);
        try
        {
            //在表PAY_PrePayment中生成一条数据
            Prepay.CompID     = CompID;
            Prepay.DisID      = DisID;
            Prepay.OrderID    = 0;
            Prepay.Start      = 2;
            Prepay.PreType    = 1;
            Prepay.price      = Convert.ToDecimal(price);
            Prepay.Paytime    = DateTime.Now;
            Prepay.CreatDate  = DateTime.Now;
            Prepay.OldId      = 0;
            Prepay.CrateUser  = UserID;
            Prepay.AuditState = 2;
            Prepay.AuditUser  = 0;
            Prepay.IsEnabled  = 1;
            Prepay.ts         = DateTime.Now;
            Prepay.modifyuser = UserID;
            prepayid          = bll_prepay.Add(Prepay);
            if (prepayid > 0)
            {
                //如果pay_prepayment表中插入数据成功的话,在pay_payment表中插入一条数据
                int keyID = prepayid;
                Hi.Model.PAY_PrePayment Prepay_M = bll_prepay.GetModel(prepayid);
                string guid = Guid.NewGuid().ToString().Replace("-", "");
                Hi.Model.PAY_Payment pay = new Hi.Model.PAY_Payment();
                pay.OrderID      = keyID;
                pay.DisID        = DisID;
                pay.PayUser      = dis.DisName;
                pay.PayPrice     = Convert.ToDecimal(price);
                pay.guid         = Common.Number_repeat(guid);
                pay.IsAudit      = 2;
                pay.vdef3        = "2";
                pay.CreateDate   = DateTime.Now;
                pay.CreateUserID = UserID;
                pay.ts           = DateTime.Now;
                pay.modifyuser   = UserID;
                pay.Channel      = "6";
                payid            = bll_pay.Add(pay);
                //如果pay_prepayment表中插入数据成功的话,在PAY_RegisterLog表中插入一条数据
                Hi.Model.PAY_RegisterLog reg = new Hi.Model.PAY_RegisterLog();
                reg.OrderId    = keyID;
                reg.Ordercode  = WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(keyID);
                reg.number     = pay.guid;
                reg.Price      = Convert.ToDecimal(price);
                reg.Payuse     = "企业钱包充值";
                reg.PayName    = dis.DisName;
                reg.DisID      = DisID;
                reg.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                reg.BankID     = "支付宝";
                reg.CreateUser = UserID;
                reg.CreateDate = DateTime.Now;
                reg.LogType    = 1375;
                regid          = bll_reg.Add(reg);
                if (payid > 0 && regid > 0)
                {
                    //返回的list第一行放支付流水号,第二行放企业订单号(支付时生成)
                    list.Add(ClsSystem.gnvl(pay.guid, ""));

                    list.Add(ClsSystem.gnvl(reg.Ordercode, ""));
                    return(list);
                }
            }
        }
        catch
        {
        }
        return(null);
    }
Exemple #8
0
    /// <summary>
    /// 支付宝支付
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnApliay()
    {
        //企业钱包充值记录
        Hi.Model.PAY_PrePayment prepayM = new Hi.BLL.PAY_PrePayment().GetModel(KeyID);
        decimal price = prepayM.price;

        #region 支付记录
        int    payid = 0;
        int    regid = 0;
        string guid  = Guid.NewGuid().ToString().Replace("-", "");
        Hi.Model.PAY_Payment payModel = new Hi.Model.PAY_Payment();
        payModel.OrderID      = KeyID;
        payModel.DisID        = this.DisID;
        payModel.PayUser      = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
        payModel.PayPrice     = price;
        payModel.guid         = Common.Number_repeat(guid);
        payModel.IsAudit      = 2;
        payModel.vdef3        = "2";
        payModel.CreateDate   = DateTime.Now;
        payModel.CreateUserID = this.UserID;
        payModel.ts           = DateTime.Now;
        payModel.modifyuser   = this.UserID;

        payModel.Channel  = "6";    //1,快捷支付,2,银联支付 ,3,网银支付,4,B2B网银支付,5,线下支付,6,支付宝支付 7,微信支付
        payModel.State    = 0;      //手续费收取方
        payModel.vdef5    = "0.00"; //支付手续费
        payModel.PrintNum = 1;      //结算标示

        payid = new Hi.BLL.PAY_Payment().Add(payModel);

        Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
        regModel.OrderId    = KeyID;
        regModel.Ordercode  = WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(KeyID);
        regModel.number     = payModel.guid;
        regModel.Price      = price;
        regModel.Payuse     = prepayM.PreType == 6 ? "转账汇款" : prepayM.PreType == 1 ? "企业钱包充值" : "";
        regModel.PayName    = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
        regModel.DisID      = this.DisID;
        regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
        regModel.Remark     = prepayM.vdef1;
        regModel.DisName    = new Hi.BLL.BD_Company().GetModel(this.CompID).CompName;
        regModel.BankID     = "支付宝";
        regModel.CreateUser = this.UserID;
        regModel.CreateDate = DateTime.Now;
        regModel.LogType    = 1375;
        regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);

        if (payid <= 0 || regid <= 0)
        {
            //JScript.AlertMsg(this, "数据异常!");
            ClientScript.RegisterStartupScript(this.GetType(), "payTx1375", "<script>$('#lblErr').html('数据异常!');</script>");
            return;
        }

        #endregion

        #region  支付宝支付
        //支付类型
        string payment_type = "1";
        //必填,不能修改
        //服务器异步通知页面路径
        string notify_url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/Distributor/Pay/ReceiveNoticeAlipay.aspx";
        //需http://格式的完整路径,不能加?id=123这类自定义参数

        //页面跳转同步通知页面路径
        string return_url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/Distributor/pay/PrePayList.aspx";
        //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/

        //卖家支付宝帐户
        //string seller_email = "*****@*****.**";
        string seller_email = Common.GetPayWxandAli(this.CompID).ali_seller_email;// ConfigurationManager.AppSettings["seller_email"] == null ? "*****@*****.**" : ConfigurationManager.AppSettings["seller_email"].ToString().Trim();

        //必填
        //商户订单号
        string out_trade_no = payModel.guid;// OrderModel.GUID;
        //商户网站订单系统中唯一订单号,必填



        //订单名称
        string subject = "钱包充值";//OrderModel.GUID;
        //必填
        //付款金额
        string total_fee = price.ToString("0.00");

        string paymethod   = string.Empty; //默认支付方式
        string defaultbank = string.Empty; //默认网银

        //if (OrderInfoModel.BankId != "0" && OrderInfoModel.BankId != "")
        //{
        //    //默认支付方式
        //    paymethod = "bankPay";
        //    //必填
        //    //默认网银
        //    defaultbank = OrderInfoModel.BankId;
        //}

        //必填
        //订单描述
        string body = prepayM.vdef1;
        //商品展示地址
        string show_url = "http://www.my1818.com";
        //需以http://开头的完整路径,

        //防钓鱼时间戳
        string anti_phishing_key = Submit.Query_timestamp();//"";
        //若要使用请调用类文件submit中的query_timestamp函数

        //客户端的IP地址
        string exter_invoke_ip = Page.Request.UserHostAddress;
        //非局域网的外网IP地址,如:221.0.0.1

        //把请求参数打包成数组
        SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
        sParaTemp.Add("partner", Config.Partner);
        sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
        sParaTemp.Add("service", "create_direct_pay_by_user");
        sParaTemp.Add("payment_type", payment_type);
        sParaTemp.Add("notify_url", notify_url);
        sParaTemp.Add("return_url", return_url);
        sParaTemp.Add("seller_email", seller_email);
        sParaTemp.Add("out_trade_no", out_trade_no);
        sParaTemp.Add("subject", subject);
        sParaTemp.Add("total_fee", total_fee);
        sParaTemp.Add("body", body);

        //if (OrderInfoModel.BankId != "0" && OrderInfoModel.BankId != "")
        //{
        //    sParaTemp.Add("paymethod", paymethod);
        //    sParaTemp.Add("defaultbank", defaultbank);
        //}

        sParaTemp.Add("show_url", show_url);
        sParaTemp.Add("anti_phishing_key", anti_phishing_key);
        sParaTemp.Add("exter_invoke_ip", exter_invoke_ip);

        //建立请求
        string sHtmlText = Submit.BuildRequest(sParaTemp, "get", "确认");
        Response.Write(sHtmlText);
        #endregion
    }
Exemple #9
0
    public void tx1311()
    {
        Hi.Model.PAY_Payment     payModel = new Hi.Model.PAY_Payment();
        Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
        try
        {
            //账户类型
            string AccountType = Request["AccountType"];
            int    accountType = Convert.ToInt32(AccountType);

            //银行编码
            string bankid = this.hidBank.Value;

            Hi.Model.PAY_PrePayment prepayM = new Hi.BLL.PAY_PrePayment().GetModel(KeyID);
            decimal price = prepayM.price;

            #region     计算支付手续费 start
            string  sxfsq    = "-1";
            decimal sxf      = 0;
            decimal comp_sxf = 0;//收费方是厂商是,为了不改变支付金额,故声明此变量来记录,厂商手续费。
            // 获取手续费 begin
            string[] Json = Common.GetSxf(this.CompID, AccountType, bankid, price);

            string strMsg = Json[2].ToString();
            if (!string.IsNullOrEmpty(strMsg))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "payTx1375", "<script>$('#lblErr').html(' 充值金额小于支付手续费,不允许支付 !');</script>");
                return;
            }
            else
            {
                sxfsq    = Json[1].ToString();
                sxf      = Convert.ToDecimal(Json[0]);
                comp_sxf = Convert.ToDecimal(Json[3]);
            }

            //支付总金额(含手续费)
            decimal UNIT = 0.01M;
            price = price + Common.Round(sxf, UNIT);

            #endregion  计算支付手续费 end



            int    payid   = 0;
            int    regid   = 0;
            string orderNo = WebConfigurationManager.AppSettings["OrgCode"] + DateTime.Now.ToString("yyyyMMdd");//支付订单号前半部分

            string guid = Guid.NewGuid().ToString().Replace("-", "");
            payModel.OrderID      = KeyID;
            payModel.DisID        = this.DisID;
            payModel.PayUser      = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
            payModel.PayPrice     = price;
            payModel.IsAudit      = 2;
            payModel.guid         = Common.Number_repeat(guid);
            payModel.vdef3        = "2";
            payModel.vdef4        = orderNo;
            payModel.CreateDate   = DateTime.Now;
            payModel.CreateUserID = this.UserID;
            payModel.ts           = DateTime.Now;
            payModel.modifyuser   = this.UserID;
            //判断账户类型,判断支付渠道,然后赋值
            if (AccountType == "11")
            {
                if (bankid == "888")
                {
                    payModel.Channel = "2";
                }
                else
                {
                    payModel.Channel = "3";
                }
            }//个人贷记卡支付
            else if (AccountType == "13")
            {
                payModel.Channel = "8";
            }
            else
            {
                payModel.Channel = "4";
            }
            payModel.State = Convert.ToInt32(sxfsq);//手续费收取方
            if (sxfsq.Equals("2"))
            {
                payModel.vdef5 = comp_sxf.ToString("0.00");
            }
            else
            {
                payModel.vdef5 = sxf.ToString("0.00");//支付手续费
            }
            payid = new Hi.BLL.PAY_Payment().Add(payModel);

            regModel.OrderId    = KeyID;
            regModel.Ordercode  = WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(KeyID);
            regModel.number     = payModel.guid;
            regModel.Price      = price;
            regModel.Payuse     = prepayM.PreType == 6 ? "转账汇款" : prepayM.PreType == 1 ? "企业钱包充值" : "";
            regModel.PayName    = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
            regModel.DisID      = this.DisID;
            regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            regModel.Remark     = prepayM.vdef1;
            regModel.DisName    = new Hi.BLL.BD_Company().GetModel(this.CompID).CompName;
            regModel.BankID     = bankid;
            regModel.CreateUser = this.UserID;
            regModel.CreateDate = DateTime.Now;
            regModel.LogType    = 1311;
            regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);

            if (payid <= 0 || regid <= 0)
            {
                //JScript.AlertMsg(this, "数据异常!");
                ClientScript.RegisterStartupScript(this.GetType(), "payTx1375", "<script>$('#lblErr').html('数据异常!');</script>");
                return;
            }

            string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
            try
            {
                PaymentEnvironment.Initialize(configPath);
            }
            catch
            {
                //JScript.AlertMsg(this, "支付配置有误,请联系系统管理员!");
                //return;
                throw new Exception("支付配置有误,请联系系统管理员!");
            }

            String institutionID = WebConfigurationManager.AppSettings["PayOrgCode"];
            //原来传递的支付订单号----目前订单号运行重复
            //String orderNo = WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(KeyID);
            long   amount    = Convert.ToInt64(price * 100);
            long   fee       = 0;
            String payerID   = this.DisID.ToString();
            String payerName = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
            String usage     = prepayM.PreType == 6 ? "转账汇款" : prepayM.PreType == 1 ? "企业钱包充值" : "";
            String remark    = prepayM.PreType == 6 ? "转账汇款" : prepayM.PreType == 1 ? "企业钱包充值" : "";

            String notificationURL = string.Empty;

            if (WebConfigurationManager.AppSettings["PayType"] == "0")
            {
                notificationURL = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/Handler/ReceiveNoticePage.ashx";
            }
            else
            {
                notificationURL = "http://www.my1818.com/Handler/ReceiveNoticePage.ashx";//回调页面地址
            }
            String payees = new Hi.BLL.BD_Company().GetModel(this.CompID).CompName;


            //判断支付接口
            string Pay_type = WebConfigurationManager.AppSettings["PayType"];
            String bankID   = string.Empty;
            if (Pay_type == "0")
            {
                bankID = "700";//bankid;//
            }
            else
            {
                bankID = bankid;
            }



            // 2.创建交易请求对象
            Tx1311Request tx1311Request = new Tx1311Request();
            tx1311Request.setInstitutionID(institutionID);     //机构号码
            tx1311Request.setOrderNo(orderNo);                 //转账流水号
            tx1311Request.setPaymentNo(payModel.guid);         //支付交易流水号
            tx1311Request.setAmount(amount);                   //支付金额 单位分
            tx1311Request.setFee(fee);                         //支付服务手续费 单位分
            tx1311Request.setPayerID("");                      //付款人注册ID
            tx1311Request.setPayerName("");                    //付款方名称
            tx1311Request.setUsage(usage);                     //资金用途
            tx1311Request.setRemark(remark);                   //备注
            tx1311Request.setNotificationURL(notificationURL); //机构接收支付通知的URL
            tx1311Request.addPayee("");                        //收款方名称
            tx1311Request.setBankID(bankID);                   //付款银行标识

            if (accountType == 13)
            {
                tx1311Request.setAccountType(11); //付款方帐号类型
                tx1311Request.setCardType("02");  //银行卡类型(01=借记卡、02=贷记卡)
            }
            else if (accountType == 11)
            {
                tx1311Request.setAccountType(accountType); //付款方帐号类型
                tx1311Request.setCardType("01");           //银行卡类型(01=借记卡、02=贷记卡)
            }
            else if (accountType == 12)
            {
                tx1311Request.setAccountType(accountType);//付款方帐号类型
            }
            // 3.执行报文处理
            tx1311Request.process();

            try
            {
                Hi.Model.PAY_RegisterLog regM = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                regM.PlanMessage = tx1311Request.getRequestPlainText();
                new Hi.BLL.PAY_RegisterLog().Update(regM);
            }
            catch { }

            // 4.将参数放置到request对象
            // //3个交易参数
            HttpContext.Current.Items["plainText"] = tx1311Request.getRequestPlainText();
            HttpContext.Current.Items["message"]   = tx1311Request.getRequestMessage();
            HttpContext.Current.Items["signature"] = tx1311Request.getRequestSignature();
            // //2个信息参数
            HttpContext.Current.Items["txCode"] = "1311";
            HttpContext.Current.Items["txName"] = "市场订单支付直通车";
            // 1个action(支付平台地址)参数
            HttpContext.Current.Items["action"] = PaymentEnvironment.PaymentURL;

            // 5.转向Request.jsp页面
            Context.Server.Transfer("ReRequest.aspx", true);
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "payTx1375", "<script>$('#lblErr').html('" + ex.Message + "!');</script>");
            return;
        }
    }
Exemple #10
0
    protected void btnTx1376_Click(object sender, EventArgs e)
    {
        try
        {
            Hi.Model.PAY_PrePayment prepayM = new Hi.Model.PAY_PrePayment();
            Hi.Model.PAY_Payment    payM    = new Hi.Model.PAY_Payment();
            if (Request.QueryString["KeyID"] == "")
            {
                KeyID = 0;
            }
            else
            {
                KeyID = Convert.ToInt32(Common.DesDecrypt(Request.QueryString["KeyID"].ToString(), Common.EncryptKey));
            }

            string  phoneCode = this.txtPhoneNum.Value; //检验码
            decimal price     = 0;                      //使用企业钱包金额
            int     hidPay    = 0;                      //支付表ID
            if (ViewState["payid"] == null || ViewState["payid"] == "")
            {
                //JScript.ShowAlert(this, "数据异常!", "$('#txtPhoneNum').val('');$('.tip').fadeOut(100);$('.opacity').fadeOut(100);");
                Tx1376ErrResult("数据异常!");
                return;
            }
            hidPay             = Convert.ToInt32(ViewState["payid"]);
            ViewState["payid"] = null;
            payM = new Hi.BLL.PAY_Payment().GetModel(hidPay);
            int hidPrepay = KeyID;//企业钱包表ID
            if (hidPrepay <= 0)
            {
                //JScript.ShowAlert(this, "数据异常!", "$('#txtPhoneNum').val('');$('.tip').fadeOut(100);$('.opacity').fadeOut(100);");
                Tx1376ErrResult("数据异常!");
                return;
            }
            prepayM = new Hi.BLL.PAY_PrePayment().GetModel(Convert.ToInt32(hidPrepay));
            price   = prepayM.price;
            int hidFastPay = Convert.ToInt32(this.hidFastPay.Value);
            int regid      = 0;

            Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
            regModel.OrderId    = hidPrepay;
            regModel.Ordercode  = payM.vdef4;// WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(hidPrepay);
            regModel.number     = payM.guid;
            regModel.Price      = price;
            regModel.Payuse     = prepayM.PreType == 6 ? "转账汇款" : prepayM.PreType == 1 ? "企业钱包充值" : "";
            regModel.PayName    = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
            regModel.DisID      = this.DisID;
            regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            regModel.Remark     = prepayM.vdef1;
            regModel.DisName    = new Hi.BLL.BD_Company().GetModel(this.CompID).CompName;
            regModel.BankID     = new Hi.BLL.PAY_FastPayMent().GetModel(hidFastPay).BankID.ToString();
            regModel.CreateUser = this.UserID;
            regModel.CreateDate = DateTime.Now;
            regModel.LogType    = 1376;
            regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);

            if (regid <= 0)
            {
                Tx1376ErrResult("数据异常!");
                return;
            }

            if (WebConfigurationManager.AppSettings["Paytest_zj"] != "1")
            {
                string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
                try
                {
                    PaymentEnvironment.Initialize(configPath);
                }
                catch
                {
                    throw new Exception("支付配置不正确,请联系管理员!");
                }

                string institutionID = WebConfigurationManager.AppSettings["PayOrgCode"];//机构号码

                Tx1376Request tx1376Request = new Tx1376Request();

                tx1376Request.setInstitutionID(institutionID);
                tx1376Request.setOrderNo(payM.vdef4);//WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(hidPrepay)
                tx1376Request.setPaymentNo(new Hi.BLL.PAY_Payment().GetModel(Convert.ToInt32(hidPay)).guid);
                tx1376Request.setSmsValidationCode(phoneCode);

                tx1376Request.process();

                TxMessenger txMessenger = new TxMessenger();
                String[]    respMsg     = txMessenger.send(tx1376Request.getRequestMessage(), tx1376Request.getRequestSignature());

                Tx1376Response tx1376Response = new Tx1376Response(respMsg[0], respMsg[1]);

                try
                {
                    Hi.Model.PAY_RegisterLog regM = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                    regM.PlanMessage   = tx1376Request.getRequestPlainText();
                    regM.Start         = tx1376Response.getCode();
                    regM.ResultMessage = tx1376Response.getMessage();
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                    Hi.Model.PAY_Payment payModel = new Hi.BLL.PAY_Payment().GetModel(hidPay);
                    payM.PayDate          = DateTime.Now;
                    payModel.ts           = DateTime.Now;
                    payModel.verifystatus = tx1376Response.getVerifyStatus();
                    payModel.status       = tx1376Response.getStatus();
                    new Hi.BLL.PAY_Payment().Update(payModel);
                }
                catch { }
                if (!"2000".Equals(tx1376Response.getCode()))
                {
                    Tx1376ErrResult(tx1376Response.getMessage());
                    return;
                }
                int VerifyStatus = tx1376Response.getVerifyStatus();
                int Status       = tx1376Response.getStatus();
                if (VerifyStatus != 40 || Status != 20)//VerifyStatus = 40 验证码验证成功,Status = 20 支付成功
                {
                    if (Status == 10)
                    {
                        //中金:支付处理中,钱会从账户中扣除,第二天会退回到账户中。
                        Tx1376ErrResult("代扣失败");
                        return;
                    }
                    Tx1376ErrResult(tx1376Response.getResponseMessage());
                    return;
                }
            }
            else
            {
                try
                {
                    Hi.Model.PAY_RegisterLog regM = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                    regM.PlanMessage   = "";
                    regM.Start         = "2000";
                    regM.ResultMessage = "OK.";
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                    Hi.Model.PAY_Payment payModel = new Hi.BLL.PAY_Payment().GetModel(hidPay);
                    payM.PayDate          = DateTime.Now;
                    payModel.ts           = DateTime.Now;
                    payModel.verifystatus = 40;
                    payModel.status       = 20;
                    new Hi.BLL.PAY_Payment().Update(payModel);
                }
                catch { }
            }

            int           prepay = 0;
            int           pay    = 0;
            SqlConnection con    = new SqlConnection(LocalSqlServer);
            con.Open();
            SqlTransaction sqlTrans = con.BeginTransaction();
            try
            {
                pay    = new Hi.BLL.PAY_Payment().updatePayState(con, hidPay, sqlTrans);
                prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, hidPrepay, sqlTrans);
                if (pay > 0 && prepay > 0)
                {
                    sqlTrans.Commit();
                }
                else
                {
                    sqlTrans.Rollback();
                }
            }
            catch
            {
                pay    = 0;
                prepay = 0;
                sqlTrans.Rollback();
            }
            finally
            {
                con.Close();
            }
            if (pay <= 0 || prepay <= 0)
            {
                Tx1376ErrResult("支付成功,但修改支付状态失败,请联系系统管理员,勿重复操作!");
                return;
            }
            Response.Redirect("PaySuccess.aspx?type=" + Common.DesEncrypt("3", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey), false);
            return;
        }
        catch (Exception ex)
        {
            JScript.AlertMethod(this, ex.Message, JScript.IconOption.错误, "function (){ $('#txtPhoneNum').val('');$('.tip').fadeOut(100);$('.opacity').fadeOut(100); }");
            return;
        }
    }
Exemple #11
0
    protected void btnPay_Click(object sender, EventArgs e)
    {
        string strWhere = " 1=1 ";

        if (KeyID > 0)
        {
            strWhere += " and OrderID = " + KeyID;
        }
        strWhere += " and vdef3 = 2 and status = 20 and isnull(dr,0)=0";
        List <Hi.Model.PAY_Payment> payL = new Hi.BLL.PAY_Payment().GetList("", strWhere, "");

        if (payL.Count > 0)
        {
            int           prepay = 0;
            int           pay    = 0;
            SqlConnection con    = new SqlConnection(LocalSqlServer);
            con.Open();
            SqlTransaction sqlTrans = con.BeginTransaction();
            try
            {
                pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payL[0].ID, sqlTrans);
                prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, KeyID, sqlTrans);
                sqlTrans.Commit();
            }
            catch
            {
                pay    = 0;
                prepay = 0;
                sqlTrans.Rollback();
            }
            finally
            {
                con.Close();
            }
            if (pay > 0 && prepay > 0)
            {
                JScript.AlertMethod(this, "转账已成功!", JScript.IconOption.正确, "function (){ location.replace('" + ("PrePayList.aspx") + "'); }");
                return;
            }
            else
            {
                JScript.AlertMsgOne(this, "系统繁忙,请稍后!", JScript.IconOption.错误);
                return;
            }
        }

        string a2 = this.hida2.Value; //是否使用快捷支付
        string a3 = this.hida3.Value; //是否使用网银支付
        string a5 = this.hida5.Value; //是否使用其他支付

        if (a2 == "1" && a3 == "0" && a5 == "0")
        {
            tx1375();
        }
        else if (a3 == "1" && a2 == "0" && a5 == "0")
        {
            tx1311();
        }
        else if (a5 == "1" && a2 == "0" && a3 == "0")
        {
            if (hidWxorAplipay.Value == "zfb")
            {
                btnApliay();
            }
            else
            {
                btnWx();
            }
        }
        else
        {
            JScript.AlertMsgOne(this, "请选择支付方式!", JScript.IconOption.错误);
            return;
        }
    }
Exemple #12
0
    /// <summary>
    /// 申请退款
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void btnRefund_Click(object sender, EventArgs e)
    //{
    //    Hi.Model.DIS_Order OrderModel = OrderBll.GetModel(KeyID);

    //    if (OrderModel != null)
    //    {
    //        if ((OrderModel.OState == (int)Enums.OrderState.已审) && OrderModel.PayState == (int)Enums.PayState.已支付)
    //        {
    //            string sql = " update [DIS_Order] set [PayState]=" + (int)Enums.PayState.申请退款 + ",[ReturnState]=" + (int)Enums.ReturnState.申请退款 + " where ID=" + KeyID;

    //            if (OrderBll.UpdateOrderState(sql))
    //            {
    //                Utils.AddSysBusinessLog(this.CompID, "Order", KeyID.ToString(), "申请退款", "");
    //                //Bind();
    //                Response.Redirect("OrderInfo.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
    //            }
    //        }
    //        else
    //        {
    //            JScript.ShowAlert(this, "数据状态不正确,不能取消!");
    //        }
    //    }
    //}

    /// <summary>
    /// 支付查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPayInfo_Click(object sender, EventArgs e)
    {
        Hi.Model.DIS_Order      orderM  = OrderBll.GetModel(KeyID);
        Hi.Model.PAY_PrePayment prepayM = new Hi.Model.PAY_PrePayment();
        if (orderM.PayState == (int)Enums.PayState.已支付)
        {
            //支付已成功
            JScript.AlertMsgOne(this, "支付已成功!", JScript.IconOption.笑脸);
            return;
        }
        else
        {
            //支付未成功
            string strWhere5 = string.Empty;
            if (KeyID > 0)
            {
                strWhere5 += " OrderID = " + KeyID;
            }
            strWhere5 += " and isnull(dr,0)=0";
            List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", strWhere5, "");
            if (prepayL.Count > 0 && orderM.AuditAmount == prepayL[0].price * -1)
            {
                //只用企业钱包支付,但是修改状态时出错
                SqlConnection con = new SqlConnection(LocalSqlServer);
                con.Open();
                SqlTransaction sqlTrans = con.BeginTransaction();
                int            order    = 0;
                int            prepay   = 0;
                try
                {
                    order  = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, KeyID, prepayL[0].price * -1, sqlTrans);
                    prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayL[0].ID, sqlTrans);
                    sqlTrans.Commit();
                }
                catch
                {
                    order  = 0;
                    prepay = 0;
                    sqlTrans.Rollback();
                }
                finally
                {
                    con.Close();
                }
                if (order > 0 && prepay > 0)
                {
                    JScript.AlertMsgOne(this, "支付已成功!", JScript.IconOption.笑脸);
                    return;
                }
                else
                {
                    JScript.AlertMsgOne(this, "支付处理中!", JScript.IconOption.哭脸);
                    return;
                }
            }

            string strWhere = string.Empty;
            if (KeyID > 0)
            {
                strWhere += " OrderID = " + KeyID;
            }
            strWhere += " and vdef3 = '1' and verifystatus = '40' and status = '20' and isnull(dr,0)=0";
            List <Hi.Model.PAY_Payment> payL = new Hi.BLL.PAY_Payment().GetList("", strWhere, "");
            if (payL.Count > 0)
            {
                //使用快捷支付成功,但是修改状态失败
                if (orderM.AuditAmount > payL[0].PayPrice)
                {
                    //是否使用企业钱包
                    string strWhere1 = string.Empty;
                    if (KeyID != 0)
                    {
                        strWhere1 += " OrderID = " + KeyID;
                    }
                    strWhere += " and isnull(dr,0)=0";
                    prepayM   = new Hi.BLL.PAY_PrePayment().GetList("", strWhere1, "")[0];
                }
                int           order  = 0;
                int           prepay = 0;
                int           pay    = 0;
                SqlConnection con    = new SqlConnection(LocalSqlServer);
                con.Open();
                SqlTransaction sqlTrans = con.BeginTransaction();
                try
                {
                    order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderM.ID, payL[0].PayPrice + (prepayM.price * -1), sqlTrans);

                    if (orderM.AuditAmount == payL[0].PayPrice)
                    {
                        prepay = 1;
                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payL[0].ID, sqlTrans);
                    }
                    else if (orderM.AuditAmount > payL[0].PayPrice)
                    {
                        prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payL[0].ID, sqlTrans);
                    }
                    else
                    {
                        order  = 0;
                        prepay = 0;
                        pay    = 0;
                        sqlTrans.Rollback();
                    }

                    sqlTrans.Commit();
                }
                catch
                {
                    order  = 0;
                    prepay = 0;
                    pay    = 0;
                    sqlTrans.Rollback();
                }
                finally
                {
                    con.Close();
                }
                if (order > 0 && prepay > 0 && pay > 0)
                {
                    JScript.AlertMsgOne(this, "支付成功!", JScript.IconOption.笑脸);
                    //Bind();
                    Response.Redirect("neworder/orderdetail.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
                    return;
                }
                else
                {
                    JScript.AlertMsgOne(this, "支付处理中!", JScript.IconOption.哭脸);
                    return;
                }
            }
            else
            {
                //使用快捷支付未成功
                string strWhere2 = string.Empty;
                if (KeyID > 0)
                {
                    strWhere2 += " OrderID = " + KeyID;
                }
                strWhere2 += " and vdef3 = '1' and verifystatus = '40' and status = '10' and isnull(dr,0)=0";
                List <Hi.Model.PAY_Payment> payList = new Hi.BLL.PAY_Payment().GetList("", strWhere2, "ID desc");

                if (payList.Count > 0)
                {
                    //使用快捷支付,处理中
                    int regid = 0;
                    try
                    {
                        Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
                        regModel.OrderId    = KeyID;
                        regModel.Ordercode  = orderM.ReceiptNo;
                        regModel.number     = payList[0].guid;
                        regModel.Price      = payList[0].PayPrice;
                        regModel.Payuse     = "订单支付查询";
                        regModel.PayName    = new Hi.BLL.BD_Distributor().GetModel(orderM.DisID).DisName;
                        regModel.DisID      = orderM.DisID;
                        regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        regModel.Remark     = orderM.Remark;
                        regModel.DisName    = new Hi.BLL.BD_Company().GetModel(orderM.CompID).CompName;
                        regModel.CreateUser = this.UserID;
                        regModel.CreateDate = DateTime.Now;
                        regModel.LogType    = 1372;
                        regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    if (regid > 0)
                    {
                        if (orderM.AuditAmount > payList[0].PayPrice)
                        {
                            //是否使用企业钱包
                            string strWhere3 = string.Empty;
                            if (KeyID != 0)
                            {
                                strWhere3 += " OrderID = " + KeyID;
                            }
                            strWhere3 += " and isnull(dr,0)=0";
                            prepayM    = new Hi.BLL.PAY_PrePayment().GetList("", strWhere3, "")[0];
                        }

                        //调用快捷支付查询接口
                        string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
                        PaymentEnvironment.Initialize(configPath);

                        Tx1372Request tx1372Request = new Tx1372Request();
                        tx1372Request.setInstitutionID("001520");
                        tx1372Request.setPaymentNo(payList[0].guid);
                        tx1372Request.process();

                        TxMessenger txMessenger = new TxMessenger();
                        String[]    respMsg     = txMessenger.send(tx1372Request.getRequestMessage(), tx1372Request.getRequestSignature());

                        Tx1372Response tx1372Response = new Tx1372Response(respMsg[0], respMsg[1]);

                        try
                        {
                            Hi.Model.PAY_RegisterLog regModel = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                            regModel.Start         = tx1372Response.getCode();
                            regModel.ResultMessage = tx1372Response.getMessage();
                            new Hi.BLL.PAY_RegisterLog().Update(regModel);
                            Hi.Model.PAY_Payment payM = new Hi.BLL.PAY_Payment().GetModel(payList[0].ID);
                            payM.status = tx1372Response.getStatus();
                            new Hi.BLL.PAY_Payment().Update(payM);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        if ("2000".Equals(tx1372Response.getCode()))
                        {
                            int Status = tx1372Response.getStatus();
                            if (Status == 10)
                            {
                                JScript.AlertMsgOne(this, "支付处理中!", JScript.IconOption.哭脸);
                                return;
                            }
                            else if (Status == 20)
                            {
                                int           order  = 0;
                                int           prepay = 0;
                                int           pay    = 0;
                                SqlConnection con    = new SqlConnection(LocalSqlServer);
                                con.Open();
                                SqlTransaction sqlTrans = con.BeginTransaction();
                                try
                                {
                                    order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, KeyID, payList[0].PayPrice + prepayM.price * -1, sqlTrans);

                                    if (orderM.AuditAmount == payList[0].PayPrice)
                                    {
                                        prepay = 1;
                                        pay    = 1;
                                    }
                                    else if (orderM.AuditAmount > payList[0].PayPrice)
                                    {
                                        prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payList[0].ID, sqlTrans);
                                    }
                                    else
                                    {
                                        sqlTrans.Rollback();
                                    }

                                    sqlTrans.Commit();
                                }
                                catch (Exception ex)
                                {
                                    order  = 0;
                                    prepay = 0;
                                    pay    = 0;
                                    sqlTrans.Rollback();
                                }
                                finally
                                {
                                    con.Close();
                                }

                                if (order > 0 && prepay > 0 && pay > 0)
                                {
                                    JScript.AlertMsgOne(this, "支付成功!", JScript.IconOption.笑脸);
                                    //Bind();
                                    Response.Redirect("neworder/orderdetail.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
                                    return;
                                }
                                else
                                {
                                    JScript.AlertMsgOne(this, "系统繁忙,请稍后!", JScript.IconOption.错误);
                                    return;
                                }
                            }
                            else if (Status == 30)
                            {
                                bool f = false;
                                try
                                {
                                    Hi.Model.PAY_PrePayment prepayModel = new Hi.BLL.PAY_PrePayment().GetModel(prepayL[0].ID);
                                    prepayModel.Start = Convert.ToInt32(Enums.PrePayMentState.失败);
                                    f = new Hi.BLL.PAY_PrePayment().Update(prepayModel);
                                    Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(KeyID);
                                    orderModel.PayState = Convert.ToInt32(Enums.PayState.未支付);
                                    f = new Hi.BLL.DIS_Order().Update(orderModel);
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                                if (f)
                                {
                                    JScript.AlertMsgOne(this, "支付失败!", JScript.IconOption.错误);
                                    Bind();
                                    return;
                                }
                                else
                                {
                                    JScript.AlertMsgOne(this, "系统繁忙,请稍后!", JScript.IconOption.错误);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #13
0
    /// <summary>
    /// 中金聚合支付(微信支付宝支付)
    /// </summary>
    /// <param name="paytype">类型(10=微信扫码支付  20=支付宝扫码支付)</param>
    /// <param name="KeyID">支付订单id</param>
    /// <param name="payPrice">本次支付金额</param>
    /// <returns></returns>
    public static string[] tx1401(string paytype, string KeyID, decimal payPrice)
    {
        string imageUrl = string.Empty;
        bool   fal      = false;

        Hi.Model.DIS_Order      OrderModel = new Hi.BLL.DIS_Order().GetModel(Convert.ToInt32(KeyID));
        Hi.Model.BD_Distributor disModel   = new Hi.BLL.BD_Distributor().GetModel(OrderModel.DisID);



        #region     计算支付手续费 start
        string  sxfsq    = "-1";
        decimal sxf      = 0;
        decimal comp_sxf = 0; //收费方是厂商是,为了不改变支付金额,故声明此变量来记录,厂商手续费。
                              // 获取手续费 begin
        string[] Json = Common.GetAli_Sxf(disModel.CompID, payPrice);

        string strMsg = Json[2].ToString();
        if (!string.IsNullOrEmpty(strMsg))
        {
            return(new string[] { "false", strMsg }); //"{\"sxf\":\"" + sxf + "\",\"sxfsq\":\"" + sxfsq + "\",\"strMsg\":\"" + str + "\"}";
        }
        else
        {
            sxfsq    = Json[1].ToString();
            sxf      = Convert.ToDecimal(Json[0]);
            comp_sxf = Convert.ToDecimal(Json[3]);
        }
        // 获取手续费 end


        //支付总金额(含手续费)
        decimal UNIT = 0.01M;
        payPrice = payPrice + Common.Round(sxf, UNIT);

        #endregion  计算支付手续费 end


        int payid = 0;
        int regid = 0;
        Hi.Model.PAY_Payment payModel = new Hi.Model.PAY_Payment();
        string orderNo = WebConfigurationManager.AppSettings["OrgCode"] + DateTime.Now.ToString("yyyyMMdd");//支付订单号前半部分

        string guid = Guid.NewGuid().ToString().Replace("-", "");
        payModel.OrderID      = OrderModel.ID;
        payModel.DisID        = OrderModel.DisID;
        payModel.Type         = Convert.ToInt32(WebConfigurationManager.AppSettings["IsDBPay"]);
        payModel.PayUser      = disModel.DisName;
        payModel.PayPrice     = payPrice;
        payModel.IsAudit      = 2;
        payModel.guid         = Common.Number_repeat(guid);
        payModel.vdef3        = "1";//1,订单支付,2,预付款充值、汇款
        payModel.vdef4        = orderNo;
        payModel.CreateDate   = DateTime.Now;
        payModel.CreateUserID = OrderModel.CreateUserID;
        payModel.ts           = DateTime.Now;
        payModel.modifyuser   = OrderModel.CreateUserID;
        payModel.Channel      = paytype.Equals("10") ? "7" : "6"; //(微信支付6,支付宝7)

        payModel.State = Convert.ToInt32(sxfsq);                  //手续费收取方

        if (sxfsq.Equals("2"))
        {
            payModel.vdef5 = comp_sxf.ToString("0.00");
        }
        else
        {
            payModel.vdef5 = sxf.ToString("0.00");//支付手续费
        }
        payid = new Hi.BLL.PAY_Payment().Add(payModel);

        //插入日志表
        Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
        regModel.OrderId    = OrderModel.ID;
        regModel.Ordercode  = orderNo;// orderNo + payid.ToString();
        regModel.number     = payModel.guid;
        regModel.Price      = payPrice;
        regModel.Payuse     = "订单支付";
        regModel.PayName    = disModel.DisName;
        regModel.DisID      = OrderModel.DisID;
        regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
        regModel.Remark     = OrderModel.Remark;
        regModel.DisName    = new Hi.BLL.BD_Company().GetModel(OrderModel.CompID).CompName;
        regModel.BankID     = paytype;
        regModel.CreateUser = OrderModel.CreateUserID;
        regModel.CreateDate = DateTime.Now;
        regModel.LogType    = 1401;
        regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);
        if (payid <= 0 || regid <= 0)
        {
            return(new string[] { "false", "数据有误" });
        }
        string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
        try
        {
            PaymentEnvironment.Initialize(configPath);
        }
        catch (Exception ex)
        {
            return(new string[] { "false", "支付配置有误,请联系系统管理员" });
        }

        String institutionID = WebConfigurationManager.AppSettings["PayOrgCode"];//机构代码

        string    GoodsName = string.Empty;
        DataTable l         = new Hi.BLL.DIS_OrderDetail().GetOrderDe("", " IsNUll(o.dr,0)=0 and o.OrderId=" + KeyID);
        foreach (DataRow dr in l.Rows)
        {
            GoodsName += dr["GoodsName"] + ",";
        }
        if (GoodsName.Length > 15)
        {
            GoodsName = GoodsName.Substring(0, 10) + "...";
        }

        // 1.取得参数
        int    paymentWay      = Convert.ToInt32(paytype);
        String expirePeriod    = "5";//默认是五分钟
        String subject         = GoodsName;
        String productID       = KeyID.ToString();
        String goodsTag        = "";
        String remark          = "";
        String notificationURL = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/Distributor/Pay/ReceiveNoticeAlipay.aspx";
        int    limitPay        = 10;

        long amount         = Convert.ToInt64(payPrice * 100);//支付金额(单位:分)
        long discountAmount = 0;

        // 2.创建交易请求对象
        Tx1401Request tx1401Request = new Tx1401Request();
        tx1401Request.setInstitutionID(institutionID);
        tx1401Request.setOrderNo(orderNo);
        tx1401Request.setPaymentNo(payModel.guid);
        tx1401Request.setPaymentWay(paymentWay);
        tx1401Request.setAmount(amount);
        tx1401Request.setExpirePeriod(expirePeriod);
        tx1401Request.setSubject(subject);
        tx1401Request.setDiscountAmount(discountAmount);
        tx1401Request.setProductID(productID);
        tx1401Request.setGoodsTag(goodsTag);
        tx1401Request.setRemark(remark);
        tx1401Request.setNotificationURL(notificationURL);
        tx1401Request.setLimitPay(limitPay);

        // 3.执行报文处理
        tx1401Request.process();

        //2个信息参数
        HttpContext.Current.Items["txCode"] = "1401";
        HttpContext.Current.Items["txName"] = "市场订单聚合支付";

        // 与支付平台进行通讯
        TxMessenger txMessenger = new TxMessenger();
        String[]    respMsg     = txMessenger.send(tx1401Request.getRequestMessage(), tx1401Request.getRequestSignature());// 0:message; 1:signature

        String plaintext = XmlUtil.formatXmlString(Encoding.UTF8.GetString(Convert.FromBase64String(respMsg[0])));

        //Console.WriteLine("[message] = [" + respMsg[0] + "]");
        //Console.WriteLine("[signature] = [" + respMsg[1] + "]");
        //Console.WriteLine("[plaintext] = [" + plaintext + "]");

        Tx1401Response tx1401Response = new Tx1401Response(respMsg[0], respMsg[1]);
        HttpContext.Current.Items["plainText"] = tx1401Response.getResponsePlainText();
        if ("2000".Equals(tx1401Response.getCode()))
        {
            //图片URL
            imageUrl = tx1401Response.getImageUrl();
            //二维码代码
            string codeUrl = tx1401Response.getCodeUrl();
            //处理业务
            fal = true;
        }
        return(new string[] { fal.ToString(), imageUrl, payModel.guid });
    }
Exemple #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SortedDictionary <string, string> sPara = GetRequestPost();

        Common.CatchInfo("调用成功", sPara.ToString());

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

            if (verifyResult)//验证成功
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //请在这里加上商户的业务逻辑程序代码
                //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                //商户订单号
                string out_trade_no = Request.Form["out_trade_no"];

                //支付宝交易号
                string trade_no = Request.Form["trade_no"];

                //交易状态
                string trade_status = Request.Form["trade_status"];

                //买家账号
                string buyer_email = Request.Form["buyer_email"];

                //支付金额
                string price = Request.Form["total_fee"];

                if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")
                {
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //如果有做过处理,不执行商户的业务程序
                    string strWhere2 = string.Empty;
                    if (out_trade_no != "")
                    {
                        strWhere2 += " number = '" + out_trade_no + "'";
                    }
                    Hi.Model.PAY_RegisterLog        regM = new Hi.Model.PAY_RegisterLog();
                    List <Hi.Model.PAY_RegisterLog> regL = new Hi.BLL.PAY_RegisterLog().GetList("", strWhere2, "");
                    if (regL == null || regL.Count <= 0)
                    {
                        //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                        //return;
                        Console.WriteLine("未找到对应的支付记录!");
                    }
                    regM = regL[0];
                    string strWhere = string.Empty;
                    if (out_trade_no != "")
                    {
                        strWhere += " guid = '" + out_trade_no + "'";
                    }
                    strWhere += " and isnull(dr,0)=0";
                    Hi.Model.PAY_Payment        payM = new Hi.Model.PAY_Payment();
                    List <Hi.Model.PAY_Payment> payL = new Hi.BLL.PAY_Payment().GetList("", strWhere, "");
                    if (payL == null || payL.Count <= 0)
                    {
                        //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                        // return;
                        Console.WriteLine("未找到对应的支付记录!");
                    }
                    payM = payL[0];

                    payM.PayDate = DateTime.Now;
                    payM.ts      = DateTime.Now;
                    payM.status  = trade_status == "TRADE_FINISHED" ? 80 : 90;
                    new Hi.BLL.PAY_Payment().Update(payM);
                    regM.Start = trade_status;
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                    if (payM.IsAudit == 1)
                    {
                        Console.WriteLine("该支付记录状态已经修改成功,请不要重复操作!");
                    }

                    //!!!支付成功 !!!
                    decimal prepayPrice = 0;

                    //企业钱包充值
                    Hi.Model.PAY_PrePayment prepayMnew = new Hi.Model.PAY_PrePayment();
                    string strWhere3 = string.Empty;
                    if (out_trade_no != "")
                    {
                        strWhere3 += " ID = " + payM.OrderID;
                    }
                    strWhere3 += " and isnull(dr,0)=0";
                    List <Hi.Model.PAY_PrePayment> plist = new Hi.BLL.PAY_PrePayment().GetList("", strWhere3, "");
                    if (plist.Count > 0)
                    {
                        prepayMnew = plist[0];
                    }

                    //订单
                    Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(payM.OrderID);
                    if (orderModel != null)
                    {
                        string strWhere1 = string.Empty;
                        strWhere1 += " vdef4 = '" + payM.ID + "'";
                        strWhere1 += " and isnull(dr,0)=0";
                        Hi.Model.PAY_PrePayment        prepayM = new Hi.Model.PAY_PrePayment();
                        List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", strWhere1, "");
                        if (prepayL != null && prepayL.Count > 0)
                        {
                            prepayM     = prepayL[0];
                            prepayPrice = prepayM.price * -1;
                        }

                        int           order  = 0;
                        int           prepay = 0;
                        int           pay    = 0;
                        decimal       prices = Convert.ToDecimal(price);
                        SqlConnection con    = new SqlConnection(LocalSqlServer);
                        con.Open();
                        SqlTransaction sqlTrans = con.BeginTransaction();
                        try
                        {
                            order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderModel.ID, payM.PayPrice + prepayPrice - Convert.ToDecimal(payM.vdef5), sqlTrans);
                            pay   = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);


                            if (prepayPrice > 0)
                            {
                                prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                            }
                            else
                            {
                                prepay = 1;
                            }
                            sqlTrans.Commit();
                        }
                        catch
                        {
                            order  = 0;
                            prepay = 0;
                            pay    = 0;
                            sqlTrans.Rollback();
                        }
                        finally
                        {
                            con.Close();
                        }

                        if (order <= 0 || prepay <= 0 || pay <= 0)
                        {
                            Console.WriteLine("支付成功,但修改支付状态失败,请联系系统管理员,勿重复操作!");
                        }

                        try
                        {
                            //new Common().GetWxService("2", orderModel.ID.ToString(), "1");
                            if (orderModel.Otype != 9)
                            {
                                Common.AddIntegral(orderModel.CompID, orderModel.DisID, "1", 1, orderModel.ID, (prepayPrice + prices), "订单支付", "", orderModel.CreateUserID);
                            }
                        }
                        catch { }
                        if (orderModel.Otype == (int)Enums.OType.推送账单)
                        {
                            Common.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "账单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(支付宝支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                        }
                        else
                        {
                            Common.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "订单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(支付宝支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                        }

                        //微信和安卓消息推送
                        try
                        {
                            MsgSend.Jpushdega jpushdega = new MsgSend.Jpushdega(new MsgSend().GetWxService);
                            jpushdega.BeginInvoke("2", orderModel.ID.ToString(), "1", prepayPrice + prices, null, null);
                            //new MsgSend().GetWxService("2", orderModel.ID.ToString(), "1", prepayPrice + prices);
                        }
                        catch { }

                        //Response.Write("success");  //请不要修改或删除
                        //打印页面
                        //Response.Write("支付成功<br />");
                        Response.Write("success");  //请不要修改或删除
                    }//钱包充值
                    else if (prepayMnew != null)
                    {
                        int           prepay = 0;
                        int           pay    = 0;
                        SqlConnection con    = new SqlConnection(LocalSqlServer);
                        con.Open();
                        SqlTransaction sqlTrans = con.BeginTransaction();
                        try
                        {
                            pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayMnew.ID, sqlTrans);
                            sqlTrans.Commit();
                        }
                        catch
                        {
                            pay    = 0;
                            prepay = 0;
                            sqlTrans.Rollback();
                        }
                        finally
                        {
                            con.Close();
                        }
                    }
                    else
                    {
                        //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到该支付订单!", false);
                        //return;

                        Console.WriteLine("未找到该支付记录!");
                    }
                }

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
            else//验证失败
            {
                Response.Write("fail");
            }
        }
        //else
        //{
        //    Response.Write("无通知参数");
        //    Response.Redirect("ErrorPay.aspx?type=2&OrderCode=" + Request.QueryString["out_trade_no"]);
        //}
    }
Exemple #15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int orderid = 0;

        if (!IsPostBack)
        {
            try
            {
                // 1.取得参数
                if (Request.Form["hidOid"] == "")
                {
                    orderid = 0;
                }
                else
                {
                    orderid = Common.DesDecrypt(Request.Form["hidOid"], Common.EncryptKey).ToInt(0);
                    KeyID   = orderid;
                }
                if (!Common.PageDisOperable("Order", orderid, this.DisID))
                {
                    Response.Redirect("../../NoOperable.aspx", true);
                    return;
                }

                decimal txtPayOrder = Convert.ToDecimal(Request.Form["hidPayOrder"]); //本次支付总金额
                decimal price       = Convert.ToDecimal(Request.Form["hidPrice"]);    //使用企业钱包金额
                int     yfk         = Convert.ToInt32(Request.Form["hidIsPre"]);      //是否使用企业钱包  1:是  0:否
                int     isDBPay     = Convert.ToInt32(Request.Form["hidIsDBPay"]);    //是否是担保支付  1:是  0:否
                string  bankid      = Convert.ToString(Request.Form["hidBankNo"]);    //银行编号
                string  AccountType = Request.Form["hidAccountType"];                 //账户类型
                string  payPas      = Convert.ToString(Request.Form["hidPayPas"]);    //预付款密码

                Hi.Model.BD_Distributor disModel = new Hi.BLL.BD_Distributor().GetModel(this.DisID);

                Hi.Model.DIS_Order disOrderMOdel = new Hi.BLL.DIS_Order().GetModel(orderid);

                if (disModel == null)
                {
                    err = true;
                    ErrMessage("数据异常");
                    return;
                }

                decimal sumPrice = new Hi.BLL.PAY_PrePayment().sums(disModel.ID, disOrderMOdel.CompID); //剩余企业钱包
                int     disid    = this.DisID;                                                          //代理商ID
                string  password = disModel.Paypwd;

                if (yfk == 1)
                {
                    if (payPas == null || payPas.Trim().ToString() == "")
                    {
                        err = true;
                        ErrMessage("企业钱包密码不能为空");
                        return;
                    }
                    payPas = payPas.Trim().ToString();
                    if (password == Util.md5("123456"))
                    {
                        err = true;
                        ErrMessage("请先修改企业钱包支付密码");
                        return;
                    }
                    else
                    {
                        if (payPas == "")
                        {
                            //string Josn = "{\"error\":\"1\",\"msg\":\"密码不能为空!\"}";
                            err = true;
                            ErrMessage("密码不能为空");

                            return;
                        }
                    }
                }

                decimal payPrice = 0;
                if (txtPayOrder == 0)
                {
                    err = true;
                    ErrMessage("支付金额不能为0");

                    return;
                }
                if (yfk == 1 && txtPayOrder < price)
                {
                    err = true;
                    ErrMessage("使用企业钱包大于支付金额!");
                    return;
                }
                if (yfk == 1)
                {
                    payPrice = txtPayOrder - price;
                }
                else
                {
                    payPrice = txtPayOrder;
                }
                if (orderid <= 0)
                {
                    //string Josn = "{\"error\":\"1\",\"msg\":\"操作有误!\"}";
                    err = true;
                    ErrMessage("数据有误");

                    return;
                }
                Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(orderid);
                if (orderModel == null)
                {
                    err = true;
                    ErrMessage("数据有误");

                    return;
                }
                if (txtPayOrder > orderModel.AuditAmount + orderModel.OtherAmount - orderModel.PayedAmount)
                {
                    err = true;
                    ErrMessage("支付金额大于未支付金额,不能支付!");
                    return;
                }
                if (!((
                          (orderModel.Otype == (int)Enums.OType.赊销订单 && (orderModel.OState != (int)Enums.OrderState.退回 && orderModel.OState != (int)Enums.OrderState.未提交 && orderModel.OState != (int)Enums.OrderState.待审核) && (orderModel.PayState == (int)Enums.PayState.未支付 || orderModel.PayState == (int)Enums.PayState.部分支付)) ||
                          (orderModel.Otype != (int)Enums.OType.赊销订单 && orderModel.Otype != (int)Enums.OType.推送账单 && (orderModel.OState == (int)Enums.OrderState.已审 || orderModel.OState == (int)Enums.OrderState.已发货 || orderModel.OState == (int)Enums.OrderState.已到货) && (orderModel.PayState == (int)Enums.PayState.未支付 || orderModel.PayState == (int)Enums.PayState.部分支付)) ||
                          (orderModel.Otype == (int)Enums.OType.推送账单 && orderModel.OState == (int)Enums.OrderState.已审 && (orderModel.PayState == (int)Enums.PayState.部分支付 || orderModel.PayState == (int)Enums.PayState.未支付))
                          ) &&
                      orderModel.OState != (int)Enums.OrderState.已作废))
                {
                    if (orderModel.Otype == (int)Enums.OType.推送账单)
                    {
                        err = true;
                        ErrMessage("账单异常,不能支付");
                    }
                    else
                    {
                        err = true;
                        ErrMessage("订单异常,不能支付");
                    }
                    return;
                }

                int prepayid = 0;

                if (yfk == 1 && price > 0)
                {
                    //企业钱包处理
                    if (sumPrice < price)
                    {
                        err = true;
                        ErrMessage("企业钱包余额不足");

                        return;
                    }
                    if (disModel.Paypwd != Util.md5(payPas))
                    {
                        err = true;
                        ErrMessage("支付密码不正确");

                        return;
                    }
                    Hi.Model.PAY_PrePayment prepayModel = new Hi.Model.PAY_PrePayment();
                    prepayModel.CompID     = disOrderMOdel.CompID;
                    prepayModel.DisID      = disModel.ID;
                    prepayModel.OrderID    = orderid;
                    prepayModel.Start      = 2;
                    prepayModel.PreType    = 5;
                    prepayModel.price      = price * -1;
                    prepayModel.Paytime    = DateTime.Now;
                    prepayModel.CreatDate  = DateTime.Now;
                    prepayModel.CrateUser  = this.UserID;
                    prepayModel.AuditState = 2;
                    prepayModel.IsEnabled  = 1;
                    prepayModel.ts         = DateTime.Now;
                    prepayModel.modifyuser = this.UserID;
                    prepayModel.guid       = Common.Number_repeat(Guid.NewGuid().ToString().Replace("-", ""));
                    // prepayModel.vdef1 = "订单支付";
                    prepayid = new Hi.BLL.PAY_PrePayment().Add(prepayModel);
                    int prepay = 0;
                    int order  = 0;
                    if (prepayid > 0 && payPrice == 0)//payPrice(网银支付金额)= 0 ,只用企业钱包支付,修改状态
                    {
                        SqlConnection con = new SqlConnection(LocalSqlServer);
                        con.Open();
                        SqlTransaction sqlTrans = con.BeginTransaction();
                        try
                        {
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayid, sqlTrans);  //修改企业钱包状态
                            order  = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderid, price, sqlTrans); //修改订单状态
                            if (prepay > 0 && order > 0)
                            {
                                sqlTrans.Commit();
                            }
                            else
                            {
                                sqlTrans.Rollback();
                            }
                        }
                        catch
                        {
                            prepay = 0;
                            order  = 0;
                            sqlTrans.Rollback();
                        }
                        finally
                        {
                            con.Close();
                        }
                        if (prepay > 0 && order > 0)
                        {
                            try
                            {
                                if (orderModel.Otype == (int)Enums.OType.推送账单)
                                {
                                    Utils.AddSysBusinessLog(disOrderMOdel.CompID, "Order", orderid.ToString(), "账单支付", "支付:" + price.ToString("0.00") + "元(企业钱包支付)", this.UserID.ToString());
                                }
                                else
                                {
                                    Utils.AddSysBusinessLog(disOrderMOdel.CompID, "Order", orderid.ToString(), "订单支付", "支付:" + price + "元(企业钱包支付)", this.UserID.ToString());
                                }
                                if (orderModel.Otype != 9)
                                {
                                    OrderInfoType.AddIntegral(disOrderMOdel.CompID, disOrderMOdel.DisID, "1", 1, orderid, price, "订单支付", "", this.UserID);
                                }
                                new Common().GetWxService("2", orderid.ToString(), "1", price);
                            }
                            catch (Exception ex) { throw ex; }

                            if (orderModel.Otype == (int)Enums.OType.推送账单)
                            {
                                err = true;//阻止进入网银支付
                                Response.Redirect("PaySuccess.aspx?type=" + Common.DesEncrypt("2", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(orderid.ToString(), Common.EncryptKey) + "&Pid=" + Common.DesEncrypt("0".ToString(), Common.EncryptKey) + "&PPid=" + Common.DesEncrypt(prepayid.ToString(), Common.EncryptKey) + "&IsRef=Y", false);
                            }
                            else
                            {
                                err = true;//阻止进入网银支付
                                Response.Redirect("PaySuccess.aspx?type=" + Common.DesEncrypt("1", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(orderid.ToString(), Common.EncryptKey) + "&Pid=" + Common.DesEncrypt("0".ToString(), Common.EncryptKey) + "&PPid=" + Common.DesEncrypt(prepayid.ToString(), Common.EncryptKey) + "&IsRef=Y", false);
                            }
                            return;
                        }
                        else
                        {
                            err = true;
                            ErrMessage("支付失败");
                            return;
                        }
                    }
                }

                if (payPrice <= 0)
                {
                    err = true;
                    ErrMessage("数据有误");
                    return;
                }


                #region     计算支付手续费 start
                string  sxfsq    = "-1";
                decimal sxf      = 0;
                decimal comp_sxf = 0;//收费方是厂商是,为了不改变支付金额,故声明此变量来记录,厂商手续费。
                // 获取手续费 begin
                string[] Json = Common.GetSxf(disOrderMOdel.CompID, AccountType, bankid, payPrice);

                string strMsg = Json[2].ToString();
                if (!string.IsNullOrEmpty(strMsg))
                {
                    ErrMessage(strMsg);
                    return;
                }
                else
                {
                    sxfsq    = Json[1].ToString();
                    sxf      = Convert.ToDecimal(Json[0]);
                    comp_sxf = Convert.ToDecimal(Json[3]);
                }
                // 获取手续费 end


                //支付总金额(含手续费)
                decimal UNIT = 0.01M;
                payPrice = payPrice + Common.Round(sxf, UNIT);

                #endregion  计算支付手续费 end


                int payid = 0;
                int regid = 0;
                Hi.Model.PAY_Payment payModel = new Hi.Model.PAY_Payment();
                string orderNo = WebConfigurationManager.AppSettings["OrgCode"] + DateTime.Now.ToString("yyyyMMdd");//支付订单号前半部分

                string guid = Guid.NewGuid().ToString().Replace("-", "");
                payModel.OrderID      = orderid;
                payModel.DisID        = this.DisID;
                payModel.Type         = isDBPay;
                payModel.PayUser      = disModel.DisName;
                payModel.PayPrice     = payPrice;
                payModel.IsAudit      = 2;
                payModel.guid         = Common.Number_repeat(guid);
                payModel.vdef3        = "1";
                payModel.vdef4        = orderNo;
                payModel.CreateDate   = DateTime.Now;
                payModel.CreateUserID = this.UserID;
                payModel.ts           = DateTime.Now;
                payModel.modifyuser   = this.UserID;
                //判断账户类型,判断支付渠道,然后赋值
                if (AccountType == "11")
                {
                    if (bankid == "888")
                    {
                        payModel.Channel = "2";
                    }
                    else
                    {
                        payModel.Channel = "3";
                    }
                }//信用卡支付
                else if (AccountType == "13")
                {
                    payModel.Channel = "8";
                }
                else//网银支付
                {
                    payModel.Channel = "4";
                }

                payModel.State = Convert.ToInt32(sxfsq);//手续费收取方

                if (sxfsq.Equals("2"))
                {
                    payModel.vdef5 = comp_sxf.ToString("0.00");
                }
                else
                {
                    payModel.vdef5 = sxf.ToString("0.00");//支付手续费
                }
                payid = new Hi.BLL.PAY_Payment().Add(payModel);
                if (prepayid > 0)
                {
                    Hi.Model.PAY_PrePayment prepayMent = new Hi.BLL.PAY_PrePayment().GetModel(prepayid);
                    prepayMent.vdef4 = payid.ToString();//与企业钱包关联
                    new Hi.BLL.PAY_PrePayment().Update(prepayMent);
                }

                Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
                regModel.OrderId    = orderid;
                regModel.Ordercode  = orderNo;// orderNo + payid.ToString();
                regModel.number     = payModel.guid;
                regModel.Price      = payPrice;
                regModel.Payuse     = "订单支付";
                regModel.PayName    = disModel.DisName;
                regModel.DisID      = disid;
                regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                regModel.Remark     = orderModel.Remark;
                regModel.DisName    = new Hi.BLL.BD_Company().GetModel(disOrderMOdel.CompID).CompName;
                regModel.BankID     = bankid;
                regModel.CreateUser = this.UserID;
                regModel.CreateDate = DateTime.Now;
                regModel.LogType    = 1311;
                regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);
                if (payid <= 0 || regid <= 0)
                {
                    err = true;
                    ErrMessage("数据有误");
                    return;
                }
                string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
                try
                {
                    PaymentEnvironment.Initialize(configPath);
                }
                catch (Exception ex)
                {
                    //string Josn = "{\"error\":\"1\",\"msg\":\"支付配置有误,请联系系统管理员!\"}";
                    err = true;
                    ErrMessage("支付配置有误,请联系系统管理员");

                    return;
                }

                String institutionID = WebConfigurationManager.AppSettings["PayOrgCode"]; //机构代码

                long   amount          = Convert.ToInt64(payPrice * 100);                 //支付金额(单位:分)
                long   fee             = 0;
                String usage           = "支付订单";
                String remark          = "订单支付";
                String notificationURL = "";
                //"http://www.my1818.com/Handler/ReceiveNoticePage.ashx";//Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port +

                if (WebConfigurationManager.AppSettings["PayType"] == "0")
                {
                    notificationURL = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/Handler/ReceiveNoticePage.ashx";
                }
                // notificationURL = "https://www.yibanmed.com/Handler/ReceiveNoticePage.ashx";
                else
                {
                    notificationURL = "https://www.yibanmed.com/Handler/ReceiveNoticePage.ashx";//回调页面地址
                }
                String payees = new Hi.BLL.BD_Company().GetModel(disOrderMOdel.CompID).CompName;

                //判断支付接口
                string Pay_type = WebConfigurationManager.AppSettings["PayType"];
                String bankID   = string.Empty;
                if (Pay_type == "0") //测试接口
                {
                    bankID = "700";  //bankid;//
                }
                else
                {
                    bankID = bankid;//正式接口
                }
                int accountType = Convert.ToInt32(AccountType);

                // 2.创建交易请求对象
                Tx1311Request tx1311Request = new Tx1311Request();
                tx1311Request.setInstitutionID(institutionID);     //机构号码
                tx1311Request.setOrderNo(orderNo);                 //订单号orderNo + payid.ToString()
                tx1311Request.setPaymentNo(payModel.guid);         //支付交易流水号
                tx1311Request.setAmount(amount);                   //支付金额 单位分
                tx1311Request.setFee(fee);                         //支付服务手续费 单位分
                tx1311Request.setPayerID("");                      //付款人注册ID
                tx1311Request.setPayerName("");                    //付款方名称
                tx1311Request.setUsage(usage);                     //资金用途
                tx1311Request.setRemark(remark);                   //备注
                tx1311Request.setNotificationURL(notificationURL); //机构接收支付通知的URL
                tx1311Request.addPayee("");                        //收款方名称

                if (accountType == 13)
                {
                    tx1311Request.setAccountType(11); //付款方帐号类型
                    tx1311Request.setCardType("02");  //银行卡类型(01=借记卡、02=贷记卡)
                }
                else if (accountType == 11)
                {
                    tx1311Request.setAccountType(accountType); //付款方帐号类型
                    tx1311Request.setCardType("01");           //银行卡类型(01=借记卡、02=贷记卡)
                }
                else if (accountType == 12)
                {
                    tx1311Request.setAccountType(accountType); //付款方帐号类型
                }
                tx1311Request.setBankID(bankID);               //付款银行标识


                // 3.执行报文处理
                tx1311Request.process();
                try
                {
                    Hi.Model.PAY_RegisterLog regM = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                    regM.PlanMessage = tx1311Request.getRequestPlainText();
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                }
                catch (Exception ex) { throw ex; }

                //跳转的url地址
                HttpContext.Current.Items["action"] = PaymentEnvironment.PaymentURL;
                //中金返回信息
                HttpContext.Current.Items["message"] = tx1311Request.getRequestMessage();
                //中金签名信息
                HttpContext.Current.Items["signature"] = tx1311Request.getRequestSignature();
            }
            catch (Exception ex)
            {
                err = true;
                ErrMessage(ex.Message);
                return;
            }
            finally
            {
                if (!err)
                {
                    Context.Server.Transfer("DoSubmit.aspx", false);
                }
            }
        }
    }
Exemple #16
0
    public void Tx1372()
    {
        LogManager.LogFielPrefix = "tx1372";
        LogManager.LogPath       = "D:/Tx1372Order_log/";
        LogManager.WriteLog(LogFile.Trace.ToString(), DateTime.Now + "进入Tx372程序\r");
        string    LocalSqlServer = SqlHelper.LocalSqlServer;
        DataTable dt             = new Hi.BLL.PAY_PrePayment().GetDate("guid,id,OrderID", "pay_payment", "  verifystatus=40 and status =10 and IsAudit =2 ");

        foreach (DataRow dr in dt.Rows)
        {
            string number    = Convert.ToString(dr["guid"]);   //支付交易流水号
            int    paymentid = Convert.ToInt32(dr["id"]);      //支付表id
            int    Orderid   = Convert.ToInt32(dr["OrderID"]); //支付表关联ID

            string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
            PaymentEnvironment.Initialize(configPath);
            string institutionID = WebConfigurationManager.AppSettings["PayOrgCode"];//机构号码

            Tx1372Request tx1372 = new Tx1372Request();
            tx1372.setInstitutionID(institutionID);
            tx1372.setPaymentNo(number);
            tx1372.process();
            TxMessenger    txMessenger    = new TxMessenger();
            String[]       respMsg        = txMessenger.send(tx1372.getRequestMessage(), tx1372.getRequestSignature());
            Tx1372Response tx1372Response = new Tx1372Response(respMsg[0], respMsg[1]);
            //接口调用成功
            if ("2000".Equals(tx1372Response.getCode()))
            {
                LogManager.WriteLog(LogFile.Trace.ToString(), "流水号:" + number + "    状态:" + tx1372Response.getStatus() + "\r");
                //支付成功
                if (20 == tx1372Response.getStatus())
                {
                    //支付成功,修改状态
                    //企业钱包修改状态
                    int           order  = 0;
                    int           pay    = 0;
                    int           prepay = 0;
                    SqlConnection con    = new SqlConnection(LocalSqlServer);
                    con.Open();
                    SqlTransaction sqlTrans = con.BeginTransaction();
                    try
                    {
                        Hi.Model.PAY_Payment    paymentmodel    = new Hi.BLL.PAY_Payment().GetModel(paymentid);
                        Hi.Model.DIS_Order      ordermodel      = new Hi.BLL.DIS_Order().GetModel(Orderid);
                        Hi.Model.PAY_PrePayment prepaymentmodel = new Hi.BLL.PAY_PrePayment().GetModel(Orderid);
                        if (ordermodel != null)                                                                                                                                                       //订单支付
                        {
                            order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, Orderid, paymentmodel.PayPrice - Convert.ToDecimal(paymentmodel.vdef5 == "" ? "0" : paymentmodel.vdef5), sqlTrans); //修改订单状态
                            pay   = new Hi.BLL.PAY_Payment().updatePayState(con, paymentid, sqlTrans);                                                                                                //修改支付表状态

                            if (order > 0 && pay > 0)
                            {
                                sqlTrans.Commit();
                            }
                            else
                            {
                                sqlTrans.Rollback();
                            }
                        }
                        else if (prepaymentmodel != null)//预付款充值
                        {
                            pay    = new Hi.BLL.PAY_Payment().updatePayState(con, paymentid, sqlTrans);
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepaymentmodel.ID, sqlTrans);
                            if (pay > 0 && prepay > 0)
                            {
                                sqlTrans.Commit();
                            }
                            else
                            {
                                sqlTrans.Rollback();
                            }
                        }
                    }
                    catch
                    {
                        order = 0;
                        pay   = 0;
                        sqlTrans.Rollback();
                    }
                    finally
                    {
                        con.Close();
                    }
                }
                else if (30 == tx1372Response.getStatus())//支付失败
                {
                    Hi.Model.PAY_Payment payment = new Hi.BLL.PAY_Payment().GetModel(paymentid);
                    payment.status = 30;//支付失败
                    new Hi.BLL.PAY_Payment().Update(payment);

                    LogManager.WriteLog(LogFile.Trace.ToString(), "失败:" + tx1372Response.getStatus() + "\r");
                }
            }
        }
    }
Exemple #17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //this.lblMsg.InnerText = Request["msg"];
        LogManager.LogFielPrefix = "jsnx";
        LogManager.LogPath       = "C:/requestpag/";
        LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "进入回调页面");
        SortedDictionary <string, string> sPara = GetRequestPost();

        try
        {
            if (sPara == null || sPara.Count <= 0)
            {
                Response.Write("无通知参数");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:无通知参数");
                return;
            }
            Notify aliNotify    = new Notify();
            bool   verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
            if (!verifyResult)//验证失败
            {
                Response.Write("fail");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:验证失败");
                return;
            }

            //企业订单号
            string out_trade_no = Common.NoHTML(Request.Form["out_trade_no"]);

            //支付宝交易号
            string trade_no = Common.NoHTML(Request.Form["trade_no"]);

            //交易状态
            string trade_status = Common.NoHTML(Request.Form["trade_status"]);

            decimal prepayPrice = 0;
            string  guid        = "";
            int     orderid     = 0;
            Hi.Model.PAY_RegisterLog        regM = new Hi.Model.PAY_RegisterLog();
            List <Hi.Model.PAY_RegisterLog> regL = new Hi.BLL.PAY_RegisterLog().GetList("", " Ordercode = '" + out_trade_no + "'", "");
            if (regL == null || regL.Count <= 0)
            {
                Response.Write("找不到" + out_trade_no);
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:找不到" + out_trade_no);
                return;
            }
            regM = regL[0];
            try
            {
                regM.Start         = trade_status;
                regM.ResultMessage = trade_no;
                new Hi.BLL.PAY_RegisterLog().Update(regM);
            }
            catch { }
            guid    = regM.number;
            orderid = regM.OrderId;
            Hi.Model.DIS_Order          orderModel = new Hi.BLL.DIS_Order().GetModel(orderid);
            Hi.Model.PAY_Payment        payM       = new Hi.Model.PAY_Payment();
            List <Hi.Model.PAY_Payment> payL       = new Hi.BLL.PAY_Payment().GetList("", " guid = '" + guid + "' ", "");
            if (payL == null || payL.Count <= 0)
            {
                Response.Write("找不到" + out_trade_no);
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:找不到" + out_trade_no);
                return;
            }
            payM = payL[0];
            if (payM.IsAudit == 1)
            {
                Response.Write("success");//请不要修改或删除,输出success后,支付宝将不再发送通知
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\n支付成功\r\n支付订单号:" + out_trade_no);
                return;
            }
            if (trade_status != "TRADE_SUCCESS")
            {
                Response.Write(GetTradeStatusByName(trade_status));
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:" + GetTradeStatusByName(trade_status) + "\r\n支付订单号:" + out_trade_no);
                return;
            }
            Hi.Model.PAY_PrePayment        prepayM = new Hi.Model.PAY_PrePayment();
            List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", " vdef4 = '" + payM.ID + "' ", "");
            if (prepayL != null && prepayL.Count > 0)
            {
                prepayM     = prepayL[0];
                prepayPrice = prepayM.price * -1;
            }

            int           order  = 0;
            int           prepay = 0;
            int           pay    = 0;
            SqlConnection con    = new SqlConnection(LocalSqlServer);
            con.Open();
            SqlTransaction sqlTrans = con.BeginTransaction();
            try
            {
                order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderid, payM.PayPrice + prepayPrice, sqlTrans);
                pay   = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);
                if (prepayPrice > 0)
                {
                    prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                }
                else
                {
                    prepay = 1;
                }
                sqlTrans.Commit();
            }
            catch (Exception ex)
            {
                Response.Write("Error");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:" + ex.Message + "\r\n支付订单号:" + out_trade_no);
                order  = 0;
                prepay = 0;
                pay    = 0;
                sqlTrans.Rollback();
            }
            finally
            {
                con.Close();
            }
            if (order <= 0 || prepay <= 0 || pay <= 0)
            {
                Response.Write("Error");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:支付成功,修改状态失败,等待下次页面通知\r\n支付订单号:" + out_trade_no);
                return;
            }

            try
            {
                new Common().GetWxService("2", orderModel.ID.ToString(), "1");
                if (orderModel.Otype != 9)
                {
                    OrderInfoType.AddIntegral(orderModel.CompID, orderModel.DisID, "1", 1, orderModel.ID, (prepayPrice + payM.PayPrice), "订单支付", "", orderModel.CreateUserID);
                }
            }
            catch { }
            if (orderModel.Otype == (int)Enums.OType.推送账单)
            {
                Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "账单支付", "支付:" + (prepayPrice + payM.PayPrice).ToString("0.00") + "元(支付宝支付)", payM.CreateUserID.ToString());
            }
            else
            {
                Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "订单支付", "支付:" + (prepayPrice + payM.PayPrice).ToString("0.00") + "元(支付宝支付)", payM.CreateUserID.ToString());
            }

            Response.Write("success");  //请不要修改或删除,输出success后,支付宝将不再发送通知
            LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\n支付成功\r\n支付订单号:" + out_trade_no);
            return;
        }
        catch (Exception ex)
        {
            LogManager.LogFielPrefix = "requestpag";
            LogManager.LogPath       = "C:/requestpag/";
            LogManager.WriteLog(LogFile.Error.ToString(), "Error:" + ex.Message + "\r\n");
            Response.Write(ex.Message);
            return;
        }
        finally
        {
            Response.End();
        }
    }
Exemple #18
0
    public void tx1375()
    {
        try
        {
            int hidFastPay = Convert.ToInt32(this.hidFastPay.Value);
            if (hidFastPay > 0)
            {
                string phone = new Hi.BLL.PAY_FastPayMent().GetModel(hidFastPay).phone;
                this.phone.InnerHtml = "(已发送至" + phone.Substring(0, 3) + " **** " + phone.Substring(phone.Length - 4, 4) + ")";
            }
            Hi.Model.PAY_PrePayment prepayM = new Hi.BLL.PAY_PrePayment().GetModel(KeyID);
            decimal price = prepayM.price;

            #region     计算支付手续费 start
            string AccountType = hid_PayType.Value;
            string bankid      = hidBank.Value;

            string  sxfsq = "-1";
            decimal sxf   = 0;
            // 获取手续费 begin
            string[] Json = Common.GetFastPay_sxf(this.CompID, price);

            string strMsg = Json[2].ToString();
            if (!string.IsNullOrEmpty(strMsg))
            {
                Tx1376ErrResult(strMsg);
                return;
            }
            else
            {
                sxfsq = Json[1].ToString();
                sxf   = Convert.ToDecimal(Json[0]);
            }

            //支付总金额(含手续费)
            decimal UNIT = 0.01M;
            price = price + Common.Round(sxf, UNIT);

            #endregion  计算支付手续费 end

            String orderNo = WebConfigurationManager.AppSettings["OrgCode"] + DateTime.Now.ToString("yyyyMMdd");//支付订单号前半部分

            int    payid = 0;
            int    regid = 0;
            string guid  = Guid.NewGuid().ToString().Replace("-", "");
            Hi.Model.PAY_Payment payModel = new Hi.Model.PAY_Payment();
            payModel.OrderID      = KeyID;
            payModel.DisID        = this.DisID;
            payModel.PayUser      = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
            payModel.PayPrice     = price;
            payModel.guid         = Common.Number_repeat(guid);
            payModel.IsAudit      = 2;
            payModel.vdef3        = "2";
            payModel.vdef4        = orderNo;
            payModel.CreateDate   = DateTime.Now;
            payModel.CreateUserID = this.UserID;
            payModel.ts           = DateTime.Now;
            payModel.modifyuser   = this.UserID;

            payModel.Channel   = "1";                    //支付渠道
            payModel.State     = Convert.ToInt32(sxfsq); //手续费收取方
            payModel.vdef5     = sxf.ToString("0.00");   //支付手续费
            payModel.vdef9     = "1";                    //默认支付
            payid              = new Hi.BLL.PAY_Payment().Add(payModel);
            ViewState["payid"] = payid;

            Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
            regModel.OrderId    = KeyID;
            regModel.Ordercode  = WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(KeyID);
            regModel.number     = payModel.guid;
            regModel.Price      = price;
            regModel.Payuse     = prepayM.PreType == 6 ? "转账汇款" : prepayM.PreType == 1 ? "企业钱包充值" : "";
            regModel.PayName    = new Hi.BLL.BD_Distributor().GetModel(this.DisID).DisName;
            regModel.DisID      = this.DisID;
            regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            regModel.Remark     = prepayM.vdef1;
            regModel.DisName    = new Hi.BLL.BD_Company().GetModel(this.CompID).CompName;
            regModel.BankID     = new Hi.BLL.PAY_FastPayMent().GetModel(hidFastPay).BankID.ToString();
            regModel.CreateUser = this.UserID;
            regModel.CreateDate = DateTime.Now;
            regModel.LogType    = 1375;
            regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);

            if (payid <= 0 || regid <= 0)
            {
                //JScript.AlertMsg(this, "数据异常!");
                ClientScript.RegisterStartupScript(this.GetType(), "payTx1375", "<script>$('#lblErr').html('数据异常!');</script>");
                return;
            }

            if (WebConfigurationManager.AppSettings["Paytest_zj"] != "1")
            {
                string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
                try
                {
                    PaymentEnvironment.Initialize(configPath);
                }
                catch
                {
                    throw new Exception("支付配置不正确,请联系管理员!");
                }

                String institutionID = WebConfigurationManager.AppSettings["PayOrgCode"];
                // String orderNo = WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(KeyID);   为了统一清算,作废次方法
                long amount = Convert.ToInt64(price * 100);

                // 2.创建交易请求对象
                Tx1375Request tx1375Request = new Tx1375Request();
                tx1375Request.setInstitutionID(institutionID);
                tx1375Request.setOrderNo(orderNo);
                tx1375Request.setPaymentNo(new Hi.BLL.PAY_Payment().GetModel(payid).guid);
                tx1375Request.setTxSNBinding(WebConfigurationManager.AppSettings["OrgCode"] + Convert.ToString(hidFastPay));
                tx1375Request.setAmount(amount);
                tx1375Request.setRemark("快捷支付发送短信".ToString());

                // 3.执行报文处理
                tx1375Request.process();

                TxMessenger txMessenger = new TxMessenger();
                String[]    respMsg     = txMessenger.send(tx1375Request.getRequestMessage(), tx1375Request.getRequestSignature());

                Tx1375Response tx1375Response = new Tx1375Response(respMsg[0], respMsg[1]);
                try
                {
                    Hi.Model.PAY_RegisterLog regM = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                    regM.PlanMessage   = tx1375Request.getRequestPlainText();
                    regM.Start         = tx1375Response.getCode();
                    regM.ResultMessage = tx1375Response.getMessage();
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                }
                catch { }

                if (!"2000".Equals(tx1375Response.getCode()))
                {
                    //JScript.AlertMsg(this, tx1375Response.getMessage());
                    ClientScript.RegisterStartupScript(this.GetType(), "payTx1375", "<script>$('#lblErr').html('" + tx1375Response.getMessage() + "!');</script>");
                    return;
                }
            }
            else
            {
                try
                {
                    Hi.Model.PAY_RegisterLog regM = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                    regM.PlanMessage   = "";
                    regM.Start         = "2000";
                    regM.ResultMessage = "OK.";
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                }
                catch { }
            }
            ClientScript.RegisterStartupScript(this.GetType(), "pay", "<script>$('.opacity').fadeIn(200);$('.tip').fadeIn(200);$('#paying').hide();$('#txtPhoneNum').show();$('#txtPhoneNum').select();$('#msgtwo').hide();$('#msgone').show();msgTime(120);</script>");
            return;
        }
        catch (Exception ex)
        {
            //JScript.AlertMsg(this, ex.Message);
            ClientScript.RegisterStartupScript(this.GetType(), "payTx1375", "<script>$('#lblErr').html('" + ex.Message + "!');</script>");
            return;
        }
    }