C# 请求外部服务的办法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Models;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Text;
using System.Data.Entity.Validation;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Net;
using System.Text.RegularExpressions;
using jmail;
using Security;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Runtime.Serialization.Json;

/// <summary>
/// P2PScore 的摘要说明
/// </summary>
public class P2PScore : SessionGlobal
{
    
        string returnMenu = "调用失败";

        CHKEntities chkEt = new CHKEntities();
        CSTEntities cstEt = new CSTEntities();
        SYSEntities sysEt = new SYSEntities();
        string appKey = System.Configuration.ConfigurationManager.AppSettings["appKey"] != null ? System.Configuration.ConfigurationManager.AppSettings["appKey"].Trim() : "";
        string uuid = System.Configuration.ConfigurationManager.AppSettings["uuId"] != null ? System.Configuration.ConfigurationManager.AppSettings["uuId"].Trim() : "";             //机构注册生成唯一标识码。
        string version = System.Configuration.ConfigurationManager.AppSettings["version"] != null ? System.Configuration.ConfigurationManager.AppSettings["version"].Trim() : "";//默认值 “1.0”
        #region 传入字段
        string phoneCode = "";  //手机设备码
        string phoneCodeType = "";//手机设备码类型
        string platform = "";  //手机系统
        string addressHome = "";  //家庭地址(详细)
        string addressCompany = "";   //公司地址(详细)
        string companyTel = "";
        string mobile = "";
        string month = "";                //贷款期限
        string realName = "";         //用户姓名或者机构编码
        string businessNumber = "";         //贷款编号
        string clientNumber = "";         //客户编号
        string idenCard = "";         //身份标识码( 可传输身份证后四位)。
        string gender = "";               //性别(1,男;2,女)
        string yearBorn = "";          //出生年份(YYYY-MM-DD)
        string house_hold_city = "";  //户籍所在地
        string localLive = "";            //本地居住时间(单位:年)
        string marriage = "";             //婚姻状态(1未婚;2已婚;3离异/丧偶/其他)
        string children = "";             //子女状态(1 无子女 2 有子女)
        string education = "";            //教育程度(1技校/中专/高中及以下;2大专;3本科;4硕士及以上) 
        string ssFund = "";               //社保状态(1-有 2-无) 
        string companyType = "";          //公司类型1、政府非企业类(政府机构/事业单位);2,国企央企;3,三资企业(台企、港企、外企);4,内资上市;5,内资非上市(民营/私营/普通);6,个体工商户;7,其他
        string industry = "";             //公司行业(1,批发/零售;2,制造业;3,金融/保险/证券;4,住宿/餐饮/旅游;5,商业服务/娱乐/艺术/体育;6,计算机/互联网;7,通信/电子;8,建筑/房地产;9,法律/咨询;10,卫生/教育/社会服务;11,国家机关/公共事业/科研/社会团体;12,生物/制药;13,广告/媒体;14,能源;15,贸易;16,交通运输/仓储/邮政/物流;17,农/林/牧/渔;18,其他)
        string creditCard = "";           //信用卡(1、有信用卡;2、无信用卡)
        string firstCardTime = "";     //首次信用卡开卡时间YYYY-MM-DD
        string totalLimit = "";           //信用卡总额度【xxx】元
        string cardOverdueCount = "";       //信用卡逾期次数单位 【xxx】次
        string cardOverdueDays = "";     //信用卡最长逾期天数
        string cardDebt = "";             // 信用卡负债 1、有信用卡负债2、无信用卡负债
        string isHasHouse = "";          //贷款本人名下房产(1-有2-无)
        string isDebtHouse = "";         //房贷-1-有房贷、2-无房贷
        string monthlyPayHouse = "";      //房贷月供【xxx】元
        string isHasCar = "";            //贷款本人名下车产1-有车产2-无车产
        string isDebtCar = "";            //车贷1-有车贷2-无车贷
        string monthlyPayCar = "";        //车贷月供【xxx】元
        string otherLoanMoneyTotal = "";  //其他贷款总额【xxx】元
        string otherLoanReturn = "";      //其他贷款月供【xxx】元
        string MD5 = "";              //根据报文体内容1到59字段累加做MD5加密。


        #region 个人
        string work_city = "";        //工作城市  单位地址
        string currentOnboardTime = "";//本单位入职时间: YYYY-MM-DD   进入现公司时间
        string money = "";          //申请额度
        string salary = "";              //单位 元/月 ,实际到手工资 
        string salaryType = "";           //工资发放类型(1,每月打卡/转账工资;2,现金工
        #endregion

        #region 企业
        string role = "";                 //公司所处角色1-法人2-股东
        string monthlyPrivateLiquid = "";     //公司月均对私流水【xx】元/月
        string monthlyPublicLiquid = "";   //公司月均对公流水【xx】元/月
        string companySize = "";          //公司规模【xx】人
        string companyAddressOperat_city = "";    //公司经营所在城市
        string companyAddress_city = "";          //公司注册地城市
        string registTime = "";                   //公司注册时间YYYY-MM-DD
        string businessLicense = "";              //公司营业执照1-有、2-无
        string creditCardCount = "";              //信用卡所属银行个数:如:3(个)
        string cardDebtMount = "";                //信用卡负债多少:如:[XX](元)
        string consultLoan = "";                  //有无咨询其他机构1.有2.无
        #endregion
        #region 违约需要字段
        string isOpen = "";   //公开程度
        string isNative = "";
        string liveCase = "";
        string liveJoin = "";  //共同居住者
        string compAddresProvince = "";
        string compJoinDate = "";
        string yearIncome = "";  //年收入
        string borrowType = "";
        string car = "";
        string house = "";
        string isCredit = ""//是否有信用报告
        string creditLimit = "";//信用卡最高额度
        string creditCardAccount = ""//信用卡账户数
        string sumLoan = "";    //贷款账户数
        string noCancellationAccount = ""//未销户数量
        string overdueLoan = "";     //未结清贷款数
        string overdueCreditCardNum = "";   //发生过 90 天以上逾期的信用卡账户数
        string overdueLoanNum = "";   //发生过 90 天以上 逾期的 贷款账户 数
        string sumOneMonthOverdueCard = "";   //信用卡单月最高逾期总额
        string sumOneMonthOverdueLoan = "";   //贷款单月最高逾期总额
        string longOneMonthCard = "";         //信用卡单月最长逾期月数
        string longOneMonthLoan = "";         //贷款单月最长逾期月数
        string sixMonthAverageLimit = "";     //最近 6 个月平均使用额度
        string sixMonthAverageRepayment = ""//最近 6 个月平均 应还款
        string totalNowMonthRepayCard = "";   //信用卡本 月应还 款汇总
        string totalNowMonthRepayLoan = "";   //贷款本月 应还款 汇总 
        string totalCreditLimit = "";         //授信额度/信用额度汇总
        string totalLoanMoney = "";           //贷款金额 汇总
        string totalUsedLimit = "";           //已使用额 度汇总
        string totalBalance = "";             //本金余额 汇总/贷款余额汇总
        string queryTimesOne = "";            //近一个月 查询次 数
        string cardAmountAvg = "";            //信用卡月均流水
        string maxReturnMoney = "";           //月供金额
        string nowAddressProvince = "";
        string isLegalPerson = "";
        string stockRatio = "";               //所占股份比例
        string palace = "";                   //经营场所
        string regDate = "";                  //公司注册时间
        string staffAmount = "";
        string publicAverage = "";            //企业资金平均流水
        #endregion
        #endregion
        public P2PScore()
    {
        //
        
// TODO: 在此处添加构造函数逻辑
        
//
    }

