Example #1
0
        /// <summary>
        /// 查询代付信息
        /// </summary>
        /// <param name="payparamter"></param>
        /// <returns></returns>
        public bool SubmitSelectChinaPay(SelectChinaPayParameter payparamter)
        {
            bool flag = false;

            JMP.BLL.jmp_BankPlaymoney bll = new JMP.BLL.jmp_BankPlaymoney();
            try
            {
                string respStr = ChinaPayForAnother.SelectChinaPay(payparamter.merDate, payparamter.merSeqId, payparamter.PrivateKey, payparamter.merId);

                if (!string.IsNullOrEmpty(respStr))
                {
                    //截取数据验签
                    string responseCode = respStr.Substring(0, 3);

                    int    dex        = respStr.LastIndexOf("|");      // dex为chkValue的索引位置
                    string plain      = respStr.Substring(0, dex + 1); //获取待验签的字符串
                    string cpChkValue = respStr.Substring(dex + 1);    //获取ChinaPay 返回的签名值

                    //验签方法
                    string result = Utils.checkData(plain, cpChkValue, payparamter.p_PublicKey);//验签

                    if (result != "0")
                    {
                        flag = false;

                        Logger.PayForAnotherLog("单笔查询接口验签失败", "交易流水号:" + payparamter.merSeqId + "返回参数:" + respStr);
                    }
                    else
                    {
                        #region 验签成功
                        switch (responseCode)
                        {
                        //成功
                        case "000":

                            string[] s = plain.Split('|');

                            int start = ChinaPayForAnother.VerificationStatCX(s[14]);

                            switch (start)
                            {
                            case 1:

                                //修改银行打款对接表相关信息
                                flag = bll.UpdateBankPayTradeno(1, payparamter.merSeqId, s[5]);
                                if (!flag)
                                {
                                    Logger.PayForAnotherLog("修改银行打款对接表状态失败", "交易流水号:" + payparamter.merSeqId + "交易状态:" + 1 + "代付返回参数:" + respStr);
                                }

                                break;

                            case 2:

                                //修改银行打款对接表相关信息
                                flag = bll.UpdateBankPayTradeno(2, payparamter.merSeqId, "");

                                if (!flag)
                                {
                                    Logger.PayForAnotherLog("修改银行打款对接表状态失败", "交易流水号:" + payparamter.merSeqId + "交易状态:" + 2 + "代付返回参数:" + respStr);
                                }

                                break;

                            case -1:

                                //修改银行打款对接表相关信息
                                flag = bll.UpdateBankPayTradeno(-1, payparamter.merSeqId, "");
                                if (!flag)
                                {
                                    Logger.PayForAnotherLog("修改银行打款对接表状态失败", "交易流水号:" + payparamter.merSeqId + "交易状态:" + -1 + "代付返回参数:" + respStr);
                                }

                                Logger.PayForAnotherLog("代付提现失败返回参数", "交易流水号:" + payparamter.merSeqId + "代付返回参数:" + respStr);

                                break;
                            }

                            break;

                        //无记录(交易失败)
                        case "001":

                            //修改银行打款对接表相关信息
                            flag = bll.UpdateBankPayTradeno(-1, payparamter.merSeqId, "");

                            Logger.PayForAnotherLog("单笔查询接口查询无记录", "交易流水号:" + payparamter.merSeqId + "返回参数:" + respStr);

                            if (!flag)
                            {
                                Logger.PayForAnotherLog("单笔查询接口查询无记录", "交易流水号:" + payparamter.merSeqId + "交易状态:" + -1 + "返回参数:" + respStr);
                            }

                            break;

                        //查询出错
                        case "002":

                            Logger.PayForAnotherLog("单笔查询接口查询出错", "交易流水号:" + payparamter.merSeqId + "返回参数:" + respStr);
                            break;
                        }
                        #endregion
                    }
                }
                else
                {
                    //修改银行打款对接表相关信息
                    flag = bll.UpdateBankPayTradeno(3, payparamter.merSeqId, "");
                    if (!flag)
                    {
                        Logger.PayForAnotherLog("修改银行打款对接表状态失败", "交易流水号:" + payparamter.merSeqId + "交易状态:" + 3 + "代付返回参数:" + respStr);
                    }

                    Logger.PayForAnotherLog("查询接口返回数据为空!!!", "交易流水号:" + payparamter.merSeqId + "交易状态:" + 3 + "代付返回参数:" + respStr);
                }
            }
            catch (Exception ex)
            {
                //修改银行打款对接表相关信息
                flag = bll.UpdateBankPayTradeno(3, payparamter.merSeqId, "");
                if (!flag)
                {
                    Logger.PayForAnotherLog("修改银行打款对接表状态失败", "交易流水号:" + payparamter.merSeqId + "交易状态:" + 3);
                }

                Logger.PayForAnotherLog("代付查询接口异常", "异常信息:" + ex.Message);
                throw;
            }

            return(flag);
        }
