# -*- coding: utf-8 -*- import requests import json import os from ini_op import Config; base_dir = os.path.dirname(os.path.abspath(__file__)) import log import utils logger = log.logger config = Config(base_dir+"/config.ini"); CREATE_API = config.get("baseconf","create_api") qk_url= config.get("baseconf", "qk_url"); hsz_url= config.get("baseconf", "hsz_url"); hc_url= config.get("baseconf", "hc_url"); jz_url= config.get("baseconf", "jz_url"); #小赢服务 def call_credit(businessInfo): credit_xml = businessInfo["creditXml"] extendData = businessInfo["extend"] extendData = json.loads(extendData) # credit_xml = '<征信原始Json串>' rule_params = {"riskVar": {"xdStatus": 1, "isApp": 1, "pyEdu": 1}, "version": "0.0.3", "product_name": "kd", "ruleSet": {"ruleZx113": {}, "ruleZx120": {}, "ruleZx121": {}, "ruleZx101": {}, "ruleZxNohigh": {}, "ruleZx119": {}, "ruleZx118": {}, "ruleZx108": {}, "ruleZx104": {"tdCardOpenMonth": "3"}, "ruleZx110": {}, "ruleZx116": {"tdLoanOver1p5M": "1500000"}, "ruleZx115": {"tdDebitCardTotal1": "0", "tdDebitCardTotal2": "2", "tdSingleDebitCardMax": "2"}}, "specialSet": {"ruleZx111": {"tdMaxOpenMonth": "6"}}, "scoreSet": {"ruleZx129": {"tdCreditScore": "850"}}, "method": "rule_kd_one"} model_params = {"version": "kyd_pboc_lr_v1"} params = { 'ruleParams' : rule_params, 'modelParams': model_params } request_data = { 'requestId': businessInfo["coopBusinessNum"], 'extendData': json.dumps(extendData["zxmb"]), 'zxData': credit_xml } request_data1 = { 'requestId': businessInfo["coopBusinessNum"], 'extendData': extendData, } # logger.info(request_data1) resp = requests.post(CREATE_API, data=json.dumps(request_data)) return resp.text #调用洽客http def callQk(businessInfo): credit_xml = businessInfo["result"] request_data = { 'queryReq': credit_xml } # logger.info(json.dumps(request_data)) headers = {"Content-Type":"application/json"} resp = requests.post(qk_url, data=json.dumps(request_data),headers=headers) return resp.text #恒昌 def callHc(businessInfo): credit_json = businessInfo["result"] request_data = { 'queryReq': credit_json } # logger.info(json.dumps(request_data)) headers = {"Content-Type":"application/json"} resp = requests.post(hc_url, data=json.dumps(request_data),headers=headers) return resp.text #调用慧算账 def callHsz(businessInfo): creditJson = businessInfo["result"] extend = businessInfo["extend"] request_data = { 'queryReq': creditJson, 'extend':extend } # logger.info(json.dumps(request_data)) headers = {"Content-Type":"application/json"} resp = requests.post(hsz_url, data=json.dumps(request_data),headers=headers) return resp.text #新版桔子 def callJz(businessInfo): creditJson = businessInfo["result"] extend = businessInfo["extend"] request_data = { 'queryReq': creditJson, 'extend':extend } # logger.info(json.dumps(request_data)) headers = {"Content-Type":"application/json"} resp = requests.post(jz_url, data=json.dumps(request_data),headers=headers) result = resp.text dataResult = json.loads(result) dataResult["data"]["orderNo"]=businessInfo["coopBusinessNum"] return json.dumps(dataResult) def convert(N,key): N = null2Zero(N) result = "" if N == 0: result = "sun" elif N>=1 and N<3 and (key=="A2" or key=="A3" or key=="A8" or key=="A9" or key=="A10"): result = "aries" elif N>=3 and (key=="A2"): result = "taurus" elif N>=3 and N<6 and (key=="A3" or key=="A8" or key=="A9" or key=="A10"): result = "gemini" elif N>=6 and (key=="A3" or key=="A8" or key=="A9" or key=="A10"): result = "cancer" elif N>0 and N<=5000 and (key=="A4"): result = "leo" elif N > 5000 and N <= 10000 and (key == "A4"): result = "virgo" elif N > 0 and N <= 10000 and (key == "A1" or key == "A7"): result = "libra" elif N > 10000 and N <= 30000 and (key == "A1" or key == "A7"): result = "scorpio" elif N >30000 and (key == "A1" or key == "A7"): result = "sagittarius" elif N > 0 and N <= 50000 and (key == "A5" or key == "A6"): result = "capricorn" elif N > 50000 and N <= 100000 and (key == "A5" or key == "A6"): result = "aquarius" elif N > 100000 and N <= 500000 and (key == "A5" or key == "A6"): result = "pisces" elif N >500000 and (key == "A5" or key == "A6"): result = "moon" return result; def buildJyData(businessInfo,jsonPath): data = {} jsonData = json.loads(businessInfo["result"]); #强制执行信息-涉及金额 publicInfoBrief = jsonData["公共信息概要"]; data["A1"] = convert(publicInfoBrief["强制执行信息-涉及金额"],"A1") queryRecordSum = jsonData["查询记录汇总"]; data["A2"] = convert(queryRecordSum["近1月内的查询次数-贷款审批"],"A2") loanInfo = jsonData["贷款信息"]; data["A3"] = convert(loanInfo["当前贷款最大逾期期数"],"A3") data["A4"] = convert(loanInfo["当前贷款最大逾期金额"],"A4") data["A5"] = convert(loanInfo["当前未结清贷款余额总和"],"A5") data["A6"] = convert(loanInfo["当前正常贷款账户余额"],"A6") creditInfo = jsonData["贷记卡账户"]; data["A7"] = convert(creditInfo["当前贷记卡最大逾期金额"],"A7") data["A8"] = convert(creditInfo["近12月贷记卡最大逾期期数"],"A8") queryRecordDetailDf = jsonData["信贷审批查询记录明细"] data["A9"] = convert(publicInfoBrief["强制执行信息-记录数"], "A9") data["A10"] = convert(queryRecordDetailDf["近3月查询次数"],"A10") with open(jsonPath, 'w', encoding='utf-8') as fp: fp.write(json.dumps(data)) def null2Zero(value): if value==None: return 0 else: return utils.toInt(value); #本地jar def callLocal(businessInfo): jsonData = json.loads(businessInfo["result"]); approveResult = "1"; #默认为通过,如果不满足条件为3 loanInfo = jsonData["贷款信息"]; badDebtsInfo = jsonData["呆账信息汇总"]; parsePayRcdStatus = jsonData["24期还款状态"]; creditInfo = jsonData["贷记卡账户"]; creditInfoZ = jsonData["准贷记卡账户"]; loanTradeInfoDf = jsonData["信贷交易信息提示"] # useRate = jsonData["使用率"] # queryRecordDetailDf = jsonData["信贷审批查询记录明细"] recoveryInfoSum = jsonData["信贷交易违约信息概要"] allAccountNum = null2Zero(loanTradeInfoDf["个人住房贷款账户数"])+null2Zero(loanTradeInfoDf["个人商用房贷款(包括商住两用)账户数"])\ +null2Zero(loanTradeInfoDf["其他类贷款账户数"])+null2Zero(loanTradeInfoDf["贷记卡账户数"])\ +null2Zero(loanTradeInfoDf["准贷记卡账户数"]) #公积金 housingFundRcd = jsonData["住房公积金参缴记录"] rule = "" if null2Zero(parsePayRcdStatus["全账户近24月逾期期数大于或等于“3”的次数"])>=1 or null2Zero(parsePayRcdStatus["全账户近24月逾期期数大于或等于“1”的次数"])>=6: approveResult = "0" rule="#1" rule += "#全账户近24月逾期期数大于或等于“3”的次数=" + str(parsePayRcdStatus["全账户近24月逾期期数大于或等于“3”的次数"]) rule += "#全账户近24月逾期期数大于或等于“1”的次数=" + str(parsePayRcdStatus["全账户近24月逾期期数大于或等于“1”的次数"]) elif (utils.toInt(null2Zero(badDebtsInfo["账户数"]))>0) or null2Zero(badDebtsInfo["余额"])>0: approveResult = "0" rule="#2" rule += "#呆账账户数=" + str(badDebtsInfo["账户数"]) elif parsePayRcdStatus["贷款账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷记卡账户近24个月是否出现\"G\""]=="1" \ or parsePayRcdStatus["准贷记卡账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷款账户近24个月是否出现\"Z\""]=="1": approveResult = "0" rule="#3" rule += "#明细出现\"G\或者还款记录出现以资抵债\"Z\"=" + str(parsePayRcdStatus["贷款账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷记卡账户近24个月是否出现\"G\""]=="1" \ or parsePayRcdStatus["准贷记卡账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷款账户近24个月是否出现\"Z\""]=="1") elif loanInfo.__contains__("当前贷款最大逾期期数") and null2Zero(loanInfo["当前贷款最大逾期期数"])>0: approveResult = "0" rule="#4" rule += "#当前贷款最大逾期期数=" + str(loanInfo["当前贷款最大逾期期数"]) elif creditInfo.__contains__("当前贷记卡最大逾期期数") and null2Zero(creditInfo["当前贷记卡最大逾期期数"]) > 0: approveResult = "0" rule = "#4" rule += "#当前贷记卡最大逾期期数=" + str(creditInfo["当前贷记卡最大逾期期数"]) elif null2Zero(creditInfo["名下贷记卡数量-状态异常"])>0: approveResult = "0" rule="#5" rule += "#名下贷记卡数量-状态异常=" + str(creditInfo["名下贷记卡数量-状态异常"]) elif creditInfoZ.__contains__("名下准贷记卡数量-状态异常") and null2Zero(creditInfoZ["名下准贷记卡数量-状态异常"])>0: approveResult = "0" rule="#6" rule += "#名下准贷记卡数量-状态异常=" + str(creditInfoZ["名下准贷记卡数量-状态异常"]) elif null2Zero(recoveryInfoSum["垫款业务账户数"])>=3:#原来为>0 approveResult = "0" rule="#16" rule += "#垫款业务账户数=" + str(recoveryInfoSum["垫款业务账户数"]) elif null2Zero(recoveryInfoSum["垫款业务余额"]) > 0: approveResult = "0" rule="#17" rule += "#垫款业务余额=" + str(recoveryInfoSum["垫款业务余额"]) #白户 elif allAccountNum==0 and housingFundRcd["参缴日期"]==None: approveResult = "0" rule = "#18" rule += "#白户#无信贷交易明细" data = {"approveResult":approveResult,"rule":rule} return data; if __name__ == '__main__': print(call_credit())