    /// <summary>
    
/// 调用评分接口公用方法返回评分结果
    
/// </summary>
    
/// <param name="lendifId">贷款id</param>
    
/// <param name="cust_id">客户id</param>
    
/// <param name="returnMenuBeizhu">返回值备注内容</param>
    
/// <param name="Scoretype">接口类型,1:申请评分接口,2,反欺诈评分接口3,违约评分接口</param>
    
/// <returns>评分结果</returns>
    public  string GetDockingScore(int lendId, int cust_id, out string returnMenuBeizhu, int Scoretype = 1)
    {
      
        returnMenuBeizhu = "";
        CHK_docking_score_request scorerequest = chkEt.CHK_docking_score_request.Where(a => a.lend_info_id == lendId).OrderByDescending(p => p.score_request_id).FirstOrDefault();
        if (scorerequest.IsNotNull())
        {
            string url = "";
            int jktupe = 0;
            string buffer = "";
            #region 参数赋值
            CST_cust cust = cstEt.CST_cust.Find(cust_id);
            CST_person_info person = cstEt.CST_person_info.Find(cust_id);
            CHK_lend_info lendinfo = chkEt.CHK_lend_info.Find(lendId);
            if (lendinfo != null)
            {
                businessNumber = lendinfo.lend_no ?? "";         //贷款编号
                if (lendinfo.lend_month_math != null)
                    month = Convert.ToInt32(lendinfo.lend_month_math).ToString();
                money = Convert.ToDouble(lendinfo.lend_money ?? 0).ToString("0.00");
                string type = lendinfo.Lend_use??"";
                if (type.Trim() != "")
                {
                    //贷款用途
                    if (type.IndexOf("装修") >= 0)
                        borrowType = "3";
                    else if (type.IndexOf("经营") >= 0)
                        borrowType = "5";
                    else if (type.IndexOf("购车") >= 0)
                        borrowType = "6";
                    else
                        borrowType = "7";
                }
            }
            if (scorerequest.phoneCode != null)
                phoneCode = scorerequest.phoneCode.ToString();
            if (scorerequest.phoneCodeType != null)
                phoneCodeType = scorerequest.phoneCodeType.ToString();
            if (scorerequest.phoneplatform != null)
                platform = scorerequest.phoneplatform.ToString();
            if (scorerequest.companyTel != null)
                companyTel = scorerequest.companyTel.ToString();
            if (person != null)
            {
                if (person.unit_type != null)
                    companyType = person.unit_type.ToString();
                if (person.person_industry != null)
                    industry = P2PTable.Getperson_industryId(person.person_industry ?? "");
                if (person.is_marit != null)
                    marriage = person.is_marit.ToString();
                if (person.person_sex != null)
                    gender = person.person_sex.ToString();
                if (person.brith_date != null)
                    yearBorn = Convert.ToDateTime(person.brith_date).ToString("yyyy-MM-dd");
                if (person.person_edu != null)
                    education = person.person_edu.ToString();
                if (person.clew_mob_tel != null)
                    mobile = person.clew_mob_tel.ToString();
                if (person.unit_time != null)
                {
                    currentOnboardTime = Convert.ToDateTime(person.unit_time).ToString("yyyy-MM-dd");
                }
                if (person.month_base_salary != null)
                    salary = Convert.ToInt32(person.month_base_salary).ToString();//实际到手工资
                if (person.domi_place != null )
                {
                    string domi_place=Convert.ToInt32(person.domi_place).ToString();
                    var ddlinfo=sysEt.SYS_ddl_info.Where(p=>p.item_value==domi_place && p.ddl_type_id==2 && p.item_name=="本地").FirstOrDefault();
                    isNative = ddlinfo !=null"1" : "2"//是否本地户口 1是 2否
                }
                if (person.live_state != null && person.live_state.Trim()!="")
                {
                    string live_state = person.live_state.ToString();//居住状况
                    if(live_state.IndexOf("按揭")>=0)
                    liveCase = "1";
                    else if(live_state.IndexOf("自置")>=0)
                    liveCase = "4";
                     else if(live_state.IndexOf("租房")>=0)
                    liveCase = "5";
                     else if(live_state.IndexOf("亲属楼宇")>=0)
                    liveCase = "6";
                     else if(live_state.IndexOf("集体宿舍")>=0)
                    liveCase = "7";
                   else
                    liveCase = "8";
                }
               
            }
            if (scorerequest.localLive != null)
                localLive = scorerequest.localLive.ToString();
            if (scorerequest.total_credit_card != null)
                totalLimit = scorerequest.total_credit_card.ToString();
            if (scorerequest.late_credit_card != null)
                cardOverdueCount = scorerequest.late_credit_card.ToString();
            if (scorerequest.is_children_state != null)
                children = scorerequest.is_children_state.ToString();
            if (scorerequest.is_social_security != null)
                ssFund = scorerequest.is_social_security.ToString();
            if (scorerequest.wage_payment_type != null)
                salaryType = scorerequest.wage_payment_type.ToString();
            if (scorerequest.is_credit_card != null)
                creditCard = scorerequest.is_credit_card.ToString(); //dt.ToFileTime().ToString();//
            if (scorerequest.first_credit_card != null)
            {
                firstCardTime = Convert.ToDateTime(scorerequest.first_credit_card).ToString("yyyy-MM-dd");
            }
            if (scorerequest.overdue_credit_card != null)
                cardOverdueDays = scorerequest.overdue_credit_card.ToString();
            if (scorerequest.is_credit_card_debt != null)
                cardDebt = scorerequest.is_credit_card_debt.ToString();
            if (scorerequest.is_house_property != null)
                isHasHouse = scorerequest.is_house_property.ToString();
            if (scorerequest.is_mortgage != null)
                isDebtHouse = scorerequest.is_mortgage.ToString();
            if (scorerequest.mortgag_month != null)
                monthlyPayHouse = scorerequest.mortgag_month.ToString();
            if (scorerequest.is_car_production != null)
                isHasCar = scorerequest.is_car_production.ToString();
            if (scorerequest.car_loan != null)
                isDebtCar = scorerequest.car_loan.ToString();
            monthlyPayCar = scorerequest.car_loan_month.ToString();
            if (scorerequest.total_loans != null)
                otherLoanMoneyTotal = scorerequest.total_loans.ToString();
            if (scorerequest.other_loans_month != null)
                otherLoanReturn = scorerequest.other_loans_month.ToString();
            if (scorerequest.is_zxqtdkjg != null)
                consultLoan = scorerequest.is_zxqtdkjg.ToString();
            if (scorerequest.gs_scje != null)
                role = scorerequest.gs_scje.ToString();
            if (scorerequest.gs_yjdgls != null)
                monthlyPublicLiquid = scorerequest.gs_yjdgls.ToString();
            if (scorerequest.gs_yjdsls != null)
                monthlyPrivateLiquid = scorerequest.gs_yjdsls.ToString();
            if (scorerequest.gs_gm != null)
                companySize = scorerequest.gs_gm.ToString();
            companyAddress_city = GetcityName(scorerequest.gs_zcdcscity ?? ""1);//公司地址(取值最后节点)
            house_hold_city = GetcityName(scorerequest.mess_addrcity ?? ""1);//户籍所在地(取值最后节点)
            addressCompany = GetcityName(scorerequest.unit_addrcity ?? ""3);//单位地址(取值全部节点)
            addressHome = GetcityName(scorerequest.mess_addrcity ?? ""3);//户籍所在地(取值全部节点)
            compAddresProvince = GetcityName(scorerequest.unit_addrcity ?? ""2);//单位地址(取值省节点)
            if (addressCompany.Trim() == "")
            {//企业贷时单位地址不为必填项,如果没填值  可取 公司经营地址
                addressCompany = GetcityName(scorerequest.operate_url ?? ""3);//公司经营地址(取值全部节点)
                compAddresProvince = GetcityName(scorerequest.operate_url ?? ""2);//单位地址(取值省节点)
            }
            nowAddressProvince = GetcityName(scorerequest.mess_addrcity ?? ""2);//户籍所在地(取值省节点)
            work_city = GetcityName(scorerequest.unit_addrcity ?? ""1);
            companyAddressOperat_city = GetcityName(Convert.ToString(scorerequest.operate_urlcity ?? ""), 1);
            if (scorerequest.gs_yyzz != null)
                businessLicense = scorerequest.gs_yyzz.ToString();
            if (scorerequest.bank_credit_card != null)
                creditCardCount = scorerequest.bank_credit_card.ToString();
            if (scorerequest.credit_liabilities != null)
                cardDebtMount = scorerequest.credit_liabilities.ToString();
            #region 违约需要字段
            isLegalPerson = role;//是否法人(望洲均为个人申请业务流程无法人)
            compJoinDate = currentOnboardTime;//入职日期
            
             if (scorerequest.is_car_production != null)
               car = scorerequest.is_car_production==2?"0":"1";   //有无车产
            else
               car="-1";
            if (scorerequest.is_house_property != null)
               house = scorerequest.is_house_property==2?"0":"1";   //有无房产
            else
               house="-1";
            if (scorerequest.creditLimit != null)
                creditLimit = scorerequest.creditLimit.ToString();   //信用卡最高额度
            if (scorerequest.gs_gm != null)
                staffAmount = scorerequest.gs_gm.ToString();   //公司规模人
            if (scorerequest.isOpen != null)
                isOpen = scorerequest.isOpen.ToString();   //公开程度
            if (scorerequest.liveJoin != null)
                liveJoin = scorerequest.liveJoin.ToString(); //共同居住者
            if (scorerequest.yearIncome != null)
                yearIncome = scorerequest.yearIncome.ToString(); //年收入
            if (scorerequest.isCredit != null)
                isCredit = scorerequest.isCredit.ToString();//是否有信用报告
            if (scorerequest.creditCardAccount != null)
                creditCardAccount = scorerequest.creditCardAccount.ToString();//信用卡账户数
            if (scorerequest.sumLoan != null)
                sumLoan = scorerequest.sumLoan.ToString();   //贷款账户数
            if (scorerequest.noCancellationAccount != null)
                noCancellationAccount = scorerequest.noCancellationAccount.ToString();//未销户数量
            if (scorerequest.overdueLoan != null)
                overdueLoan = scorerequest.overdueLoan.ToString();    //未结清贷款数
            if (scorerequest.overdueCreditCardNum != null)
                overdueCreditCardNum = scorerequest.overdueCreditCardNum.ToString();  //发生过 90 天以上逾期的信用卡账户数
            if (scorerequest.overdueLoanNum != null)
                overdueLoanNum = scorerequest.overdueLoanNum.ToString();  //发生过 90 天以上 逾期的 贷款账户 数
            if (scorerequest.sumOneMonthOverdueCard != null)
                sumOneMonthOverdueCard = scorerequest.sumOneMonthOverdueCard.ToString();  //信用卡单月最高逾期总额
            if (scorerequest.sumOneMonthOverdueLoan != null)
                sumOneMonthOverdueLoan = scorerequest.sumOneMonthOverdueLoan.ToString();  //贷款单月最高逾期总额
            if (scorerequest.longOneMonthCard != null)
                longOneMonthCard = scorerequest.longOneMonthCard.ToString();        //信用卡单月最长逾期月数
            if (scorerequest.longOneMonthLoan != null)
                longOneMonthLoan = scorerequest.longOneMonthLoan.ToString();        //贷款单月最长逾期月数
            if (scorerequest.sixMonthAverageLimit != null)
                sixMonthAverageLimit = scorerequest.sixMonthAverageLimit.ToString();    //最近 6 个月平均使用额度
            if (scorerequest.sixMonthAverageRepayment != null)
                sixMonthAverageRepayment = scorerequest.sixMonthAverageRepayment.ToString();//最近 6 个月平均 应还款
            if (scorerequest.totalNowMonthRepayCard != null)
                totalNowMonthRepayCard = scorerequest.totalNowMonthRepayCard.ToString();  //信用卡本 月应还 款汇总
            if (scorerequest.totalNowMonthRepayLoan != null)
                totalNowMonthRepayLoan = scorerequest.totalNowMonthRepayLoan.ToString();  //贷款本月 应还款 汇总 
            if (scorerequest.totalCreditLimit != null)
                totalCreditLimit = scorerequest.totalCreditLimit.ToString();        //授信额度/信用额度汇总
            if (scorerequest.totalLoanMoney != null)
                totalLoanMoney = scorerequest.totalLoanMoney.ToString();          //贷款金额 汇总
            if (scorerequest.totalUsedLimit != null)
                totalUsedLimit = scorerequest.totalUsedLimit.ToString();          //已使用额 度汇总
            if (scorerequest.totalBalance != null)
                totalBalance = scorerequest.totalBalance.ToString();            //本金余额 汇总/贷款余额汇总
            if (scorerequest.queryTimesOne != null)
                queryTimesOne = scorerequest.queryTimesOne.ToString();           //近一个月 查询次 数
            if (scorerequest.cardAmountAvg != null)
                cardAmountAvg = scorerequest.cardAmountAvg.ToString();           //信用卡月均流水
            if (scorerequest.maxReturnMoney != null)
                maxReturnMoney = scorerequest.maxReturnMoney.ToString();          //月供金额
            if (scorerequest.stockRatio != null)
                stockRatio = scorerequest.stockRatio.ToString();              //所占股份比例
            if (scorerequest.palace != null)
                palace = scorerequest.palace.ToString();                  //经营场所
            if (scorerequest.regDate != null)
                regDate = scorerequest.regDate.ToString("yyyy-MM-dd");                 //公司注册时间
            if (scorerequest.publicAverage != null)
                publicAverage = scorerequest.publicAverage.ToString();           //企业资金平均流水
            #endregion
            #endregion
            if (scorerequest.lend_biz_name != null)
            {
                if (scorerequest.lend_biz_name.IndexOf("望业贷") > -1 || scorerequest.lend_biz_name.IndexOf("生意贷") > -1)
                    jktupe = 2;
                else if (scorerequest.lend_biz_name.IndexOf("贷易贷") > -1 || scorerequest.lend_biz_name.IndexOf("贷易贷") > -1)
                    jktupe = 1;
            }
            if (cust != null)
            {
                realName = cust.cust_name ?? "";
                idenCard = cust.cret_code ?? "";
                //idenCard = DateTime.Now.ToString("yyyyMMddmmss") + fiverandomno();
                clientNumber = cust.cust_no ?? "";         //客户编号
            }
            JObject jo2 = new JObject();
            switch (Scoretype)
            {
                case 1:
                    #region 申请评分接口
                    if (jktupe != 2)
                    {
                        #region 个人申请评分
                        url = System.Configuration.ConfigurationManager.AppSettings["PersonalIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["PersonalIF"].Trim() : "";
                        //类赋值处理用于序列化
                        jsonPersonclass personclass = jsonGRSQPFBind(appKey, uuid, version, month, realName, businessNumber,clientNumber, idenCard, gender, yearBorn, house_hold_city, localLive, marriage, children, education, ssFund, companyType, industry, creditCard, firstCardTime, totalLimit, cardOverdueCount, cardOverdueDays, cardDebt, isHasHouse, isDebtHouse, monthlyPayHouse, isHasCar, isDebtCar, monthlyPayCar, otherLoanMoneyTotal, otherLoanReturn, work_city, currentOnboardTime, money, salary, salaryType, consultLoan);
                       //类json序列化为string
                        buffer = JsonConvert.SerializeObject(personclass);
                        #endregion
                    }
                    else if (jktupe == 2)
                    {
                        #region 企业申请评分
                        if (companyType.Trim() != "")
                        {
                            if (companyType == "5")
                                companyType = "1";
                            else if (companyType == "6")
                                companyType = "2";
                            else
                                companyType = "3";
                        }
                        CST_relevance_person relevance_person = cstEt.CST_relevance_person.Where(p => p.person_info_id == cust_id).FirstOrDefault();
                        if (relevance_person != null)
                        {
                            if (relevance_person.build_date != null)
                                registTime = Convert.ToDateTime(relevance_person.build_date).ToString("yyyy-MM-dd");
                        }
                        url = System.Configuration.ConfigurationManager.AppSettings["EnterpriseIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["EnterpriseIF"].Trim() : "";
                        //类赋值处理用于序列化
                        Enterprise enterprise = jsonQYSQPFBind(appKey, uuid, version, month, realName, businessNumber, clientNumber, idenCard, gender, yearBorn, house_hold_city, marriage, children, education, ssFund, companyType, industry, creditCard, firstCardTime, totalLimit, cardOverdueCount, cardOverdueDays, cardDebt, isHasHouse, isDebtHouse, monthlyPayHouse, isHasCar, isDebtCar, monthlyPayCar, otherLoanMoneyTotal, otherLoanReturn, money, role, monthlyPrivateLiquid, monthlyPublicLiquid, companySize, companyAddressOperat_city, companyAddress_city, registTime, businessLicense, creditCardCount, cardDebtMount, consultLoan);
                         buffer = JsonConvert.SerializeObject(enterprise);
                        #endregion
                    }
                    // 传参数
                    jo2 = ResponseBind(url, buffer);
                    //保存返回数据并返回结果
                    ScoreReponseSave(lendId, cust_id, ref returnMenuBeizhu, ref returnMenu, chkEt, idenCard, scorerequest, lendinfo, jo2);
                    #endregion
                    break;
                case 2:
                    #region 反欺诈评分接口
                  
                    string linkmanMobile = "";
                    List<jsonNamemobileclass> NamemobileList = new List<jsonNamemobileclass>();
                    var contact = cstEt.CST_urgent_contact.Where(p => p.contact_person != null && p.contact_mobile.Trim() != null && p.contact_mobile.Trim() != "" && p.contact_person.Trim() != "" && p.person_info_id == cust_id).ToList();
                    foreach (CST_urgent_contact contactmodel in contact)
                    {
                        jsonNamemobileclass Namemobileclass = new jsonNamemobileclass();
                        Namemobileclass.name = contactmodel.contact_person;
                        Namemobileclass.mobile = contactmodel.contact_mobile;
                        NamemobileList.Add(Namemobileclass);
                    }
                     linkmanMobile = JsonConvert.SerializeObject(NamemobileList);
                   
                    url = System.Configuration.ConfigurationManager.AppSettings["FqzScoreIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["FqzScoreIF"].Trim() : "";
                      
                //类赋值处理用于序列化
                    jsonFQZclass FQZclass = jsonFQZPFBind(appKey, uuid, version, businessNumber, clientNumber, idenCard, realName, mobile,
                    companyTel, linkmanMobile, phoneCode, phoneCodeType, platform, addressHome, addressCompany);
                     buffer = JsonConvert.SerializeObject(FQZclass);
                    // 传参数
                    jo2 = ResponseBind(url, buffer);
                    //保存返回数据并返回结果
                    QZReponseSave(lendId, cust_id, ref returnMenu, chkEt, idenCard, scorerequest, lendinfo, jo2);
                    #endregion
                    break;
                case 3:
                    #region 违约评分接口
                    if(marriage=="1")
                        marriage ="2";
                    else if (marriage == "2")
                        marriage = "1";
                    else
                        marriage = "3";
                     var ddlinfo=sysEt.SYS_ddl_info.Where(p=>p.item_value==education &&p.ddl_type_id==6).FirstOrDefault();
                   if (ddlinfo != null && ddlinfo.item_name != null)
                   {
                       string item_name = ddlinfo.item_name.ToString();//学历
                       if (item_name.IndexOf("技校/中专/高中及以下") >= 0)
                           education = "4";
                       else if (item_name.IndexOf("") >= 0)
                           education = "1";
                       else if (item_name.IndexOf("") >= 0)
                           education = "2";
                       else if (item_name.IndexOf("") >= 0)
                           education = "3";
                      else
                           education = "4";
                  }
                    if (jktupe == 0)
                    {
                        #region 个人非业主违约接口评分
                        url = System.Configuration.ConfigurationManager.AppSettings["PersonalWyScoreIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["PersonalWyScoreIF"].Trim() : "";

                        //类赋值处理用于序列化
                        jsonPersonWyclass personclass = jsonGRWYPFBind(appKey, uuid, businessNumber, clientNumber, gender, yearBorn,
                             education, marriage, children, isOpen, isNative, liveCase, liveJoin, compAddresProvince, compJoinDate, companyType,
                            yearIncome, borrowType, car, house, isCredit, creditLimit, creditCardAccount, sumLoan, noCancellationAccount,
                            overdueLoan, overdueCreditCardNum, overdueLoanNum, sumOneMonthOverdueCard, sumOneMonthOverdueLoan, longOneMonthCard,
                            longOneMonthLoan, sixMonthAverageLimit, sixMonthAverageRepayment, totalNowMonthRepayCard, totalNowMonthRepayLoan,
                            totalCreditLimit, totalLoanMoney, totalUsedLimit, totalBalance, queryTimesOne, cardAmountAvg, maxReturnMoney, nowAddressProvince,
                            version);
                        buffer = JsonConvert.SerializeObject(personclass);
                        #endregion
                    }
                    else if (jktupe == 1)
                    {
                        #region 个人业主违约接口评分
                        url = System.Configuration.ConfigurationManager.AppSettings["PersonalOwnerWyScoreIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["PersonalOwnerWyScoreIF"].Trim() : "";

                        //类赋值处理用于序列化
                        jsonPersonWyclass personclass = jsonGRWYPFBind(appKey, uuid, businessNumber, clientNumber, gender, yearBorn,
                             education, marriage, children, isOpen, isNative, liveCase, liveJoin, compAddresProvince, compJoinDate, companyType,
                            yearIncome, borrowType, car, house, isCredit, creditLimit, creditCardAccount, sumLoan, noCancellationAccount,
                            overdueLoan, overdueCreditCardNum, overdueLoanNum, sumOneMonthOverdueCard, sumOneMonthOverdueLoan, longOneMonthCard,
                            longOneMonthLoan, sixMonthAverageLimit, sixMonthAverageRepayment, totalNowMonthRepayCard, totalNowMonthRepayLoan,
                            totalCreditLimit, totalLoanMoney, totalUsedLimit, totalBalance, queryTimesOne, cardAmountAvg, maxReturnMoney, nowAddressProvince,
                            version);
                        buffer = JsonConvert.SerializeObject(personclass);
                        #endregion
                    }
                    else if (jktupe == 2)
                    {
                        if (companyType.Trim() != "")
                        {
                            if (companyType == "5")
                                companyType = "1";
                            else if (companyType == "6")
                                companyType = "2";
                            else
                                companyType = "3";
                        }
                        #region 企业主违约接口评分
                        url = System.Configuration.ConfigurationManager.AppSettings["OCWyScoreIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["OCWyScoreIF"].Trim() : "";
                        //类赋值处理用于序列化
                        jsonOCWyclass personclass = jsonQYWYPFBind(appKey, uuid, businessNumber, clientNumber, gender, yearBorn,
                             education, marriage, children, isOpen, isNative, liveCase, liveJoin, compAddresProvince, companyType, isLegalPerson,
                             stockRatio, regDate, palace, staffAmount, publicAverage, monthlyPrivateLiquid,
                            yearIncome, borrowType, car, house, isCredit, creditLimit, creditCardAccount, sumLoan, noCancellationAccount,
                            overdueLoan, overdueCreditCardNum, overdueLoanNum, sumOneMonthOverdueCard, sumOneMonthOverdueLoan, longOneMonthCard,
                            longOneMonthLoan, sixMonthAverageLimit, sixMonthAverageRepayment, totalNowMonthRepayCard, totalNowMonthRepayLoan,
                            totalCreditLimit, totalLoanMoney, totalUsedLimit, totalBalance, queryTimesOne, maxReturnMoney,
                            version);
                        buffer = JsonConvert.SerializeObject(personclass);
                        #endregion
                    }
                    // 传参数
                    jo2 = ResponseBind(url, buffer);
                    //保存返回数据并返回结果
                    WYReponseSave(lendId, cust_id, ref returnMenuBeizhu, ref returnMenu, chkEt, idenCard, "", scorerequest, lendinfo, jo2,0);
                    #endregion
                    break;
            }

        }
        return returnMenu;
    }
    /// <summary>
    
/// 调用反馈接口公用方法返回评分结果
    
/// </summary>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    
/// <param name="lendifId">贷款id</param>
    
/// <param name="cust_id">客户id</param>
    
/// <param name="returnMenuBeizhu">返回值备注内容</param>
    
/// <param name="Scoretype">接口类型,1:申请反馈接口,2,反欺诈反馈接口</param>
    
/// <returns>评分结果</returns>
    public  string GetDockingFankui(int lendId, int cust_id, out string returnMenuBeizhu, string borrowResult, string refuseReason, int Scoretype = 1)
    {

        string feedbackNumber = "";
        returnMenuBeizhu = "";
        CHK_docking_score_request scorerequest = chkEt.CHK_docking_score_request.Where(a => a.lend_info_id == lendId).OrderByDescending(p => p.score_request_id).FirstOrDefault();
        if (scorerequest.IsNotNull())
        {
            string url = "";
            string buffer = "";
            CHK_lend_info lendinfo = chkEt.CHK_lend_info.Find(lendId);
            businessNumber = (lendinfo!=null&&lendinfo.lend_no !=null)?lendinfo.lend_no.ToString():"";         //贷款编号
            JObject jo2 = new JObject();
            switch (Scoretype)
            {
                case 1:
                   #region 申请反馈接口
                    feedbackNumber = chkEt.CHK_docking_score_response.Where(p => p.lend_info_id == lendId).ToList().Count()>0?(chkEt.CHK_docking_score_response.Where(p => p.lend_info_id == lendId).OrderByDescending(p => p.score_response_id).FirstOrDefault().feedbackNumber??""):"";
                    if (feedbackNumber != "")
                    {
                        url = System.Configuration.ConfigurationManager.AppSettings["FeedbackSqpfActionIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["FeedbackSqpfActionIF"].Trim() : "";
                        //类赋值处理用于序列化
                        jsonSQFKclass SQFKclass = jsonSQFKBind(appKey, uuid, version, businessNumber, feedbackNumber, borrowResult, refuseReason);
                        buffer = JsonConvert.SerializeObject(SQFKclass);
                    }
                    else 
                    {
                        int custid = (chkEt.CHK_lend_info.Find(lendId) != null && chkEt.CHK_lend_info.Find(lendId).cust_id!=null)?Convert.ToInt32(chkEt.CHK_lend_info.Find(lendId).cust_id):0;
                        CST_cust cust = cstEt.CST_cust.Find(custid);
                          CHK_docking_score_response response = chkEt.CHK_docking_score_response.Where(p => p.lend_info_id == lendId).OrderByDescending(p => p.score_response_id).FirstOrDefault() ;
                        if (cust != null && response != null)
                        {
                            realName = cust.cust_name ?? "";
                            idenCard = response.idcard_sjNo ?? "";
                        }
                        //老数据处理
                        url = System.Configuration.ConfigurationManager.AppSettings["FeedbackSqpfActionIFold"] != null ? System.Configuration.ConfigurationManager.AppSettings["FeedbackSqpfActionIFold"].Trim() : "";
                        //类赋值处理用于序列化
                        jsonSQFKclassold SQFKclass = jsonSQFKBindold(appKey, uuid, version, realName, idenCard, borrowResult, refuseReason);
                        buffer = JsonConvert.SerializeObject(SQFKclass);
                        feedbackNumber = "老数据";
                    }
                    // 传参数
                    jo2 = ResponseBind(url, buffer);
                    //保存返回数据并返回结果
                    ScoreReponseSave(lendId, cust_id, ref returnMenuBeizhu, ref returnMenu, chkEt, idenCard, scorerequest, lendinfo, jo2,
                        feedbackNumber, borrowResult, refuseReason);
                    #endregion
                    break;
                case 2:
                    #region 反欺诈反馈接口
                    feedbackNumber =  chkEt.CHK_docking_QZ_response.Where(p => p.lend_info_id == lendId).ToList().Count()>0?(chkEt.CHK_docking_QZ_response.Where(p => p.lend_info_id == lendId).OrderByDescending(p => p.qz_response_id).FirstOrDefault().sq_feedbackNumber ?? ""):""
                    string isFraud = borrowResult;
                    string fraudType = refuseReason;
                    url = System.Configuration.ConfigurationManager.AppSettings["FeedbackFqzIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["FeedbackFqzIF"].Trim() : "";
                    //类赋值处理用于序列化
                    jsonFQZFKclass FQZFKclass = jsonFQZFKBind(appKey, uuid, version, businessNumber, feedbackNumber, isFraud, fraudType);
                    buffer = JsonConvert.SerializeObject(FQZFKclass);
                    // 传参数
                    jo2 = ResponseBind(url, buffer);
                    //保存返回数据并返回结果
                    QZReponseSave(lendId, cust_id, ref returnMenu, chkEt, idenCard, scorerequest, lendinfo, jo2, feedbackNumber, isFraud, fraudType);
                    #endregion
                    break;
            }

        }
        return returnMenu;
    }

    /// <summary>
    
/// 调用违约反馈接口公用方法返回评分结果
    
/// </summary>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    
/// <param name="lendifId">贷款id</param>
    
/// <param name="cust_id">客户id</param>
    
/// <param name="returnMenuBeizhu">返回值备注内容</param>
    
/// <param name="Scoretype">接口类型,1:申请反馈接口,2,反欺诈反馈接口</param>
    
/// <returns>评分结果</returns>
    public string GetDockingWYFankui(int plan_id,int lendId, int cust_id, out string returnMenuBeizhu,string businessNumber,string clientNumber,
            string loanPeriods, string loanMoney, string period,
            string monthReturnAmount,string planRepaymentDate,
            string repaymentFunds,
            string repayInterest,
            string repaymentDate,
            string realityReceiveCapital,
            string realityReceiveInterest,
            string interestPenalty,
            string breach,
            string actualTotalAmount,
            string isOverdue,
            string overdueDays,
            string overduePeriod)
    {

        string feedbackNumber = "";
        returnMenuBeizhu = "";
        CHK_docking_score_request scorerequest = chkEt.CHK_docking_score_request.Where(a => a.lend_info_id == lendId).OrderByDescending(p => p.score_request_id).FirstOrDefault();
        if (scorerequest.IsNotNull())
        {
            string url = "";
            string buffer = "";
            CHK_lend_info lendinfo = chkEt.CHK_lend_info.Find(lendId);
            JObject jo2 = new JObject();
            feedbackNumber = chkEt.CHK_docking_WY_response.Where(p => p.lend_info_id == lendId).ToList().Count() > 0 ? (chkEt.CHK_docking_WY_response.Where(p => p.lend_info_id == lendId).OrderByDescending(p => p.wy_response_id).FirstOrDefault().feedbackNumber ?? "") : "";
            #region 违约反馈接口
            url = System.Configuration.ConfigurationManager.AppSettings["FeedbackWyIF"] != null ? System.Configuration.ConfigurationManager.AppSettings["FeedbackWyIF"].Trim() : "";

            //类赋值处理用于序列化
            jsonWYFKclass personclass = jsonGRWYFKBind(appKey, uuid, businessNumber, clientNumber, feedbackNumber, loanPeriods,
                 loanMoney, period, monthReturnAmount, planRepaymentDate, repaymentFunds, repayInterest,
                 repaymentDate, realityReceiveCapital, realityReceiveInterest, interestPenalty, breach,
                 actualTotalAmount, isOverdue, overdueDays, overduePeriod, version);
            buffer = JsonConvert.SerializeObject(personclass);
            // 传参数
            jo2 = ResponseBind(url, buffer);
            //保存返回数据并返回结果
            WYReponseSave(lendId, cust_id, ref returnMenuBeizhu, ref returnMenu, chkEt, idenCard, feedbackNumber, scorerequest, lendinfo, jo2, plan_id);
            #endregion

        }
        return returnMenu;
    }
    /// <summary>
    
/// 传输方法
    
/// </summary>
    
/// <param name="url">接口地址</param>
    
/// <param name="ms">序列化后的数据</param>
    
/// <returns></returns>
    private static JObject ResponseBind(string url,string buffer = "")
    {
        SecurityUtils su = new SecurityUtils();//给值
        IDictionary<stringstring> parameters = new Dictionary<stringstring>();
        parameters.Add("request", buffer);
        string strReturn = su.ReturnActionFromXml(url, parameters);
        JObject jo = (JObject)JsonConvert.DeserializeObject(strReturn);
        string responsestr = jo["response"] != null ? jo["response"].ToString().Trim() : "";//执行结果
        JObject jo2 = (JObject)JsonConvert.DeserializeObject(responsestr);
        return jo2;
    }
    /// <summary>
    
/// 评分历史数据保存并返回结果
    
/// </summary>
    
/// <param name="lendId">贷款id</param>
    
/// <param name="cust_id">客户id</param>
    
/// <param name="returnMenuBeizhu">备注返回内容</param>
    
/// <param name="returnMenu">接口调用结果</param>
    
/// <param name="chkEt"></param>
    
/// <param name="idenCard">随机数唯一流水</param>
    
/// <param name="scorerequest">评分表</param>
    
/// <param name="lendinfo">贷款表</param>
    
/// <param name="jo2">内层json值</param>
    private static void ScoreReponseSave(int lendId, int cust_id, ref string returnMenuBeizhu, ref string returnMenu, CHKEntities chkEt, string idenCard,
        CHK_docking_score_request scorerequest, CHK_lend_info lendinfo, JObject jo2, string feedbackNumber = ""string borrowResult = "",
        string refuseReason = "")
    {
        returnMenuBeizhu = jo2["beizhu"] != null ? jo2["beizhu"].ToString().Trim() : "";
       
            //保存历史记录 
           
            if (feedbackNumber.Trim() == "")
            {
                if (jo2["status"] != null && jo2["status"].ToString().Trim() == "true")
                {
                    #region SQ 申请返回数据保存
                     CHK_docking_score_response scorereponse = new CHK_docking_score_response();
                     scorereponse.score_response_id = P2PUtil.GetMaxTableId("CHK_docking_score_response");
                     scorereponse.score = jo2["score"].ToString().Trim();
                     scorereponse.crate = jo2["crate"].ToString().Trim();
                     scorereponse.hdchance = jo2["hdchance"].ToString().Trim();
                     scorereponse.beizhu = jo2["beizhu"].ToString().Trim();
                     scorereponse.feedbackNumber = jo2["feedbackNumber"].ToString().Trim();
                     scorereponse.status = jo2["status"].ToString().Trim();
                     scorereponse.message = jo2["message"].ToString().Trim();
                     scorereponse.add_date = P2PUtil.GetBizDate(P2PUtil.getOrgId());
                     scorereponse.add_emp_id = (int)P2PUtil.GetSessionEmpInfo().emp_id;
                     scorereponse.lend_biz_name = scorerequest.lend_biz_name ?? "";
                     scorereponse.lend_biz_type = scorerequest.lend_biz_type ?? 0;
                     scorereponse.lend_info_id = lendId;
                     scorereponse.cust_id = cust_id;
                     scorereponse.score_request_id = scorerequest.score_request_id;
                     scorereponse.idcard_sjNo = idenCard;
                     try
                     {
                         chkEt.CHK_docking_score_response.Add(scorereponse);
                         lendinfo.score_response_id = scorereponse.score_response_id;
                         scorerequest.idcard_sjNo = scorereponse.idcard_sjNo;
                         chkEt.SaveChanges();
                         returnMenu = "调用成功";
                     }
                     catch (HttpRequestValidationException ex)
                     {
                    
                         throw ex;
                     }
                    #endregion
                }
            }
            else
            {
                #region FK 反馈返回数据保存
                CHK_docking_score_response scorereponse = chkEt.CHK_docking_score_response.Where(p => p.lend_info_id == lendId && p.feedbackNumber == feedbackNumber).FirstOrDefault();
                if (feedbackNumber == "老数据" && scorereponse==null)
                    scorereponse = chkEt.CHK_docking_score_response.Where(p => p.lend_info_id == lendId).OrderByDescending(p=>p.score_response_id).FirstOrDefault();
                if (scorereponse != null)
                {
                    scorereponse.fk_status = jo2["status"].ToString().Trim();
                    scorereponse.fk_message = jo2["message"].ToString().Trim();
                    scorereponse.borrowResult = borrowResult.Trim() != "" ? borrowResult : "0";
                    scorereponse.refuseReason = refuseReason;
                    scorereponse.fk_add_date = P2PUtil.GetBizDate(P2PUtil.getOrgId());
                    scorereponse.fk_add_emp_id = (int)P2PUtil.GetSessionEmpInfo().emp_id;
                    try
                    {
                        chkEt.SaveChanges();
                        if (jo2["status"] != null && jo2["status"].ToString().Trim() == "true")
                            returnMenu = "调用成功";
                        else
                            returnMenu = "调用失败";
                    }
                    catch (HttpRequestValidationException ex)
                    {
                        throw ex;
                    }
                }
                else {
                    returnMenu = "调用失败,未添加申请评分,不可反馈";
                }
                #endregion
                
            }
        
    }

    /// <summary>
    
/// 违约历史数据保存并返回结果
    
/// </summary>
    
/// <param name="lendId">贷款id</param>
    
/// <param name="cust_id">客户id</param>
    
/// <param name="returnMenuBeizhu">备注返回内容</param>
    
/// <param name="returnMenu">接口调用结果</param>
    
/// <param name="chkEt"></param>
    
/// <param name="idenCard">随机数唯一流水</param>
    
/// <param name="scorerequest">评分表</param>
    
/// <param name="lendinfo">贷款表</param>
    
/// <param name="jo2">内层json值</param>
    private static void WYReponseSave(int lendId, int cust_id, ref string returnMenuBeizhu, ref string returnMenu, CHKEntities chkEt, string idenCard,
        string feedbackNumber, CHK_docking_score_request scorerequest, CHK_lend_info lendinfo, JObject jo2, int plan_id = 0)
    {
         //保存历史记录 
        if (feedbackNumber.Trim() == "")
        {
           returnMenuBeizhu = jo2["beizhu"] != null ? jo2["beizhu"].ToString().Trim() : "";
            if (jo2["status"] != null && jo2["status"].ToString().Trim() == "true")
            {
                //保存历史记录 
                CHK_docking_WY_response scorereponse = new CHK_docking_WY_response();
                scorereponse.wy_response_id = P2PUtil.GetMaxTableId("CHK_docking_WY_response");
                scorereponse.score = jo2["score"].ToString().Trim();
                scorereponse.crate = jo2["crate"].ToString().Trim();
                scorereponse.wychance = jo2["wychance"].ToString().Trim();
                scorereponse.beizhu = jo2["beizhu"].ToString().Trim();
                scorereponse.sq_status = jo2["status"].ToString().Trim();
                scorereponse.sq_message = jo2["message"].ToString().Trim();
                scorereponse.feedbackNumber = jo2["feedbackNumber"].ToString().Trim();
                scorereponse.sq_add_date = P2PUtil.GetBizDate(P2PUtil.getOrgId());
                scorereponse.sq_add_emp_id = (int)P2PUtil.GetSessionEmpInfo().emp_id;
                scorereponse.lend_biz_name = scorerequest.lend_biz_name ?? "";
                scorereponse.lend_biz_type = scorerequest.lend_biz_type ?? 0;
                scorereponse.lend_info_id = lendId;
                scorereponse.cust_id = cust_id;
                scorereponse.score_request_id = scorerequest.score_request_id;
                scorereponse.wy_companyUid = idenCard;
                try
                {
                    chkEt.CHK_docking_WY_response.Add(scorereponse);
                    lendinfo.wy_response_id = scorereponse.wy_response_id;
                    scorerequest.wy_companyUid = scorereponse.wy_companyUid;
                    chkEt.SaveChanges();
                    returnMenu = "调用成功";
                }
                catch (HttpRequestValidationException ex)
                {

                    throw ex;
                }

            }
        }
        else
        {
            #region FK 反馈返回数据保存
            CHK_docking_WY_response scorereponse = chkEt.CHK_docking_WY_response.Where(p => p.lend_info_id == lendId && p.feedbackNumber == feedbackNumber).FirstOrDefault();
            if (scorereponse != null)
            {
                scorereponse.fk_status = jo2["status"].ToString().Trim();
                scorereponse.fk_message = jo2["message"].ToString().Trim();
                scorereponse.fk_add_date = P2PUtil.GetBizDate(P2PUtil.getOrgId());
                scorereponse.fk_add_emp_id = (int)P2PUtil.GetSessionEmpInfo().emp_id;
                CHK_collect_plan_info plan = chkEt.CHK_collect_plan_info.Find(plan_id);
                if (plan != null && jo2["status"] != null && jo2["status"].ToString().Trim() == "true")
                {
                    plan.fk_status = 1;
                }
                else
                {
                    plan.fk_status = 0;
                }
                try
                {
                    chkEt.SaveChanges();
                    if (jo2["status"] != null && jo2["status"].ToString().Trim() == "true")
                        returnMenu = "调用成功";
                    else
                        returnMenu = "调用失败";
                }
                catch (HttpRequestValidationException ex)
                {
                    throw ex;
                }
            }
            else
            {
                returnMenu = "调用失败,未添加欺诈评分,不可反馈";
            }
            #endregion
        }
    }

    /// <summary>
    
/// 欺诈历史数据保存并返回结果
    
/// </summary>
    
/// <param name="lendId">贷款id</param>
    
/// <param name="cust_id">客户id</param>
    
/// <param name="returnMenuBeizhu">备注返回内容</param>
    
/// <param name="returnMenu">接口调用结果</param>
    
/// <param name="chkEt"></param>
    
/// <param name="idenCard">随机数唯一流水</param>
    
/// <param name="scorerequest">评分表</param>
    
/// <param name="lendinfo">贷款表</param>
    
/// <param name="jo2">内层json值</param>
    private static void QZReponseSave(int lendId, int cust_id, ref string returnMenu, CHKEntities chkEt, string idenCard, CHK_docking_score_request scorerequest,
        CHK_lend_info lendinfo, JObject jo2, string feedbackNumber = ""string isFraud = ""string fraudType = "")
    {
       
            //保存历史记录 
            if (feedbackNumber.Trim() == "")
            {
                if (jo2["status"] != null && (jo2["status"].ToString().Trim() == "success" || jo2["status"].ToString().Trim() == "true"))
                {
                    #region SQ 评分返回数据保存
                     CHK_docking_QZ_response scorereponse = new CHK_docking_QZ_response();
                     scorereponse.qz_response_id = P2PUtil.GetMaxTableId("CHK_docking_QZ_response");
                     scorereponse.totalScore = jo2["totalScore"].ToString().Trim();
                     scorereponse.riskRanking = jo2["riskRanking"].ToString().Trim();
                     scorereponse.finalProposa = jo2["finalProposal"].ToString().Trim();
                     scorereponse.firstProposal = jo2["firstProposal"].ToString().Trim();
                     scorereponse.secondProposal = jo2["secondProposal"].ToString().Trim();
                     scorereponse.thirdProposal = jo2["thirdProposal"].ToString().Trim();
                     scorereponse.sq_status = jo2["status"].ToString().Trim();
                     scorereponse.sq_message = jo2["message"].ToString().Trim();
                     scorereponse.sq_feedbackNumber = jo2["feedbackNumber"].ToString().Trim();
                     scorereponse.sq_add_date = P2PUtil.GetBizDate(P2PUtil.getOrgId());
                     scorereponse.sq_add_emp_id = (int)P2PUtil.GetSessionEmpInfo().emp_id;
                     scorereponse.lend_biz_name = scorerequest.lend_biz_name ?? "";
                     scorereponse.lend_biz_type = scorerequest.lend_biz_type ?? 0;
                     scorereponse.lend_info_id = lendId;
                     scorereponse.cust_id = cust_id;
                     scorereponse.score_request_id = scorerequest.score_request_id;
                     scorereponse.qz_companyUid = idenCard;
                     
                     try
                     {
                         chkEt.CHK_docking_QZ_response.Add(scorereponse);
                         lendinfo.qz_response_id = scorereponse.qz_response_id;
                         scorerequest.qz_companyUid = scorereponse.qz_companyUid;
                         chkEt.SaveChanges();
                         returnMenu = "调用成功";
                     }
                     catch (HttpRequestValidationException ex)
                     {
                     
                         throw ex;
                     }
                    #endregion
                }
            }
            else
            {
                #region FK 反馈返回数据保存
                CHK_docking_QZ_response scorereponse = chkEt.CHK_docking_QZ_response.Where(p => p.lend_info_id == lendId && p.sq_feedbackNumber == feedbackNumber).FirstOrDefault();
                if (scorereponse != null)
                {
                    scorereponse.fk_status = jo2["status"].ToString().Trim();
                    scorereponse.fk_message = jo2["message"].ToString().Trim();
                    scorereponse.isFraud = Convert.ToInt32(isFraud.Trim() != "" ? isFraud : "0");
                    scorereponse.fraudType = Convert.ToInt32(fraudType.Trim() != "" ? fraudType : "0");
                    scorereponse.fk_add_date = P2PUtil.GetBizDate(P2PUtil.getOrgId());
                    scorereponse.fk_add_emp_id = (int)P2PUtil.GetSessionEmpInfo().emp_id;
                   
                    try
                    {
                        chkEt.SaveChanges();
                        if (jo2["status"] != null && jo2["status"].ToString().Trim() == "true")
                            returnMenu = "调用成功";
                        else
                            returnMenu = "调用失败";
                    }
                    catch (HttpRequestValidationException ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    returnMenu = "调用失败,未添加欺诈评分,不可反馈";
                }
                #endregion
            }
    }

  

    #region 个人申请评分类赋值
    private static jsonPersonclass jsonGRSQPFBind(string appKey, string uuid, string version, string month, string realName, string businessNumber, string clientNumber, string idenCard, string gender, string yearBorn, string house_hold_city, string localLive, string marriage, string children, string education, string ssFund, string companyType, string industry, string creditCard, string firstCardTime, string totalLimit, string cardOverdueCount, string cardOverdueDays, string cardDebt, string isHasHouse, string isDebtHouse, string monthlyPayHouse, string isHasCar, string isDebtCar, string monthlyPayCar, string otherLoanMoneyTotal, string otherLoanReturn, string work_city, string currentOnboardTime, string money, string salary, string salaryType, string consultLoan)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(money)
        .Append(businessNumber)
        .Append(clientNumber)
        .Append(month)
        .Append(realName)
        .Append(idenCard)
        .Append(gender)
        .Append(yearBorn)
        .Append(house_hold_city)
        .Append(localLive)
        .Append(marriage)
        .Append(children)
        .Append(education)
        .Append(ssFund)
        .Append(work_city)
        .Append(currentOnboardTime)
        .Append(companyType)
        .Append(industry)
        .Append(salary)
        .Append(salaryType)
        .Append(creditCard)
        .Append(firstCardTime)
        .Append(totalLimit)
        .Append(cardOverdueCount)
        .Append(cardOverdueDays)
        .Append(cardDebt)
        .Append(isHasHouse)
        .Append(isDebtHouse)
        .Append(monthlyPayHouse)
        .Append(isHasCar)
        .Append(isDebtCar)
        .Append(monthlyPayCar)
        .Append(consultLoan)
        .Append(otherLoanMoneyTotal)
        .Append(otherLoanReturn)
        .Append(version)
        .Append(appKey);

        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonPersonclass personclass = new jsonPersonclass();
        personclass.uuid = uuid;
        personclass.money = money;
        if (month.Trim() != "")
            personclass.month = Convert.ToInt32(month);
        personclass.realName = realName;
        personclass.idenCard = idenCard;
        personclass.businessNumber = businessNumber;
        personclass.clientNumber = clientNumber;
        if (gender.Trim() != "")
            personclass.gender = Convert.ToInt32(gender);
        personclass.yearBorn = yearBorn;
        personclass.house_hold_city = house_hold_city;
        if (localLive.Trim() != "")
            personclass.localLive = Convert.ToInt32(localLive);
        if (marriage.Trim() != "")
            personclass.marriage = Convert.ToInt32(marriage);
        if (children.Trim() != "")
            personclass.children = Convert.ToInt32(children);
        if (education.Trim() != "")
            personclass.education = Convert.ToInt32(education);
        if (ssFund.Trim() != "")
            personclass.ssFund = Convert.ToInt32(ssFund);
        personclass.work_city = work_city;
        personclass.currentOnboardTime = currentOnboardTime;
        if (companyType.Trim() != "")
            personclass.companyType = Convert.ToInt32(companyType);
        if (industry.Trim() != "")
            personclass.industry = Convert.ToInt32(industry);
        if (salary.Trim() != "")
            personclass.salary = Convert.ToInt32(salary);
        if (salaryType.Trim() != "")
            personclass.salaryType = Convert.ToInt32(salaryType);
        if (creditCard.Trim() != "")
            personclass.creditCard = Convert.ToInt32(creditCard);
        personclass.firstCardTime = firstCardTime;
        if (totalLimit.Trim() != "")
            personclass.totalLimit = Convert.ToInt32(totalLimit);
        if (cardOverdueCount.Trim() != "")
            personclass.cardOverdueCount = Convert.ToInt32(cardOverdueCount);
        if (cardOverdueDays.Trim() != "")
            personclass.cardOverdueDays = Convert.ToInt32(cardOverdueDays);
        if (cardDebt.Trim() != "")
            personclass.cardDebt = Convert.ToInt32(cardDebt);
        if (isHasHouse.Trim() != "")
            personclass.isHasHouse = Convert.ToInt32(isHasHouse);
        if (isDebtHouse.Trim() != "")
            personclass.isDebtHouse = Convert.ToInt32(isDebtHouse);
        if (monthlyPayHouse.Trim() != "")
            personclass.monthlyPayHouse = Convert.ToInt32(monthlyPayHouse);
        if (isHasCar.Trim() != "")
            personclass.isHasCar = Convert.ToInt32(isHasCar);
        if (isDebtCar.Trim() != "")
            personclass.isDebtCar = Convert.ToInt32(isDebtCar);
        if (monthlyPayCar.Trim() != "")
            personclass.monthlyPayCar = Convert.ToInt32(monthlyPayCar);
        if (consultLoan.Trim() != "")
            personclass.consultLoan = Convert.ToInt32(consultLoan);
        if (otherLoanMoneyTotal.Trim() != "")
            personclass.otherLoanMoneyTotal = Convert.ToInt32(otherLoanMoneyTotal);
        if (otherLoanReturn.Trim() != "")
            personclass.otherLoanReturn = Convert.ToInt32(otherLoanReturn);
        personclass.version = version;
        personclass.MD5 = inputStr;
        return personclass;
    }
    #endregion

    #region 企业申请评分类赋值
    private static Enterprise jsonQYSQPFBind(string appKey, string uuid, string version, string month, string realName,string businessNumber,string clientNumber, string idenCard, string gender, string yearBorn, string house_hold_city, string marriage, string children, string education, string ssFund, string companyType, string industry, string creditCard, string firstCardTime, string totalLimit, string cardOverdueCount, string cardOverdueDays, string cardDebt, string isHasHouse, string isDebtHouse, string monthlyPayHouse, string isHasCar, string isDebtCar, string monthlyPayCar, string otherLoanMoneyTotal, string otherLoanReturn, string money, string role, string monthlyPrivateLiquid, string monthlyPublicLiquid, string companySize, string companyAddressOperat_city, string companyAddress_city, string registTime, string businessLicense, string creditCardCount, string cardDebtMount, string consultLoan)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(money)
        .Append(businessNumber)
        .Append(clientNumber)
        .Append(month)
        .Append(realName)
        .Append(idenCard)
        .Append(gender)
        .Append(yearBorn)
        .Append(house_hold_city)
        .Append(marriage)
        .Append(children)
        .Append(education)
        .Append(ssFund)
        .Append(role)
        .Append(companyType)
        .Append(industry)
        .Append(businessLicense)
        .Append(registTime)
        .Append(companyAddress_city)
        .Append(companyAddressOperat_city)
        .Append(companySize)
        .Append(monthlyPublicLiquid)
        .Append(monthlyPrivateLiquid)
        .Append(creditCard)
        .Append(firstCardTime)
        .Append(creditCardCount)
        .Append(totalLimit)
        .Append(cardOverdueCount)
        .Append(cardOverdueDays)
        .Append(cardDebt)
        .Append(cardDebtMount)
        .Append(isHasHouse)
        .Append(isDebtHouse)
        .Append(monthlyPayHouse)
        .Append(isHasCar)
        .Append(isDebtCar)
        .Append(monthlyPayCar)
        .Append(consultLoan)
        .Append(otherLoanMoneyTotal)
        .Append(otherLoanReturn)
         .Append(version)
        .Append(appKey);

        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        Enterprise enterprise = new Enterprise();
        enterprise.uuid = uuid;
        enterprise.money = money;
        if (month.Trim() != "")
            enterprise.month = Convert.ToInt32(month);
        enterprise.realName = realName;
        enterprise.idenCard = idenCard;
        enterprise.businessNumber = businessNumber;
        enterprise.clientNumber = clientNumber;
        if (gender.Trim() != "")
            enterprise.gender = Convert.ToInt32(gender);
        enterprise.yearBorn = yearBorn;
        enterprise.house_hold_city = house_hold_city;
        if (marriage.Trim() != "")
            enterprise.marriage = Convert.ToInt32(marriage);
        if (children.Trim() != "")
            enterprise.children = Convert.ToInt32(children);
        if (education.Trim() != "")
            enterprise.education = Convert.ToInt32(education);
        if (ssFund.Trim() != "")
            enterprise.ssFund = Convert.ToInt32(ssFund);
        if (role.Trim() != "")
            enterprise.role = Convert.ToInt32(role);
        if (companyType.Trim() != "")
            enterprise.companyType = Convert.ToInt32(companyType);
        if (industry.Trim() != "")
            enterprise.industry = Convert.ToInt32(industry);
        if (businessLicense.Trim() != "")
            enterprise.businessLicense = Convert.ToInt32(businessLicense);
        if (registTime.Trim() != "")
            enterprise.registTime = registTime;
        if (companyAddress_city.Trim() != "")
            enterprise.companyAddress_city = companyAddress_city;
        enterprise.companyAddressOperat_city = companyAddressOperat_city;
        if (companySize.Trim() != "")
            enterprise.companySize = Convert.ToInt32(companySize);
        if (monthlyPublicLiquid.Trim() != "")
            enterprise.monthlyPublicLiquid = Convert.ToInt32(monthlyPublicLiquid);
        if (monthlyPrivateLiquid.Trim() != "")
            enterprise.monthlyPrivateLiquid = Convert.ToInt32(monthlyPrivateLiquid);
        if (creditCard.Trim() != "")
            enterprise.creditCard = Convert.ToInt32(creditCard);
        enterprise.firstCardTime = firstCardTime;
        if (creditCardCount.Trim() != "")
            enterprise.creditCardCount = Convert.ToInt32(creditCardCount);
        if (totalLimit.Trim() != "")
            enterprise.totalLimit = Convert.ToInt32(totalLimit);
        if (cardOverdueCount.Trim() != "")
            enterprise.cardOverdueCount = Convert.ToInt32(cardOverdueCount);
        if (cardOverdueDays.Trim() != "")
            enterprise.cardOverdueDays = Convert.ToInt32(cardOverdueDays);
        if (cardDebt.Trim() != "")
            enterprise.cardDebt = Convert.ToInt32(cardDebt);
        if (cardDebtMount.Trim() != "")
            enterprise.cardDebtMount = Convert.ToInt32(cardDebtMount);
        if (isHasHouse.Trim() != "")
            enterprise.isHasHouse = Convert.ToInt32(isHasHouse);
        if (isDebtHouse.Trim() != "")
            enterprise.isDebtHouse = Convert.ToInt32(isDebtHouse);
        if (monthlyPayHouse.Trim() != "")
            enterprise.monthlyPayHouse = Convert.ToInt32(monthlyPayHouse);
        if (isHasCar.Trim() != "")
            enterprise.isHasCar = Convert.ToInt32(isHasCar);
        if (isDebtCar.Trim() != "")
            enterprise.isDebtCar = Convert.ToInt32(isDebtCar);
        if (monthlyPayCar.Trim() != "")
            enterprise.monthlyPayCar = Convert.ToInt32(monthlyPayCar);
        if (consultLoan.Trim() != "")
            enterprise.consultLoan = Convert.ToInt32(consultLoan);
        if (otherLoanMoneyTotal.Trim() != "")
            enterprise.otherLoanMoneyTotal = Convert.ToInt32(otherLoanMoneyTotal);
        if (otherLoanReturn.Trim() != "")
            enterprise.otherLoanReturn = Convert.ToInt32(otherLoanReturn);
        enterprise.version = version;
        enterprise.MD5 = inputStr;
        return enterprise;
    }
    #endregion

    #region 申请反馈
    private static jsonSQFKclass jsonSQFKBind(string appKey, string uuid, string version, string businessNumber, string feedbackNumber, string borrowResult, string refuseReason)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(businessNumber)
        .Append(feedbackNumber)
        .Append(borrowResult)
        .Append(refuseReason)
        .Append(version)
        .Append(appKey);
        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonSQFKclass personclass = new jsonSQFKclass();
        personclass.uuid = uuid;
        personclass.businessNumber = businessNumber;
        personclass.feedbackNumber = feedbackNumber;
        personclass.refuseReason = refuseReason;
        if (borrowResult.Trim() != "")
            personclass.borrowResult = Convert.ToInt32(borrowResult);
        personclass.version = version;
        personclass.MD5 = inputStr;
        return personclass;
    }
    private static jsonSQFKclassold jsonSQFKBindold(string appKey, string uuid, string version, string realName, string idenCard, string borrowResult, string refuseReason)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(realName)
        .Append(idenCard)
        .Append(borrowResult)
        .Append(refuseReason)
        .Append(version)
        .Append(appKey);
        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonSQFKclassold personclass = new jsonSQFKclassold();
        personclass.uuid = uuid;
        personclass.realName = realName;
        personclass.idenCard = idenCard;
        personclass.refuseReason = refuseReason;
        if (borrowResult.Trim() != "")
            personclass.borrowResult = Convert.ToInt32(borrowResult);
        personclass.version = version;
        personclass.MD5 = inputStr;
        return personclass;
    }
   
    #endregion

    #region 反欺诈评分类赋值
    private static jsonFQZclass jsonFQZPFBind(string appKey, string uuid, string version,string businessNumber,string clientNumber, string idenCard, string name, string mobile,
        string companyTel, string linkmanMobile, string phoneCode, string phoneCodeType, string platform, string addressHome, string addressCompany)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(version)
        .Append(businessNumber)
        .Append(clientNumber)
        .Append(idenCard)
        .Append(name)
        .Append(mobile)
        .Append(companyTel)
        .Append(linkmanMobile)
        .Append(phoneCode)
        .Append(phoneCodeType)
        .Append(platform)
        .Append(addressHome)
        .Append(addressCompany)
        .Append(appKey);
        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonFQZclass enterprise = new jsonFQZclass();
        enterprise.uuid = uuid;
        enterprise.version = version;
        enterprise.businessNumber = businessNumber;
        enterprise.clientNumber = clientNumber;
        enterprise.idCard = idenCard;
        enterprise.name = name;
        enterprise.mobile = mobile;
        enterprise.companyTel = companyTel;
        enterprise.linkmanMobile = linkmanMobile;
        enterprise.phoneCode = phoneCode;
        if (phoneCodeType.Trim() != "")
            enterprise.phoneCodeType = Convert.ToInt32(phoneCodeType);
        if (platform.Trim() != "")
            enterprise.platform = Convert.ToInt32(platform);
        enterprise.addressHome = addressHome;
        enterprise.addressCompany = addressCompany;
        enterprise.MD5 = inputStr;
        return enterprise;
    }
    #endregion

    #region 反欺诈反馈类赋值
    private static jsonFQZFKclass jsonFQZFKBind(string appKey, string uuid, string version, string businessNumber, string feedbackNumber, string isFraud, string fraudType)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(version)
        .Append(businessNumber)
        .Append(feedbackNumber)
        .Append(isFraud)
        .Append(fraudType)
        .Append(appKey);
        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonFQZFKclass enterprise = new jsonFQZFKclass();
        enterprise.uuid = uuid;
        enterprise.version = version;
        enterprise.businessNumber = businessNumber;
        enterprise.feedbackNumber = feedbackNumber;
        if (isFraud.Trim() != "")
            enterprise.isFraud = Convert.ToInt32(isFraud);
        if (fraudType.Trim() != "")
            enterprise.fraudType = Convert.ToInt32(fraudType);
        enterprise.MD5 = inputStr;
        return enterprise;
    }
    #endregion

    #region 个人违约评分类赋值
    private static jsonPersonWyclass jsonGRWYPFBind(string appKey, string uuid, string businessNumber,string clientNumber, string gender, string birthday, string education,
        string marriage, string children, string isOpen, string isNative, string liveCase, string liveJoin, string compAddresProvince,
        string compJoinDate, string companyType, string yearIncome, string borrowType, string car, string house, string isCredit, string creditLimit,
        string creditCardAccount, string sumLoan, string noCancellationAccount, string overdueLoan, string overdueCreditCardNum, string overdueLoanNum,
        string sumOneMonthOverdueCard, string sumOneMonthOverdueLoan, string longOneMonthCard, string longOneMonthLoan, string sixMonthAverageLimit,
        string sixMonthAverageRepayment, string totalNowMonthRepayCard, string totalNowMonthRepayLoan, string totalCreditLimit, string totalLoanMoney,
        string totalUsedLimit, string totalBalance, string queryTimesOne, string cardAmountAvg, string maxReturnMoney, string nowAddressProvince, string version)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(businessNumber)
         .Append(clientNumber)
        .Append(gender)
        .Append(birthday)
        .Append(education)
        .Append(marriage)
        .Append(children)
        .Append(isOpen)
        .Append(isNative)
        .Append(liveCase)
        .Append(liveJoin)
        .Append(compAddresProvince)
        .Append(compJoinDate)
        .Append(companyType)
        .Append(yearIncome)
        .Append(borrowType)
        .Append(car)
        .Append(house)
        .Append(isCredit)
        .Append(creditLimit)
        .Append(creditCardAccount)
        .Append(sumLoan)
        .Append(noCancellationAccount)
        .Append(overdueLoan)
        .Append(overdueCreditCardNum)
        .Append(overdueLoanNum)
        .Append(sumOneMonthOverdueCard)
        .Append(sumOneMonthOverdueLoan)
        .Append(longOneMonthCard)
        .Append(longOneMonthLoan)
        .Append(sixMonthAverageLimit)
        .Append(sixMonthAverageRepayment)
        .Append(totalNowMonthRepayCard)
        .Append(totalNowMonthRepayLoan)
        .Append(totalCreditLimit)
        .Append(totalLoanMoney)
        .Append(totalUsedLimit)
        .Append(totalBalance)
        .Append(queryTimesOne)
        .Append(cardAmountAvg)
        .Append(maxReturnMoney)
        .Append(nowAddressProvince)
        .Append(version)
        .Append(appKey);
        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonPersonWyclass personclass = new jsonPersonWyclass();
        personclass.uuid = uuid;
        personclass.businessNumber = businessNumber;
        personclass.clientNumber = clientNumber;
        if (gender.Trim() != "")
            personclass.gender = Convert.ToInt32(gender);
        personclass.birthday = birthday;
        if (education.Trim() != "")
            personclass.education = Convert.ToInt32(education);
        if (marriage.Trim() != "")
            personclass.marriage = Convert.ToInt32(marriage);
        if (children.Trim() != "")
            personclass.children = Convert.ToInt32(children);
        if (isOpen.Trim() != "")
            personclass.isOpen = Convert.ToInt32(isOpen);
        if (isNative.Trim() != "")
            personclass.isNative = Convert.ToInt32(isNative);
        if (liveCase.Trim() != "")
            personclass.liveCase = Convert.ToInt32(liveCase);
        if (liveJoin.Trim() != "")
            personclass.liveJoin = Convert.ToInt32(liveJoin);
        personclass.compAddresProvince = compAddresProvince;
        if (compJoinDate.Trim() != "")
            personclass.compJoinDate = compJoinDate;
        if (companyType.Trim() != "")
            personclass.companyType = Convert.ToInt32(companyType);
        personclass.yearIncome = yearIncome;
        if (borrowType.Trim() != "")
            personclass.borrowType = Convert.ToInt32(borrowType);
        if (car.Trim() != "")
            personclass.car = Convert.ToInt32(car);
        if (house.Trim() != "")
            personclass.house = Convert.ToInt32(house);
        if (isCredit.Trim() != "")
            personclass.isCredit = Convert.ToInt32(isCredit);
        personclass.creditLimit = creditLimit;
        if (creditCardAccount.Trim() != "")
            personclass.creditCardAccount = Convert.ToInt32(creditCardAccount);
        if (sumLoan.Trim() != "")
            personclass.sumLoan = Convert.ToInt32(sumLoan);
        if (noCancellationAccount.Trim() != "")
            personclass.noCancellationAccount = Convert.ToInt32(noCancellationAccount);
        if (overdueLoan.Trim() != "")
            personclass.overdueLoan = Convert.ToInt32(overdueLoan);
        if (overdueCreditCardNum.Trim() != "")
            personclass.overdueCreditCardNum = Convert.ToInt32(overdueCreditCardNum);
        if (overdueLoanNum.Trim() != "")
            personclass.overdueLoanNum = Convert.ToInt32(overdueLoanNum);
        personclass.sumOneMonthOverdueCard = sumOneMonthOverdueCard;
        personclass.sumOneMonthOverdueLoan = sumOneMonthOverdueLoan;
        if (longOneMonthCard.Trim() != "")
            personclass.longOneMonthCard = Convert.ToInt32(longOneMonthCard);
        if (longOneMonthLoan.Trim() != "")
            personclass.longOneMonthLoan = Convert.ToInt32(longOneMonthLoan);
        personclass.sixMonthAverageLimit = sixMonthAverageLimit;
        personclass.sixMonthAverageRepayment = sixMonthAverageRepayment;
        personclass.totalNowMonthRepayCard = totalNowMonthRepayCard;
        personclass.totalNowMonthRepayLoan = totalNowMonthRepayLoan;
        personclass.totalCreditLimit = totalCreditLimit;
        personclass.totalLoanMoney = totalLoanMoney;
        personclass.totalUsedLimit = totalUsedLimit;
        personclass.totalBalance = totalBalance;
        if (queryTimesOne.Trim() != "")
            personclass.queryTimesOne = Convert.ToInt32(queryTimesOne);
        personclass.cardAmountAvg = cardAmountAvg;
        personclass.maxReturnMoney = maxReturnMoney;
        personclass.nowAddressProvince = nowAddressProvince;
        personclass.version = version;
        personclass.MD5 = inputStr;
        return personclass;
    }
    #endregion

    #region 企业主违约评分类赋值
    private static jsonOCWyclass jsonQYWYPFBind(string appKey, string uuid, string businessNumber, string clientNumber, string gender, string birthday, string education,
      string marriage, string children, string isOpen, string isNative, string liveCase, string liveJoin, string compAddresProvince,
      string companyType, string isLegalPerson, string stockRatio, string regDate, string palace, string staffAmount, string publicAverage,
        string monthlyPrivateLiquid, string yearIncome, string borrowType, string car, string house, string isCredit, string creditLimit,
      string creditCardAccount, string sumLoan, string noCancellationAccount, string overdueLoan, string overdueCreditCardNum, string overdueLoanNum,
      string sumOneMonthOverdueCard, string sumOneMonthOverdueLoan, string longOneMonthCard, string longOneMonthLoan, string sixMonthAverageLimit,
      string sixMonthAverageRepayment, string totalNowMonthRepayCard, string totalNowMonthRepayLoan, string totalCreditLimit, string totalLoanMoney,
      string totalUsedLimit, string totalBalance, string queryTimesOne, string maxReturnMoney, string version)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(businessNumber)
         .Append(clientNumber)
        .Append(gender)
        .Append(birthday)
        .Append(education)
        .Append(marriage)
        .Append(children)
        .Append(isOpen)
        .Append(isNative)
        .Append(liveCase)
        .Append(liveJoin)
        .Append(compAddresProvince)
        .Append(companyType)
        .Append(isLegalPerson)
        .Append(stockRatio)
        .Append(regDate)
        .Append(palace)
        .Append(staffAmount)
        .Append(publicAverage)
        .Append(monthlyPrivateLiquid)
        .Append(yearIncome)
        .Append(borrowType)
        .Append(car)
        .Append(house)
        .Append(isCredit)
        .Append(creditLimit)
        .Append(creditCardAccount)
        .Append(sumLoan)
        .Append(noCancellationAccount)
        .Append(overdueLoan)
        .Append(overdueCreditCardNum)
        .Append(overdueLoanNum)
        .Append(sumOneMonthOverdueCard)
        .Append(sumOneMonthOverdueLoan)
        .Append(longOneMonthCard)
        .Append(longOneMonthLoan)
        .Append(sixMonthAverageLimit)
        .Append(sixMonthAverageRepayment)
        .Append(totalNowMonthRepayCard)
        .Append(totalNowMonthRepayLoan)
        .Append(totalCreditLimit)
        .Append(totalLoanMoney)
        .Append(totalUsedLimit)
        .Append(totalBalance)
        .Append(queryTimesOne)
        .Append(maxReturnMoney)
        .Append(version)
        .Append(appKey);
        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonOCWyclass personclass = new jsonOCWyclass();
        personclass.uuid = uuid;
        personclass.businessNumber = businessNumber;
        personclass.clientNumber = clientNumber;
        if (gender.Trim() != "")
            personclass.gender = Convert.ToInt32(gender);
        personclass.birthday = birthday;
        if (education.Trim() != "")
            personclass.education = Convert.ToInt32(education);
        if (marriage.Trim() != "")
            personclass.marriage = Convert.ToInt32(marriage);
        if (children.Trim() != "")
            personclass.children = Convert.ToInt32(children);
        if (isOpen.Trim() != "")
            personclass.isOpen = Convert.ToInt32(isOpen);
        if (isNative.Trim() != "")
            personclass.isNative = Convert.ToInt32(isNative);
        if (liveCase.Trim() != "")
            personclass.liveCase = Convert.ToInt32(liveCase);
        if (liveJoin.Trim() != "")
            personclass.liveJoin = Convert.ToInt32(liveJoin);
        personclass.compAddresProvince = compAddresProvince;
        if (companyType.Trim() != "")
            personclass.companyType = Convert.ToInt32(companyType);
        if (isLegalPerson.Trim() != "")
            personclass.isLegalPerson = Convert.ToInt32(isLegalPerson);
        personclass.stockRatio = stockRatio;
        personclass.regDate = regDate;
        if (palace.Trim() != "")
            personclass.palace = Convert.ToInt32(palace);
        if (staffAmount.Trim() != "")
            personclass.staffAmount = Convert.ToInt32(staffAmount);
        personclass.publicAverage = publicAverage;
        personclass.monthlyPrivateLiquid = monthlyPrivateLiquid;
        personclass.yearIncome = yearIncome;
        if (borrowType.Trim() != "")
            personclass.borrowType = Convert.ToInt32(borrowType);
        if (car.Trim() != "")
            personclass.car = Convert.ToInt32(car);
        if (house.Trim() != "")
            personclass.house = Convert.ToInt32(house);
        if (isCredit.Trim() != "")
            personclass.isCredit = Convert.ToInt32(isCredit);
        personclass.creditLimit = creditLimit;
        if (creditCardAccount.Trim() != "")
            personclass.creditCardAccount = Convert.ToInt32(creditCardAccount);
        if (sumLoan.Trim() != "")
            personclass.sumLoan = Convert.ToInt32(sumLoan);
        if (noCancellationAccount.Trim() != "")
            personclass.noCancellationAccount = Convert.ToInt32(noCancellationAccount);
        if (overdueLoan.Trim() != "")
            personclass.overdueLoan = Convert.ToInt32(overdueLoan);
        if (overdueCreditCardNum.Trim() != "")
            personclass.overdueCreditCardNum = Convert.ToInt32(overdueCreditCardNum);
        if (overdueLoanNum.Trim() != "")
            personclass.overdueLoanNum = Convert.ToInt32(overdueLoanNum);
        personclass.sumOneMonthOverdueCard = sumOneMonthOverdueCard;
        personclass.sumOneMonthOverdueLoan = sumOneMonthOverdueLoan;
        if (longOneMonthCard.Trim() != "")
            personclass.longOneMonthCard = Convert.ToInt32(longOneMonthCard);
        if (longOneMonthLoan.Trim() != "")
            personclass.longOneMonthLoan = Convert.ToInt32(longOneMonthLoan);
        personclass.sixMonthAverageLimit = sixMonthAverageLimit;
        personclass.sixMonthAverageRepayment = sixMonthAverageRepayment;
        personclass.totalNowMonthRepayCard = totalNowMonthRepayCard;
        personclass.totalNowMonthRepayLoan = totalNowMonthRepayLoan;
        personclass.totalCreditLimit = totalCreditLimit;
        personclass.totalLoanMoney = totalLoanMoney;
        personclass.totalUsedLimit = totalUsedLimit;
        personclass.totalBalance = totalBalance;
        if (queryTimesOne.Trim() != "")
            personclass.queryTimesOne = Convert.ToInt32(queryTimesOne);
        personclass.maxReturnMoney = maxReturnMoney;
        personclass.version = version;
        personclass.MD5 = inputStr;
        return personclass;
    }
    #endregion
    #region 违约反馈类赋值
    private static jsonWYFKclass jsonGRWYFKBind(string appKey, string uuid, string businessNumber, string clientNumber, string feedbackNumber, string loanPeriods,
        string loanMoney,string period, string monthReturnAmount, string planRepaymentDate, string repaymentFunds, string repayInterest, 
        string repaymentDate, string realityReceiveCapital, string realityReceiveInterest, string interestPenalty, string breach,
        string actualTotalAmount, string isOverdue, string overdueDays,
        string overduePeriod,string version)
    {
        //请求明文
        StringBuilder sb = new StringBuilder();
        sb.Append(uuid)
        .Append(businessNumber)
         .Append(clientNumber)
        .Append(feedbackNumber)
        .Append(loanPeriods)
        .Append(loanMoney)
        .Append(period)
        .Append(monthReturnAmount)
        .Append(planRepaymentDate)
        .Append(repaymentFunds)
        .Append(repayInterest)
        .Append(repaymentDate)
        .Append(realityReceiveCapital)
        .Append(realityReceiveInterest)
        .Append(interestPenalty)
        .Append(breach)
        .Append(actualTotalAmount)
        .Append(isOverdue)
        .Append(overdueDays)
        .Append(overduePeriod)
        .Append(version)
        .Append(appKey);
        string inputStr = GetMd5String(sb.ToString());//账号密码MD5加密
        jsonWYFKclass personclass = new jsonWYFKclass();
        personclass.uuid = uuid;
        personclass.businessNumber = businessNumber;
        personclass.clientNumber = clientNumber;
        personclass.feedbackNumber = feedbackNumber;
        if (loanPeriods.Trim() != "")
            personclass.loanPeriods = Convert.ToInt32(loanPeriods);
        personclass.loanMoney = loanMoney;
        if (period.Trim() != "")
            personclass.period = Convert.ToInt32(period);
        personclass.monthReturnAmount = monthReturnAmount;
        personclass.planRepaymentDate = planRepaymentDate;
        personclass.repaymentFunds = repaymentFunds;
        personclass.repayInterest = repayInterest;
        personclass.repaymentDate = repaymentDate;
        personclass.realityReceiveCapital = realityReceiveCapital;
        personclass.realityReceiveInterest = realityReceiveInterest;
        personclass.interestPenalty = interestPenalty;
        personclass.breach = breach;
        personclass.actualTotalAmount = actualTotalAmount;
        if (isOverdue.Trim() != "")
            personclass.isOverdue = Convert.ToInt32(isOverdue);
        if (overdueDays.Trim() != "")
            personclass.overdueDays = Convert.ToInt32(overdueDays);
        if (overduePeriod.Trim() != "")
            personclass.overduePeriod = Convert.ToInt32(overduePeriod);
        personclass.version = version;
        personclass.MD5 = inputStr;
        return personclass;
    }
    #endregion

    #region 定义存储数据类
    //个人申请评分接口序列化临时类
    public class jsonPersonclass : Object
    {
        public string uuid { getset; }
        public string money { getset; }
        public Nullable<int> month { getset; }
        public string realName { getset; }
        public string businessNumber { getset; }
        public string clientNumber { getset; }
        public string idenCard { getset; }
        public Nullable<int> gender { getset; }
        public string yearBorn { getset; }
        public string house_hold_city { getset; }
        public Nullable<int> localLive { getset; }
        public Nullable<int> marriage { getset; }
        public Nullable<int> children { getset; }
        public Nullable<int> education { getset; }
        public Nullable<int> ssFund { getset; }
        public string work_city { getset; }
        public string currentOnboardTime { getset; }
        public Nullable<int> companyType { getset; }
        public Nullable<int> industry { getset; }
        public Nullable<int> salary { getset; }
        public Nullable<int> salaryType { getset; }
        public Nullable<int> creditCard { getset; }
        public string firstCardTime { getset; }
        public Nullable<int> totalLimit { getset; }
        public Nullable<int> cardOverdueCount { getset; }
        public Nullable<int> cardOverdueDays { getset; }
        public Nullable<int> cardDebt { getset; }
        public Nullable<int> isHasHouse { getset; }
        public Nullable<int> isDebtHouse { getset; }
        public Nullable<int> monthlyPayHouse { getset; }
        public Nullable<int> isHasCar { getset; }
        public Nullable<int> isDebtCar { getset; }
        public Nullable<int> monthlyPayCar { getset; }
        public Nullable<int> consultLoan { getset; }
        public Nullable<int> otherLoanMoneyTotal { getset; }
        public Nullable<int> otherLoanReturn { getset; }
        public string version { getset; }
        public string MD5 { getset; }
    }
    //企业申请评分接口序列化临时类
    public class Enterprise : Object
    {
        public string uuid { getset; }
        public string money { getset; }
        public Nullable<int> month { getset; }
        public string realName { getset; }
        public string businessNumber { getset; }
        public string clientNumber { getset; }
        public string idenCard { getset; }
        public Nullable<int> gender { getset; }
        public string yearBorn { getset; }
        public string house_hold_city { getset; }
        public Nullable<int> marriage { getset; }
        public Nullable<int> children { getset; }
        public Nullable<int> education { getset; }
        public Nullable<int> ssFund { getset; }
        public Nullable<int> role { getset; }
        public Nullable<int> companyType { getset; }
        public Nullable<int> industry { getset; }
        public Nullable<int> businessLicense { getset; }
        public string registTime { getset; }
        public string companyAddress_city { getset; }
        public string companyAddressOperat_city { getset; }
        public Nullable<int> companySize { getset; }
        public Nullable<int> monthlyPublicLiquid { getset; }
        public Nullable<int> monthlyPrivateLiquid { getset; }
        public Nullable<int> creditCard { getset; }
        public string firstCardTime { getset; }
        public Nullable<int> creditCardCount { getset; }
        public Nullable<int> totalLimit { getset; }
        public Nullable<int> cardOverdueCount { getset; }
        public Nullable<int> cardOverdueDays { getset; }
        public Nullable<int> cardDebt { getset; }
        public Nullable<int> cardDebtMount { getset; }
        public Nullable<int> isHasHouse { getset; }
        public Nullable<int> isDebtHouse { getset; }
        public Nullable<int> monthlyPayHouse { getset; }
        public Nullable<int> isHasCar { getset; }
        public Nullable<int> isDebtCar { getset; }
        public Nullable<int> monthlyPayCar { getset; }
        public Nullable<int> consultLoan { getset; }
        public Nullable<int> otherLoanMoneyTotal { getset; }
        public Nullable<int> otherLoanReturn { getset; }
        public string version { getset; }
        public string MD5 { getset; }
    }
    //申请反馈接口临时类
    public class jsonSQFKclass : Object
    {
        public string uuid { getset; }
        public string businessNumber { getset; }
        public string feedbackNumber { getset; }
        public Nullable<int> borrowResult { getset; }
        public string refuseReason { getset; }
        public string version { getset; }
        public string MD5 { getset; }
    }

    //老数据申请反馈接口临时类
    public class jsonSQFKclassold : Object
    {
        public string uuid { getset; }
        public string realName { getset; }
        public string idenCard { getset; }
        public Nullable<int> borrowResult { getset; }
        public string refuseReason { getset; }
        public string version { getset; }
        public string MD5 { getset; }
    }
    //反欺诈评分接口临时类
    public class jsonFQZclass : Object
    {
        public string uuid { getset; }
        public string version { getset; }
        public string businessNumber { getset; }
        public string clientNumber { getset; }
        public string idCard { getset; }
        public string name { getset; }
        public string mobile { getset; }
        public string companyTel { getset; }
        public string linkmanMobile { getset; }
        public string phoneCode { getset; }
        public Nullable<int> phoneCodeType { getset; }
        public Nullable<int> platform { getset; }
        public string addressHome { getset; }
        public string addressCompany { getset; }
        public string MD5 { getset; }
    }
    //反欺诈评分接口联系人集合临时类
    public class jsonNamemobileclass : Object
    {
        public string mobile { getset; }
        public string name { getset; }
    }
    //反欺诈反馈接口临时类
    public class jsonFQZFKclass : Object
    {
        public string uuid { getset; }
        public string version { getset; }
        public string businessNumber { getset; }
        public string feedbackNumber { getset; }
        public string companyUid { getset; }
        public Nullable<int> isFraud { getset; }
        public Nullable<int> fraudType { getset; }
        public string MD5 { getset; }
    }

    //个人违约评分接口序列化临时类
    public class jsonPersonWyclass : Object
    {
        public string uuid { getset; }
        public string businessNumber { getset; }
        public string clientNumber { getset; }
        public Nullable<int> gender { getset; }
        public string birthday { getset; }
        public Nullable<int> education { getset; }
        public Nullable<int> marriage { getset; }
        public Nullable<int> children { getset; }
        public Nullable<int> isOpen { getset; }
        public Nullable<int> isNative { getset; }
        public Nullable<int> liveCase { getset; }
        public Nullable<int> liveJoin { getset; }
        public string compAddresProvince { getset; }
        public string compJoinDate { getset; }
        public Nullable<int> companyType { getset; }
        public string yearIncome { getset; }
        public Nullable<int> borrowType { getset; }
        public Nullable<int> car { getset; }
        public Nullable<int> house { getset; }
        public Nullable<int> isCredit { getset; }
        public string creditLimit { getset; }
        public Nullable<int> creditCardAccount { getset; }
        public Nullable<int> sumLoan { getset; }
        public Nullable<int> noCancellationAccount { getset; }
        public Nullable<int> overdueLoan { getset; }
        public Nullable<int> overdueCreditCardNum { getset; }
        public Nullable<int> overdueLoanNum { getset; }
        public string sumOneMonthOverdueCard { getset; }
        public string sumOneMonthOverdueLoan { getset; }
        public Nullable<int> longOneMonthCard { getset; }
        public Nullable<int> longOneMonthLoan { getset; }
        public string sixMonthAverageLimit { getset; }
        public string sixMonthAverageRepayment { getset; }
        public string totalNowMonthRepayCard { getset; }
        public string totalNowMonthRepayLoan { getset; }
        public string totalCreditLimit { getset; }
        public string totalLoanMoney { getset; }
        public string totalUsedLimit { getset; }
        public string totalBalance { getset; }
        public Nullable<int> queryTimesOne { getset; }
        public string cardAmountAvg { getset; }
        public string maxReturnMoney { getset; }
        public string nowAddressProvince { getset; }
        public string version { getset; }
        public string MD5 { getset; }
    }
    //企业违约评分接口序列化临时类
    public class jsonOCWyclass : Object
    {
        public string uuid { getset; }
        public string businessNumber { getset; }
        public string clientNumber { getset; }
        public Nullable<int> gender { getset; }
        public string birthday { getset; }
        public Nullable<int> education { getset; }
        public Nullable<int> marriage { getset; }
        public Nullable<int> children { getset; }
        public Nullable<int> isOpen { getset; }
        public Nullable<int> isNative { getset; }
        public Nullable<int> liveCase { getset; }
        public Nullable<int> liveJoin { getset; }
        public string compAddresProvince { getset; }
        public Nullable<int> companyType { getset; }
        public Nullable<int> isLegalPerson { getset; }
        public string stockRatio { getset; }
        public string regDate { getset; }
        public Nullable<int> palace { getset; }
        public Nullable<int> staffAmount { getset; }
        public string publicAverage { getset; }
        public string monthlyPrivateLiquid { getset; }
        public string yearIncome { getset; }
        public Nullable<int> borrowType { getset; }
        public Nullable<int> car { getset; }
        public Nullable<int> house { getset; }
        public Nullable<int> isCredit { getset; }
        public string creditLimit { getset; }
        public Nullable<int> creditCardAccount { getset; }
        public Nullable<int> sumLoan { getset; }
        public Nullable<int> noCancellationAccount { getset; }
        public Nullable<int> overdueLoan { getset; }
        public Nullable<int> overdueCreditCardNum { getset; }
        public Nullable<int> overdueLoanNum { getset; }
        public string sumOneMonthOverdueCard { getset; }
        public string sumOneMonthOverdueLoan { getset; }
        public Nullable<int> longOneMonthCard { getset; }
        public Nullable<int> longOneMonthLoan { getset; }
        public string sixMonthAverageLimit { getset; }
        public string sixMonthAverageRepayment { getset; }
        public string totalNowMonthRepayCard { getset; }
        public string totalNowMonthRepayLoan { getset; }
        public string totalCreditLimit { getset; }
        public string totalLoanMoney { getset; }
        public string totalUsedLimit { getset; }
        public string totalBalance { getset; }
        public string maxReturnMoney { getset; }
        public Nullable<int> queryTimesOne { getset; }
        public string version { getset; }
        public string MD5 { getset; }
    }

    //违约反馈接口序列化临时类
    public class jsonWYFKclass : Object
    {
        public string uuid { getset; }
        public string businessNumber { getset; }
        public string clientNumber { getset; }
        public string feedbackNumber { getset; }
        public Nullable<int> loanPeriods { getset; }
        public string loanMoney { getset; }
        public Nullable<int> period { getset; }
        public string monthReturnAmount { getset; }
        public string planRepaymentDate { getset; }
        public string repaymentFunds { getset; }
        public string repayInterest { getset; }
        public string repaymentDate { getset; }
        public string realityReceiveCapital { getset; }
        public string realityReceiveInterest { getset; }
        public string interestPenalty { getset; }
        public string breach { getset; }
        public string actualTotalAmount { getset; }
        public Nullable<int> isOverdue { getset; }
        public Nullable<int> overdueDays { getset; }
        public Nullable<int> overduePeriod { getset; }
        public string version { getset; }
        public string MD5 { getset; }
    }
    #endregion
 


    #region 生成五位随机数
    private static string fiverandomno()
    {
        Random r = new Random();
        string fiverandomno = r.Next(1000000099999999).ToString();
        return fiverandomno;
    }
    #endregion

    /// <summary>
    
/// MD5标准化加密  32位 16进制小写英文加密
    
/// </summary>
    
/// <param name="paramsString">加密字符串</param>
    
/// <returns>加密结果</returns>
    static string GetMd5String(string paramsString)
    {
        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
        byte[] bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(paramsString));
        StringBuilder sb = new StringBuilder();
        foreach (byte b in bytes)
            sb.AppendFormat("{0:x2}", b);
        return sb.ToString();
    }
    /// <summary>
    
/// 获取地区名称
    
/// </summary>
    
/// <param name="itemid">地区id</param>
    
/// <param name="cityType">地区类型1:最后节点地区,2:省,3:详细地址</param>
    
/// <returns>地区名称</returns>
    public static string GetcityName(string itemid, int cityType)
    {
        SYSEntities sysEt = new SYSEntities();
        string cityName = ""; ;
        var idList = itemid.Split('|').ToList();
        string idvalue = idList.Count > 0 ? idList[0] : "";
        if (idvalue.Length > 2)
        {
            if (cityType == 3 && idvalue != "" && idvalue.Length > 4)
            {
                var Name = sysEt.SYS_ddl_info.Where(p => p.ddl_type_id == 49 && p.item_value == idvalue).Select(p => p.item_name).FirstOrDefault();
                string idvalue1 = idvalue.Substring(02) + "0000";//
                string idvalue2 = idvalue.Substring(04) + "00";//
                var Name1 = sysEt.SYS_ddl_info.Where(p => p.ddl_type_id == 49 && p.item_value == idvalue1).Select(p => p.item_name).FirstOrDefault();
                if (idvalue1 != idvalue2)
                {
                    var Name2 = sysEt.SYS_ddl_info.Where(p => p.ddl_type_id == 49 && p.item_value == idvalue2).Select(p => p.item_name).FirstOrDefault();
                    cityName = (Name1 ?? "") + (Name2 ?? "");

                }
                if (idvalue2 != idvalue)
                {
                    var Name3 = sysEt.SYS_ddl_info.Where(p => p.ddl_type_id == 49 && p.item_value == idvalue).Select(p => p.item_name).FirstOrDefault();
                    cityName = cityName + (Name ?? "");
                }

            }
            else
            {
                if (cityType == 2 && idvalue != "")
                {
                    idvalue = idvalue.Substring(02) + "0000";
                }
                var Name = sysEt.SYS_ddl_info.Where(p => p.ddl_type_id == 49 && p.item_value == idvalue).Select(p => p.item_name).FirstOrDefault();
                cityName = Name ?? "";
                idvalue = idList.Count > 2 ? idList[2] : "";
                if (idvalue.Trim() != "")
                {
                    cityName = idvalue;
                }
                if (cityName == "市辖区" || cityName == "" || cityName == "" || cityName == "省直辖行政单位")
                {
                    cityName = "";
                }
            }
        }
        return cityName;
    }
    /// <summary>
    
/// 查询申请评分分数区间
    
/// </summary>
    
/// <param name="responseid">评分表id</param>
    
/// <param name="scoreType">类型(1,评分;2,区间)</param>
    
/// <returns>数据库对应值</returns>
    public static string GetScoreQJ(int responseid, int scoreType)
    {
        string PForQJ = "";
        CHKEntities chkEt = new CHKEntities();
        CHK_docking_score_response scoreresponse = chkEt.CHK_docking_score_response.Find(responseid);
        if (scoreresponse.IsNotNull())
        {
            if (scoreType == 1)
            {
                PForQJ = scoreresponse.score ?? "/";
            }
            else
            {
                PForQJ = scoreresponse.crate ?? "/";
            }
        }
        else
        {
            PForQJ = "/";
        }
        return PForQJ;
    }
     /// <summary>
    
/// 查询违约评分分数区间
    
/// </summary>
    
/// <param name="responseid">违约评分表id</param>
    
/// <param name="scoreType">类型(1,评分;2,区间)</param>
    
/// <returns>数据库对应值</returns>
    public static string GetWYScoreQJ(int responseid, int scoreType)
    {
        string PForQJ = "";
        CHKEntities chkEt = new CHKEntities();
        CHK_docking_WY_response scoreresponse = chkEt.CHK_docking_WY_response.Find(responseid);
        if (scoreresponse.IsNotNull())
        {
            if (scoreType == 1)
            {
                PForQJ = scoreresponse.score ?? "/";
            }
            else
            {
                PForQJ = scoreresponse.crate ?? "/";
            }
        }
        else
        {
            PForQJ = "/";
        }
        return PForQJ;
    }
    /// <summary>
    
/// 查询欺诈评分分数区间
    
/// </summary>
    
/// <param name="responseid">欺诈评分表id</param>
    
/// <param name="scoreType">类型(1,评分;2,区间3、建议分数)</param>
    
/// <returns>数据库对应值</returns>
    public static string GetQZScoreQJ(int responseid, int scoreType)
    {
        string PForQJ = "";
        CHKEntities chkEt = new CHKEntities();
        CHK_docking_QZ_response scoreresponse = chkEt.CHK_docking_QZ_response.Find(responseid);
        if (scoreresponse.IsNotNull())
        {
            if (scoreType == 1)
            {
                PForQJ = scoreresponse.totalScore ?? "/";
            }
            else if(scoreType == 3)
            {
                PForQJ = "第一高分:" + (scoreresponse.firstProposal ?? "") + "第二高分:" + (scoreresponse.secondProposal ?? "") + "第三高分:" + (scoreresponse.thirdProposal ?? "");
            }
        }
        else
        {
            PForQJ = "/";
        }
        return PForQJ;
    }

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 using System;

using System.Text;
using System.Security.Cryptography;
using System.Web;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.Web.UI;
using System.Collections.Generic;
using HttpWebUtility;
using System.Configuration;
using System.Data.Entity.Validation;

namespace Security
{
    public class SecurityUtils
    {

