/// <summary>
        /// 功能描述:处理参数
        /// 创建  人:周文卿
        /// 创建时间:2018-11-17
        /// </summary>
        /// <param name="tblSubroutes">路由表</param>
        /// <param name="payparameter">请求参数表</param>
        /// <param name="sing">签名的字段</param>
        /// <param name="orderid">订单号</param>
        /// <param name="url">请求地址</param>
        /// <returns></returns>
        public Dictionary <string, string> HandleParm(List <DDYZ.Ensis.Presistence.DataEntity.newtblSubroute> tblSubroutes, Dictionary <string, string> payparameter, ref string sing, ref string orderid, ref string url)
        {
            //读取参数配置Json 文件
            RuleCommon rule    = new RuleCommon();
            string     getjson = rule.GetJson(strLocalpath);
            JArray     jsonObj = JArray.Parse(getjson);
            string     bco     = "";
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();
            JToken array = new JArray();

            //根据路由表判断 取哪个对象
            for (int i = 0; i < jsonObj.Count; i++)
            {
                //网关编号和支付方式一样
                if (tblSubroutes[0].fldGatewaynumber == jsonObj[i]["fldGatewaynumber"].ToString() && tblSubroutes[0].fldPayType == jsonObj[i]["fldPayType"].ToString())
                {
                    array = jsonObj[i];
                    sing  = jsonObj[i]["sign"].ToString();
                    url   = jsonObj[i]["payurl"].ToString();
                    if (jsonObj[i]["bankCode"] != null)
                    {
                        bco = jsonObj[i]["bankCode"].ToString();
                    }
                }
            }
            JArray childrenarray = new JArray();

            //得到参数列表
            childrenarray = JArray.Parse(array["parameter"].ToString());

            //分别获取Key和value
            foreach (JToken item in childrenarray[0].Children())
            {
                var    JP    = item as JProperty;
                string key   = JP.Name;
                string value = JP.Value.ToString();
                //如果value分别是num time 则为系统分配
                switch (value)
                {
                //自己发往商户的订单号
                case "num":
                    value   = ram();
                    orderid = value;
                    break;

                //自己发往商户的时间
                case "time":
                    value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    break;

                case "time2":
                    value = DateTime.Now.ToString("yyyyMMddHHmmss");
                    break;

                case "userid":
                    value = ramsix();
                    break;

                case "bankCode":
                    RuletblDictionaries ruletblDictionaries = new RuletblDictionaries();
                    value = ruletblDictionaries.ValidateDictionariesCode(bco, payparameter["Bankname"].ToString());
                    break;

                default:
                    if (payparameter.Keys.Contains(value))
                    {
                        value = payparameter[value];
                    }
                    break;
                }
                keyValuePairs.Add(key, value);
            }


            return(keyValuePairs);
        }
