xyHttp.py0706 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. # -*- coding: utf-8 -*-
  2. import requests
  3. import json
  4. import os
  5. from ini_op import Config;
  6. base_dir = os.path.dirname(os.path.abspath(__file__))
  7. import log
  8. import utils
  9. logger = log.logger
  10. config = Config(base_dir+"/config.ini");
  11. CREATE_API = config.get("baseconf","create_api")
  12. qk_url= config.get("baseconf", "qk_url");
  13. hsz_url= config.get("baseconf", "hsz_url");
  14. hc_url= config.get("baseconf", "hc_url");
  15. jz_url= config.get("baseconf", "jz_url");
  16. #小赢服务
  17. def call_credit(businessInfo):
  18. credit_xml = businessInfo["creditXml"]
  19. extendData = businessInfo["extend"]
  20. extendData = json.loads(extendData)
  21. # credit_xml = '<征信原始Json串>'
  22. rule_params = {"riskVar": {"xdStatus": 1, "isApp": 1, "pyEdu": 1},
  23. "version": "0.0.3",
  24. "product_name": "kd",
  25. "ruleSet": {"ruleZx113": {},
  26. "ruleZx120": {},
  27. "ruleZx121": {},
  28. "ruleZx101": {},
  29. "ruleZxNohigh": {},
  30. "ruleZx119": {},
  31. "ruleZx118": {},
  32. "ruleZx108": {},
  33. "ruleZx104": {"tdCardOpenMonth": "3"},
  34. "ruleZx110": {},
  35. "ruleZx116": {"tdLoanOver1p5M": "1500000"},
  36. "ruleZx115": {"tdDebitCardTotal1": "0", "tdDebitCardTotal2": "2",
  37. "tdSingleDebitCardMax": "2"}},
  38. "specialSet": {"ruleZx111": {"tdMaxOpenMonth": "6"}},
  39. "scoreSet": {"ruleZx129": {"tdCreditScore": "850"}},
  40. "method": "rule_kd_one"}
  41. model_params = {"version": "kyd_pboc_lr_v1"}
  42. params = {
  43. 'ruleParams' : rule_params,
  44. 'modelParams': model_params
  45. }
  46. request_data = {
  47. 'requestId': businessInfo["coopBusinessNum"],
  48. 'extendData': json.dumps(extendData["zxmb"]),
  49. 'zxData': credit_xml
  50. }
  51. request_data1 = {
  52. 'requestId': businessInfo["coopBusinessNum"],
  53. 'extendData': extendData,
  54. }
  55. # logger.info(request_data1)
  56. resp = requests.post(CREATE_API, data=json.dumps(request_data))
  57. return resp.text
  58. #调用洽客http
  59. def callQk(businessInfo):
  60. credit_xml = businessInfo["result"]
  61. request_data = {
  62. 'queryReq': credit_xml
  63. }
  64. # logger.info(json.dumps(request_data))
  65. headers = {"Content-Type":"application/json"}
  66. resp = requests.post(qk_url, data=json.dumps(request_data),headers=headers)
  67. return resp.text
  68. #恒昌
  69. def callHc(businessInfo):
  70. credit_json = businessInfo["result"]
  71. request_data = {
  72. 'queryReq': credit_json
  73. }
  74. # logger.info(json.dumps(request_data))
  75. headers = {"Content-Type":"application/json"}
  76. resp = requests.post(hc_url, data=json.dumps(request_data),headers=headers)
  77. return resp.text
  78. #调用慧算账
  79. def callHsz(businessInfo):
  80. creditJson = businessInfo["result"]
  81. extend = businessInfo["extend"]
  82. request_data = {
  83. 'queryReq': creditJson,
  84. 'extend':extend
  85. }
  86. # logger.info(json.dumps(request_data))
  87. headers = {"Content-Type":"application/json"}
  88. resp = requests.post(hsz_url, data=json.dumps(request_data),headers=headers)
  89. return resp.text
  90. #新版桔子
  91. def callJz(businessInfo):
  92. creditJson = businessInfo["result"]
  93. extend = businessInfo["extend"]
  94. request_data = {
  95. 'queryReq': creditJson,
  96. 'extend':extend
  97. }
  98. # logger.info(json.dumps(request_data))
  99. headers = {"Content-Type":"application/json"}
  100. resp = requests.post(jz_url, data=json.dumps(request_data),headers=headers)
  101. result = resp.text
  102. dataResult = json.loads(result)
  103. dataResult["data"]["orderNo"]=businessInfo["coopBusinessNum"]
  104. return json.dumps(dataResult)
  105. def convert(N,key):
  106. N = null2Zero(N)
  107. result = ""
  108. if N == 0:
  109. result = "sun"
  110. elif N>=1 and N<3 and (key=="A2" or key=="A3" or key=="A8" or key=="A9" or key=="A10"):
  111. result = "aries"
  112. elif N>=3 and (key=="A2"):
  113. result = "taurus"
  114. elif N>=3 and N<6 and (key=="A3" or key=="A8" or key=="A9" or key=="A10"):
  115. result = "gemini"
  116. elif N>=6 and (key=="A3" or key=="A8" or key=="A9" or key=="A10"):
  117. result = "cancer"
  118. elif N>0 and N<=5000 and (key=="A4"):
  119. result = "leo"
  120. elif N > 5000 and N <= 10000 and (key == "A4"):
  121. result = "virgo"
  122. elif N > 0 and N <= 10000 and (key == "A1" or key == "A7"):
  123. result = "libra"
  124. elif N > 10000 and N <= 30000 and (key == "A1" or key == "A7"):
  125. result = "scorpio"
  126. elif N >30000 and (key == "A1" or key == "A7"):
  127. result = "sagittarius"
  128. elif N > 0 and N <= 50000 and (key == "A5" or key == "A6"):
  129. result = "capricorn"
  130. elif N > 50000 and N <= 100000 and (key == "A5" or key == "A6"):
  131. result = "aquarius"
  132. elif N > 100000 and N <= 500000 and (key == "A5" or key == "A6"):
  133. result = "pisces"
  134. elif N >500000 and (key == "A5" or key == "A6"):
  135. result = "moon"
  136. return result;
  137. def buildJyData(businessInfo,jsonPath):
  138. data = {}
  139. jsonData = json.loads(businessInfo["result"]);
  140. #强制执行信息-涉及金额
  141. publicInfoBrief = jsonData["公共信息概要"];
  142. data["A1"] = convert(publicInfoBrief["强制执行信息-涉及金额"],"A1")
  143. queryRecordSum = jsonData["查询记录汇总"];
  144. data["A2"] = convert(queryRecordSum["近1月内的查询次数-贷款审批"],"A2")
  145. loanInfo = jsonData["贷款信息"];
  146. data["A3"] = convert(loanInfo["当前贷款最大逾期期数"],"A3")
  147. data["A4"] = convert(loanInfo["当前贷款最大逾期金额"],"A4")
  148. data["A5"] = convert(loanInfo["当前未结清贷款余额总和"],"A5")
  149. data["A6"] = convert(loanInfo["当前正常贷款账户余额"],"A6")
  150. creditInfo = jsonData["贷记卡账户"];
  151. data["A7"] = convert(creditInfo["当前贷记卡最大逾期金额"],"A7")
  152. data["A8"] = convert(creditInfo["近12月贷记卡最大逾期期数"],"A8")
  153. queryRecordDetailDf = jsonData["信贷审批查询记录明细"]
  154. data["A9"] = convert(publicInfoBrief["强制执行信息-记录数"], "A9")
  155. data["A10"] = convert(queryRecordDetailDf["近3月查询次数"],"A10")
  156. with open(jsonPath, 'w', encoding='utf-8') as fp:
  157. fp.write(json.dumps(data))
  158. def null2Zero(value):
  159. if value==None:
  160. return 0
  161. else:
  162. return utils.toInt(value);
  163. #本地jar
  164. def callLocal(businessInfo):
  165. jsonData = json.loads(businessInfo["result"]);
  166. approveResult = "1";
  167. #默认为通过,如果不满足条件为3
  168. loanInfo = jsonData["贷款信息"];
  169. badDebtsInfo = jsonData["呆账信息汇总"];
  170. parsePayRcdStatus = jsonData["24期还款状态"];
  171. creditInfo = jsonData["贷记卡账户"];
  172. creditInfoZ = jsonData["准贷记卡账户"];
  173. loanTradeInfoDf = jsonData["信贷交易信息提示"]
  174. # useRate = jsonData["使用率"]
  175. # queryRecordDetailDf = jsonData["信贷审批查询记录明细"]
  176. recoveryInfoSum = jsonData["信贷交易违约信息概要"]
  177. allAccountNum = null2Zero(loanTradeInfoDf["个人住房贷款账户数"])+null2Zero(loanTradeInfoDf["个人商用房贷款(包括商住两用)账户数"])\
  178. +null2Zero(loanTradeInfoDf["其他类贷款账户数"])+null2Zero(loanTradeInfoDf["贷记卡账户数"])\
  179. +null2Zero(loanTradeInfoDf["准贷记卡账户数"])
  180. #公积金
  181. housingFundRcd = jsonData["住房公积金参缴记录"]
  182. rule = ""
  183. if null2Zero(parsePayRcdStatus["全账户近24月逾期期数大于或等于“3”的次数"])>=1 or null2Zero(parsePayRcdStatus["全账户近24月逾期期数大于或等于“1”的次数"])>=6:
  184. approveResult = "0"
  185. rule="#1"
  186. rule += "#全账户近24月逾期期数大于或等于“3”的次数=" + str(parsePayRcdStatus["全账户近24月逾期期数大于或等于“3”的次数"])
  187. rule += "#全账户近24月逾期期数大于或等于“1”的次数=" + str(parsePayRcdStatus["全账户近24月逾期期数大于或等于“1”的次数"])
  188. elif (utils.toInt(null2Zero(badDebtsInfo["账户数"]))>0) or null2Zero(badDebtsInfo["余额"])>0:
  189. approveResult = "0"
  190. rule="#2"
  191. rule += "#呆账账户数=" + str(badDebtsInfo["账户数"])
  192. elif parsePayRcdStatus["贷款账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷记卡账户近24个月是否出现\"G\""]=="1" \
  193. or parsePayRcdStatus["准贷记卡账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷款账户近24个月是否出现\"Z\""]=="1":
  194. approveResult = "0"
  195. rule="#3"
  196. rule += "#明细出现\"G\或者还款记录出现以资抵债\"Z\"=" + str(parsePayRcdStatus["贷款账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷记卡账户近24个月是否出现\"G\""]=="1" \
  197. or parsePayRcdStatus["准贷记卡账户近24个月是否出现\"G\""]=="1" or parsePayRcdStatus["贷款账户近24个月是否出现\"Z\""]=="1")
  198. elif loanInfo.__contains__("当前贷款最大逾期期数") and null2Zero(loanInfo["当前贷款最大逾期期数"])>0:
  199. approveResult = "0"
  200. rule="#4"
  201. rule += "#当前贷款最大逾期期数=" + str(loanInfo["当前贷款最大逾期期数"])
  202. elif creditInfo.__contains__("当前贷记卡最大逾期期数") and null2Zero(creditInfo["当前贷记卡最大逾期期数"]) > 0:
  203. approveResult = "0"
  204. rule = "#4"
  205. rule += "#当前贷记卡最大逾期期数=" + str(creditInfo["当前贷记卡最大逾期期数"])
  206. elif null2Zero(creditInfo["名下贷记卡数量-状态异常"])>0:
  207. approveResult = "0"
  208. rule="#5"
  209. rule += "#名下贷记卡数量-状态异常=" + str(creditInfo["名下贷记卡数量-状态异常"])
  210. elif creditInfoZ.__contains__("名下准贷记卡数量-状态异常") and null2Zero(creditInfoZ["名下准贷记卡数量-状态异常"])>0:
  211. approveResult = "0"
  212. rule="#6"
  213. rule += "#名下准贷记卡数量-状态异常=" + str(creditInfoZ["名下准贷记卡数量-状态异常"])
  214. elif null2Zero(recoveryInfoSum["垫款业务账户数"])>=3:#原来为>0
  215. approveResult = "0"
  216. rule="#16"
  217. rule += "#垫款业务账户数=" + str(recoveryInfoSum["垫款业务账户数"])
  218. elif null2Zero(recoveryInfoSum["垫款业务余额"]) > 0:
  219. approveResult = "0"
  220. rule="#17"
  221. rule += "#垫款业务余额=" + str(recoveryInfoSum["垫款业务余额"])
  222. #白户
  223. elif allAccountNum==0 and housingFundRcd["参缴日期"]==None:
  224. approveResult = "0"
  225. rule = "#18"
  226. rule += "#白户#无信贷交易明细"
  227. data = {"approveResult":approveResult,"rule":rule}
  228. return data;
  229. if __name__ == '__main__':
  230. print(call_credit())