        // 商户代码
        public static string mchnt_cd = ConfigurationSettings.AppSettings["mchnt_cd"].Trim();

        //随机生成流水号
        public static string GetMchnt_txn_ssn()
        {
            Random rad = new Random();//实例化随机数产生器rad;
            string value = rad.Next(100010000).ToString();//用rad生成大于等于1000,小于等于9999的随机数
            return DateTime.Now.ToString("yyyyMMddHHmmssfff") + value;
        }

        // 私钥存放的位置
        public static string GetPrKey()
        {
            var foldName = "Bin";//存放的文件的名字
            string prKey = GetFileName(foldName) + "\prkey.key";
            return prKey;

        }
        //公钥 存放的位置
        public static string GetPrKey1()
        {
            var foldName = "Bin";//存放的文件的名字
            string prKey = GetFileName(foldName) + "\pbkey.key";
            return prKey;
        }
        /// <summary>
        
/// 验证签名
        
/// </summary>
        
/// <param name="OriginalString">原文:UTF8编码</param>
        
/// <param name="SignatureString">签名:base64编码的字节</param>
        
/// <param name="publicKeyPath">公钥路径</param>
        
/// <returns> 验签结果</returns>
        public static bool Verify(string OriginalString, string SignatureString, string publicKeyPath)
        {
            //将base64签名数据转码为字节 
            byte[] signedBase64 = Convert.FromBase64String(SignatureString);
            byte[] orgin = Encoding.UTF8.GetBytes(OriginalString);
            string pem;
            using (System.IO.FileStream fs = System.IO.File.OpenRead(publicKeyPath))
            {
                byte[] data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                pem = Encoding.UTF8.GetString(data);
            }

            RSACryptoServiceProvider oRSA = new RSACryptoServiceProvider();
            oRSA.FromXmlString(pem);




            bool bVerify = oRSA.VerifyData(orgin, "SHA1", signedBase64);
            return bVerify;
        }