Example #2
0
        /// <summary>
        /// 功能描述:判断请求是否合法
        /// 创建  人:周文卿
        /// 创建时间:2018-11-20
        /// </summary>
        /// <param name="payparameter"></param>
        /// <returns></returns>
        public rerurnpram Islegitimate(paysubparameter payparameter)
        {
            try
            {
                Dictionary <object, object> dict2 = new Dictionary <object, object>();
                dict2 = PayBehavior.GetPropertiesboj <paysubparameter>(payparameter);
                rerurnpram rerurnpram = new rerurnpram();

                //日志实体类
                SysLogMsg sysLogMsg = new SysLogMsg();
                string    Retunr    = "";

                //判断是否有null的参数
                rerurnpram = PayBehavior.IsParmNull(dict2);
                if (rerurnpram.message != "" && rerurnpram.message != null)
                {
                    return(rerurnpram);
                }

                //获取IP
                CheckIP checkIP = new CheckIP();
                string  ip      = checkIP.GetIP();

                Dictionary <string, string> dict = new Dictionary <string, string>();
                dict = PayBehavior.GetProperties <paysubparameter>(payparameter);
                //判断金额
                if (!PayBehavior.tryint(payparameter.Amount))
                {
                    rerurnpram.statecode    = "40005";
                    rerurnpram.message      = "金额不正确!";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "金额不正确:{'Amount':" + payparameter.Amount + "}";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);
                }



                int    outint    = 0;
                string SecretKey = "";
                string rateName  = "";

                RuletblAgentPay ruletblAgent = new RuletblAgentPay();

                List <newtblSubroute> subroute = new List <newtblSubroute>();
                subroute = ruletblAgent.IsRuleSub(out outint, payparameter.MerchantId, decimal.Parse(payparameter.Amount), payparameter.OrderID, "117", out SecretKey, out rateName, ip);

                switch (outint)
                {
                case 40001:
                    rerurnpram.statecode    = "40001";
                    rerurnpram.message      = "未开户的商户!";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "未开户的商户:{'Amount':" + payparameter.MerchantId + "}";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);

                case 40008:
                    rerurnpram.statecode    = "40008";
                    rerurnpram.message      = "订单号已存在!";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "订单号已存在!";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);

                case 40003:
                    rerurnpram.statecode    = "40003";
                    rerurnpram.message      = "路由未配置,请联系管理员!";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "路由未配置,请联系管理员!";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);

                case 40009:
                    rerurnpram.statecode    = "40009";
                    rerurnpram.message      = "账户余额不足!";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "账户余额不足!";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);

                case 40011:
                    rerurnpram.statecode    = "40011";
                    rerurnpram.message      = "IP地址受限!";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "IP地址受限:{'IP':" + ip + "}";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);
                }


                #region 判断Key值
                //排序得到一个新的Dictionary
                string newdict = PayBehavior.AsciiDesc(dict);
                newdict += "key=" + SecretKey;
                //加密
                string md5string = PayBehavior.EncryptionMd5(newdict);
                if (md5string != payparameter.Sign)
                {
                    rerurnpram.statecode    = "40002";
                    rerurnpram.message      = "验签失败";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "验签失败:{'mysign':" + md5string + ",'sign':" + payparameter.Sign + "}";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);
                }
                #endregion
                //根据权重 随机出路由信息
                List <newtblSubroute> newList = PayBehavior.GetRandomList(subroute, 1);

                //渠道信息
                RuleCommon common = new RuleCommon();
                DataTable  dt     = common.GetQueryDate("", "tblChannelinformation", "1=1");

                string fldRequestUrl        = "";  //请求地址
                string fldUpstreamSecretKey = "";  //上游分配的KEY值
                string fldType = "";               //支付类型
                string fldUpstreamMerchantID = ""; //上游ID
                string channel = "";               //渠道

                bool fldState = false;             //渠道状态 0是API,1是手工

                decimal outamount = 0;             //外扣金额

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (newList[0].fldPayType == dt.Rows[i]["fldPayType"].ToString() && newList[0].fldGatewaynumber == dt.Rows[i]["fldNum"].ToString())
                    {
                        fldRequestUrl        = dt.Rows[i]["fldRequestUrl"].ToString();
                        fldUpstreamSecretKey = dt.Rows[i]["fldUpstreamSecretKey"].ToString();
                        fldType = dt.Rows[i]["fldType"].ToString();
                        fldUpstreamMerchantID = dt.Rows[i]["fldUpstreamMerchantID"].ToString();
                        channel   = dt.Rows[i]["fldNum"].ToString();
                        fldState  = bool.Parse(dt.Rows[i]["fldState"].ToString());
                        outamount = decimal.Parse(dt.Rows[i]["fldbuckle"].ToString());
                    }
                }

                //判断银行名称是否正确 正确并且换成渠道所需要的银行名称
                RuletblDictionaries ruletblDictionaries = new RuletblDictionaries();
                string bankname = ruletblDictionaries.ValidateDictionaries(fldUpstreamMerchantID, payparameter.Bankname);

                if (bankname == "0")
                {
                    rerurnpram.statecode    = "40010";
                    rerurnpram.message      = "不支持该银行";
                    rerurnpram.data         = "";
                    sysLogMsg.OperationTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    sysLogMsg.MerchantId    = payparameter.MerchantId;
                    sysLogMsg.MethodName    = "LB_PaySub";
                    sysLogMsg.Parameter     = JsonHelper.SerializeObject(payparameter);
                    sysLogMsg.Content       = "不支持该银行:{'bankname':" + payparameter.Bankname + "}";
                    Retunr = LogHelp.logMessage(sysLogMsg);
                    LogHelp.warn(Retunr);
                    return(rerurnpram);
                }

                dict["Bankname"] = bankname;



                string sign    = "";
                string orderid = "";
                string url     = "";
                //处理参数
                Dictionary <string, string> directory = PayBehavior.HandleParm(newList, dict, ref sign, ref orderid, ref url);



                //按照Ascii从小到大排序 得到一个字符串
                string ascdict = PayBehavior.AsciiDesc(directory);



                rerurnpram.message = fldUpstreamSecretKey;
                ascdict            = ascdict + "key=" + fldUpstreamSecretKey;
                //加密后的字符串
                string encstring = "";
                //判断加密方式
                switch (newList[0].fldEncryptionWay)
                {
                case "md5":
                    encstring = PayBehavior.EncryptionMd5(ascdict);
                    break;

                case "shal":
                    encstring = PayBehavior.Sha1Signature(ascdict);
                    break;
                }

                Processingparameter processingparameter = new Processingparameter();

                string por = "";

                #region 根据各个通道 处理请求参数
                switch (newList[0].fldGatewaynumber)
                {
                case "QJ_004":
                    por = processingparameter.ProcessingQJ(directory, fldUpstreamSecretKey, outamount);
                    break;

                case "HT_006":
                    por = processingparameter.ProcessingHT(directory, fldUpstreamSecretKey, "1");
                    break;

                case "Y_007":
                    por = processingparameter.ProcessingY(directory, fldUpstreamSecretKey);
                    break;

                case "YD_010":
                    por = processingparameter.ProcessingYDSub(directory, fldUpstreamSecretKey);
                    break;

                case "ZC_008":
                    por = processingparameter.ProcessingZC(directory, fldUpstreamSecretKey);
                    break;

                case "HF_011":
                    por = processingparameter.ProcessingHFSub(directory, fldUpstreamSecretKey);
                    break;

                default:
                    directory.Add(sign, encstring);
                    por = processingparameter.Processing(directory);
                    break;
                }

                #endregion

                RulePayRequest rulePayRequest = new RulePayRequest();

                string fldPayState = "";

                //请求代付 如果是手工代付 不请求  直接插入 1是手工 0是自动
                if (!fldState)
                {
                    //请求
                    switch (newList[0].fldGatewaynumber)
                    {
                    case "QJ_004":
                        rerurnpram.message = rulePayRequest.PostUrl(fldRequestUrl, por, channel, fldUpstreamSecretKey, orderid);
                        break;

                    case "Y_007":
                    case "HT_006":
                    case "YD_010":
                    case "ZC_008":
                    case "HF_011":
                        rerurnpram.message = rulePayRequest.HttpPostZF(fldRequestUrl, por, channel, fldUpstreamSecretKey, orderid);
                        break;
                    }

                    fldPayState = "处理中";
                }
                else
                {
                    fldPayState        = "待提交";
                    rerurnpram.message = "ok";
                }



                //支付状态

                if (rerurnpram.message == "ok")
                {
                    rerurnpram.data      = "S";
                    rerurnpram.statecode = "200";
                    rerurnpram.message   = "请求成功";

                    DDYZ.Ensis.Presistence.DataEntity.tblAgentPay agentPay = new DDYZ.Ensis.Presistence.DataEntity.tblAgentPay();
                    agentPay.fldAutoID           = 0;
                    agentPay.fldCreateTime       = DateTime.Now;
                    agentPay.fldtransactionnum   = PayBehavior.ram(1000000000);
                    agentPay.fldChannelnum       = orderid;
                    agentPay.fldOrdernum         = payparameter.OrderID;
                    agentPay.fldMerchID          = payparameter.MerchantId;
                    agentPay.fldPayAmount        = decimal.Parse(payparameter.Amount);
                    agentPay.fldPayState         = fldPayState;
                    agentPay.fldServiceCharge    = decimal.Parse(rateName);
                    agentPay.fldActualAmount     = decimal.Parse(payparameter.Amount);
                    agentPay.fldAccountname      = payparameter.Username;
                    agentPay.fldBankCardId       = payparameter.Bankaccount;
                    agentPay.fldBankName         = payparameter.Bankname;
                    agentPay.fldChannelID        = fldUpstreamMerchantID;
                    agentPay.fldLaunchIP         = ip;
                    agentPay.fldNotice           = "未通知";
                    agentPay.fldchangstautetime  = DateTime.Now;
                    agentPay.fldtransactiontime  = DateTime.Now;
                    agentPay.fldRtefundAmount    = decimal.Parse(payparameter.Amount) + outamount;
                    agentPay.fldBankType         = "支行";
                    agentPay.fldSettlementAmount = 0;
                    agentPay.fldBankbranch       = payparameter.Bankbranch;
                    agentPay.fldBankprovince     = payparameter.Bankprovince;
                    agentPay.fldBankcity         = payparameter.Bankcity;
                    agentPay.fldIdCard           = "425648499545154614";
                    agentPay.fldBankTelephoneNo  = "18997445161";
                    agentPay.fldCardType         = "01";
                    RuletblAgentPay ruletblAgentPay = new RuletblAgentPay();
                    DataTable       k = ruletblAgentPay.InserttblAgentPayUptblAcc(agentPay);
                    if (k.Rows.Count > 0)
                    {
                        rerurnpram.statecode = "50000";
                        rerurnpram.message   = "服务器出现错误,请联系管理员!";
                        return(rerurnpram);
                    }
                }
                else
                {
                    rerurnpram.data      = "F";
                    rerurnpram.statecode = "500";
                    rerurnpram.message   = "请求失败";
                }
                return(rerurnpram);
            }
            catch (Exception e)
            {
                throw new InsertException(e.Message, "RulePayMethod", "Islegitimate", payparameter.ToString());
            }
        }