Example #2
0
        public bool SubmitChinaPay(HandelPay handelPay)
        {
            bool flag = false;

            JMP.BLL.jmp_userbank      userBankBll  = new jmp_userbank();
            JMP.MDL.jmp_userbank      userBankMode = new JMP.MDL.jmp_userbank();
            JMP.BLL.jmp_BankPlaymoney bll          = new JMP.BLL.jmp_BankPlaymoney();

            Random r = new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0));

            //商户流水号
            string merSeqId = DateTime.Now.ToString("yyMMddHHmmss") + r.Next(1111, 9999).ToString();

            //查询提现银行卡信息
            userBankMode = userBankBll.SelectUserBank_Paymoney(handelPay.batchnumber);
            //金额分
            string money = Math.Floor(userBankMode.b_money * 100).ToString();
            //用途备注
            string purpose = "商户提款";

            //备注
            string remark = "操作人:" + UserInfo.UserName + ",于时间:" + DateTime.Now + ",对批次号:" + handelPay.batchnumber + ",进行代付自动打款,";

            //修改交易编号
            flag = bll.UpdateBankPayNumber(handelPay.batchnumber, merSeqId, 2, remark);

            if (flag)
            {
                ChinaPayParameter payParameter = new ChinaPayParameter
                {
                    merId      = handelPay.MerchantNumber,
                    merSeqId   = merSeqId,
                    cardNo     = userBankMode.u_banknumber,
                    usrName    = userBankMode.u_name,
                    transAmt   = money,
                    prov       = userBankMode.u_province,
                    city       = userBankMode.u_area,
                    openBank   = userBankMode.u_bankname,
                    subBank    = userBankMode.u_openbankname,
                    purpose    = purpose,
                    priKeyPath = handelPay.PrivateKey,
                    flags      = userBankMode.u_flag
                };
                //调用代付
                string respStr = ChinaPayForAnother.ChinaPay(payParameter);

                if (!string.IsNullOrEmpty(respStr))
                {
                    #region 代付有返回信息时

                    //转换成键值集合
                    System.Collections.Specialized.NameValueCollection nvclist = HttpUtility.ParseQueryString(respStr);

                    if (nvclist.Count > 0)
                    {
                        //验签方法
                        if (ChinaPayForAnother.VerificationSign(nvclist, handelPay.PublicKey))
                        {
                            #region

                            //验证请求应答码
                            if (ChinaPayForAnother.VerificationResponseCode(nvclist))
                            {
                                int state = ChinaPayForAnother.VerificationStat(nvclist, respStr);

                                #region 交易状态码(1:交易成功,-1:交易失败,2:处理中)

                                switch (state)
                                {
                                case 1:

                                    //获取ChinaPay系统内部流水
                                    string cpSeqId = ChinaPayForAnother.VerificationCpSeqId(nvclist, respStr);
                                    //修改银行打款对接表相关信息
                                    flag = bll.UpdateBankPayHD(handelPay.batchnumber, 1, merSeqId, cpSeqId, DateTime.Now);
                                    if (!flag)
                                    {
                                        Logger.PayForAnotherLog("修改银行打款对接表状态失败", "批次号:" + handelPay.batchnumber + "交易状态:" + 1 + "代付返回参数:" + respStr);
                                    }
                                    break;

                                case 2:

                                    //修改银行打款对接表相关信息
                                    flag = bll.UpdateBankPayHD(handelPay.batchnumber, 2, merSeqId, "", DateTime.Now);

                                    if (!flag)
                                    {
                                        Logger.PayForAnotherLog("修改银行打款对接表状态失败", "批次号:" + handelPay.batchnumber + "交易状态:" + 2 + "代付返回参数:" + respStr);
                                    }
                                    break;

                                case -1:
                                    //修改银行打款对接表相关信息
                                    flag = bll.UpdateBankPayHD(handelPay.batchnumber, -1, merSeqId, "", DateTime.Now);
                                    if (!flag)
                                    {
                                        Logger.PayForAnotherLog("修改银行打款对接表状态失败", "批次号:" + handelPay.batchnumber + "交易状态:" + -1 + "代付返回参数:" + respStr);
                                    }
                                    Logger.PayForAnotherLog("代付提现失败返回参数", "批次号:" + handelPay.batchnumber + "代付返回参数:" + respStr);

                                    break;
                                }

                                #endregion
                            }
                            else
                            {
                                //响应码不为0000时,记录失败日志
                                flag = bll.UpdateBankPayHD(handelPay.batchnumber, -1, merSeqId, "", DateTime.Now);
                                if (!flag)
                                {
                                    Logger.PayForAnotherLog("修改银行打款对接表状态失败", "批次号:" + handelPay.batchnumber + "交易状态:" + 2 + "代付返回参数:" + respStr);
                                }

                                Logger.PayForAnotherLog("代付提现失败返回参数", "批次号:" + handelPay.batchnumber + "代付返回参数:" + respStr);
                            }
                            #endregion
                        }
                        else
                        {
                            //修改银行打款对接表相关信息
                            flag = bll.UpdateBankPayHD(handelPay.batchnumber, -1, merSeqId, "", DateTime.Now);

                            Logger.PayForAnotherLog("代付提现回传参数验证签名失败", "批次号:" + handelPay.batchnumber + "代付返回参数:" + respStr);

                            if (!flag)
                            {
                                Logger.PayForAnotherLog("修改银行打款对接表状态失败", "批次号:" + handelPay.batchnumber + "交易状态:" + -1 + "代付返回参数:" + respStr);
                            }
                        }
                    }
                    else
                    {
                        //修改银行打款对接表相关信息
                        flag = bll.UpdateBankPayHD(handelPay.batchnumber, 3, merSeqId, "", DateTime.Now);

                        if (!flag)
                        {
                            Logger.PayForAnotherLog("修改银行打款对接表状态失败", "批次号:" + handelPay.batchnumber + "交易状态:" + -1 + "代付返回参数:" + respStr);
                        }

                        Logger.PayForAnotherLog("代付返回参数转换键值集合出错", "批次号:" + handelPay.batchnumber + "代付返回参数:" + respStr);
                    }

                    #endregion
                }
                else
                {
                    #region 代付异常时调用一次查询接口

                    SelectChinaPayParameter PayParameter = new SelectChinaPayParameter
                    {
                        merSeqId    = merSeqId,
                        merDate     = DateTime.Now.ToString("yyyyMMdd"),
                        pid         = 0,
                        p_PublicKey = handelPay.PublicKey,
                        merId       = handelPay.MerchantNumber,
                        PrivateKey  = handelPay.PrivateKey
                    };
                    SelectChinaPay ChinaPay = new SelectChinaPay();

                    flag = ChinaPay.SubmitSelectChinaPay(PayParameter);

                    #endregion
                }
            }
            else
            {
                Logger.PayForAnotherLog("修改[jmp_BankPlaymoney]表交易编号失败(重复提交也会报这个错误)", "批次号:" + handelPay.batchnumber + "交易编号:" + merSeqId);
            }
            return(flag);
        }