        /// <summary>
        
/// 验证签名
        
/// </summary>
        
/// <param name="data">原文:UTF8编码</param>
        
/// <param name="privateKeyPath">证书路径:D:/certs/mycert.key</param>
        
/// <returns> 验签</returns>
        public string Sign(string data1, string privateKeyPath)
        {
            string pem;
            using (System.IO.FileStream fs = System.IO.File.OpenRead(privateKeyPath))
            {
                byte[] data = new byte[fs.Length];
                byte[] res = null;
                fs.Read(data, 0, data.Length);
                pem = Encoding.UTF8.GetString(data);
            }
            RSACryptoServiceProvider oRSA = new RSACryptoServiceProvider();
            oRSA.FromXmlString(pem);
            byte[] dataBytes = Encoding.UTF8.GetBytes(data1);
            byte[] signatureBytes = oRSA.SignData(dataBytes, "SHA1");
            return Convert.ToBase64String(signatureBytes);
        }

        /// <summary>
        
/// 验证签名
        
/// </summary>
        
/// <param name="data">原文:UTF8编码</param>
        
/// <param name="privateKeyPath">证书路径:D:/certs/mycert.key</param>
        
/// <returns> 验签</returns>
        public string SignIFRE(string data1, string privateKeyPath)
        {

            string pem;
            using (System.IO.FileStream fs = System.IO.File.OpenRead(privateKeyPath))
            {
                byte[] data = new byte[fs.Length];
                byte[] res = null;
                fs.Read(data, 0, data.Length);
                pem = Encoding.UTF8.GetString(data);
            }
            md5 m = new md5();
            pem = m.getmd5(pem, 16);//账号密码MD5加密
            return pem;
        }

        private byte[] GetPem(string type, byte[] data)
        {
            string pem = Encoding.UTF8.GetString(data);
            string header = String.Format("-----BEGIN {0}-----", type);
            string footer = String.Format("-----END {0}-----", type);
            int start = pem.IndexOf(header) + header.Length;
            int end = pem.IndexOf(footer, start);

            string base64 = pem.Substring(start, (end - start));

            return Convert.FromBase64String(base64);
        }

        private RSACryptoServiceProvider LoadCertificateFile(string filename)
        {
            using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
            {
                byte[] data = new byte[fs.Length];
                byte[] res = null;
                fs.Read(data, 0, data.Length);
                if (data[0] != 0x30)
                {
                    res = GetPem("RSA PRIVATE KEY", data);
                }
                try
                {
                    RSACryptoServiceProvider rsa = DecodeRSAPrivateKey(res);
                    return rsa;
                }
                catch (Exception ex)
                {
                }
                return null;
            }
        }

        private RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey)
        {
            byte[] MODULUS, E, D, P, Q, DP, DQ, IQ;

            // --------- Set up stream to decode the asn.1 encoded RSA private key ------  
            MemoryStream mem = new MemoryStream(privkey);
            BinaryReader binr = new BinaryReader(mem);  //wrap Memory Stream with BinaryReader for easy reading  
            byte bt = 0;
            ushort twobytes = 0;
            int elems = 0;
            try
            {
                twobytes = binr.ReadUInt16();
                if (twobytes == 0x8130//data read as little endian order (actual data order for Sequence is 30 81)  
                    binr.ReadByte();    //advance 1 byte  
                else if (twobytes == 0x8230)
                    binr.ReadInt16();    //advance 2 bytes  
                else
                    return null;

                twobytes = binr.ReadUInt16();
                if (twobytes != 0x0102//version number  
                    return null;
                bt = binr.ReadByte();
                if (bt != 0x00)
                    return null;


                //------ all private key components are Integer sequences ----  
                elems = GetIntegerSize(binr);
                MODULUS = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                E = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                D = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                P = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                Q = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                DP = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                DQ = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                IQ = binr.ReadBytes(elems);


                // ------- create RSACryptoServiceProvider instance and initialize with public key -----  
                CspParameters CspParameters = new CspParameters();
                CspParameters.Flags = CspProviderFlags.UseMachineKeyStore;
                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(1024, CspParameters);
                RSAParameters RSAparams = new RSAParameters();
                RSAparams.Modulus = MODULUS;
                RSAparams.Exponent = E;
                RSAparams.D = D;
                RSAparams.P = P;
                RSAparams.Q = Q;
                RSAparams.DP = DP;
                RSAparams.DQ = DQ;
                RSAparams.InverseQ = IQ;
                RSA.ImportParameters(RSAparams);
                return RSA;
            }
            catch (Exception ex)
            {

                return null;
            }
            finally
            {
                binr.Close();
            }
        }

        private int GetIntegerSize(BinaryReader binr)
        {
            byte bt = 0;
            byte lowbyte = 0x00;
            byte highbyte = 0x00;
            int count = 0;
            bt = binr.ReadByte();
            if (bt != 0x02)     //expect integer  
                return 0;
            bt = binr.ReadByte();

            if (bt == 0x81)
                count = binr.ReadByte();    // data size in next byte  
            else
                if (bt == 0x82)
                {
                    highbyte = binr.ReadByte(); // data size in next 2 bytes  
                    lowbyte = binr.ReadByte();
                    byte[] modint = { lowbyte, highbyte, 0x000x00 };
                    count = BitConverter.ToInt32(modint, 0);
                }
                else
                {
                    count = bt;     // we already have the data size  
                }

            while (binr.ReadByte() == 0x00)
            {   //remove high order zeros in data  
                count -= 1;
            }
            binr.BaseStream.Seek(-1, SeekOrigin.Current);       //last ReadByte wasn't a removed zero, so back up a byte  
            return count;
        }
        //md5,加密
        public string Encode(string codeName, string sourceString)
        {

            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sourceString, "MD5").ToLower();

        }

        public byte[] ReadFile(string fileName)
        {
            FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            int size = (int)f.Length;
            byte[] data = new byte[size];
            size = f.Read(data, 0, size);
            f.Close();
            return data;
        }

        public string ReturnActionXml(string url)
        {
            string xml;
            // HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            
//  request.Method = "GET";
            
//  HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(url, nullnullnull);
            using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                xml = sr.ReadToEnd();
            }

            return xml;

        }

        public string ReturnActionFromXml(string url, IDictionary<stringstring> parameters)
        {
            string xml;
            HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(url, parameters, nullnull, Encoding.UTF8, null);
            using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                xml = sr.ReadToEnd();
            }
            return xml;
        }

        public string GetXmlParam(string xml, string startParam, string endParam)
        {
            string xmlParam;
            int a = xml.IndexOf(startParam);
            int b = xml.LastIndexOf(endParam);
            int paramLength = startParam.Length;
            xmlParam = xml.Substring(a + paramLength, (b - a) - paramLength);
            return xmlParam;
        }

        //存放的文件夹
        public static string GetFileName(string foldName)
        {
            string savepath = "";
            // string tempPath = "~/Bin";
            
//  tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
            
// tempPath = tempPath.Replace("//LoanSettle", "");
            savepath = HttpContext.Current.Server.MapPath("~");
            string datePath = foldName;
            string sPath = savepath + @"" + datePath;
            if (!Directory.Exists(sPath))
                Directory.CreateDirectory(sPath);
            return sPath;
        }



    }
}

---------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Web;

namespace HttpWebUtility
{
    /// <summary>
    
/// HttpWebResponseUtility 的摘要说明
    
/// 抓取网页的数据 分别是post 和Get
    
/// </summary>
    public class HttpWebResponseUtility
    {
        private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
        public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "GET";
            request.UserAgent = DefaultUserAgent;
            if (!string.IsNullOrEmpty(userAgent))
            {
                request.UserAgent = userAgent;

            } if (timeout.HasValue)
            {
                request.Timeout = timeout.Value;
            } if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }
            return request.GetResponse() as HttpWebResponse;
        }
        public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<stringstring> parameters, int? timeout, string userAgent, Encoding requestEncoding, CookieCollection cookies)
        {
            if (string.IsNullOrEmpty(url))
            { throw new ArgumentNullException("url"); }
            if (requestEncoding == null)
            {
                throw new ArgumentNullException("requestEncoding");
            }
            HttpWebRequest request = null;             //如果是发送HTTPS请求     
            if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                request = WebRequest.Create(url) as HttpWebRequest;
                request.ProtocolVersion = HttpVersion.Version10;
            }
            else
            {
                request = WebRequest.Create(url) as HttpWebRequest;
            }
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            if (!string.IsNullOrEmpty(userAgent))
            {
                request.UserAgent = userAgent;
            }
            else
            {
                request.UserAgent = DefaultUserAgent;
            } if (timeout.HasValue)
            {
                request.Timeout = timeout.Value;
            } if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }
            //如果需要POST数据  
            if (!(parameters == null || parameters.Count == 0))
            {
                StringBuilder buffer = new StringBuilder(); int i = 0;
                foreach (string key in parameters.Keys)
                {
                    if (i > 0)
                    {
                        buffer.AppendFormat("&{0}={1}", key, parameters[key]);
                    }
                    else
                    {
                        buffer.AppendFormat("{0}={1}", key, parameters[key]);
                    } i++;
                }
                byte[] data = requestEncoding.GetBytes(buffer.ToString());
                using (Stream stream = request.GetRequestStream())
                { stream.Write(data, 0, data.Length); }
            } return request.GetResponse() as HttpWebResponse;
        }
        private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true//总是接受    
        }
    }

} 

原文地址:https://www.cnblogs.com/dullbaby/p/5500446.html