parseCreditXml.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. #coding=utf-8
  2. from xml.dom import minidom
  3. import base64
  4. import sys
  5. import os
  6. from customModel import CustomModel
  7. from ini_op import Config;
  8. base_dir = os.path.dirname(os.path.abspath(__file__)) #当前文件上一层目录的绝对路径
  9. config = Config(base_dir+"/config.ini");
  10. productNumXy = config.get("baseconf", "productNumXy")
  11. productNumJz = config.get("baseconf","productNumJz")
  12. productNumXxw = config.get("baseconf","productNumXxw")
  13. productNumFb = config.get("baseconf", "productNumFb")
  14. productNumKcd = config.get("baseconf", "productNumKcd")
  15. productNumFd = config.get("baseconf", "productNumFd")
  16. productNumKn = config.get("baseconf", "productNumKn")
  17. productNumHst = config.get("baseconf", "productNumHst")
  18. productNumQk = config.get("baseconf", "productNumQk")
  19. productNumHc = config.get("baseconf", "productNumHc")
  20. productNum500 = config.get("baseconf", "productNum500")
  21. productNumHsz = config.get("baseconf", "productNumHsz")
  22. #简营
  23. productNumJy = config.get("baseconf", "productNumJy")
  24. #新版桔子
  25. productNumJzA = config.get("baseconf", "productNumJzA")
  26. #仁东
  27. productNumRd = config.get("baseconf", "productNumRd")
  28. #恒昌新
  29. productNumHcNew = config.get("baseconf", "productNumHcNew")
  30. isPlt = config.get("baseconf", "isPlt");
  31. import xyHttp
  32. import hst_rule_set
  33. import pboc_hc
  34. import log
  35. import shutil
  36. logger = log.logger
  37. import time
  38. from dbController import DbController
  39. dbController = DbController();
  40. import json
  41. import requests
  42. import timeit
  43. import traceback
  44. import gzip
  45. import io
  46. from xmlParser import XmlParser;
  47. from xmlParserHsz import XmlParserHsz;
  48. from pboc.invokePboc import PBOC
  49. from mailUtil import MailUtil
  50. approResult=0
  51. def gzip_str(string_):
  52. out = io.BytesIO()
  53. with gzip.GzipFile(fileobj=out, mode='w') as fo:
  54. fo.write(string_.encode())
  55. bytes_obj = out.getvalue()
  56. return bytes_obj
  57. def gunzip_bytes_obj(bytes_obj):
  58. in_ = io.BytesIO()
  59. in_.write(bytes_obj)
  60. in_.seek(0)
  61. with gzip.GzipFile(fileobj=in_, mode='rb') as fo:
  62. gunzipped_bytes_obj = fo.read()
  63. return gunzipped_bytes_obj.decode()
  64. #解析xml数据
  65. def getBusinessInfo(xmlFile):
  66. doc = minidom.parse(xmlFile)
  67. request = doc.documentElement.getElementsByTagName("request")[0]
  68. responseBody = doc.documentElement.getElementsByTagName("responseBody")[0]
  69. responseHeader = doc.documentElement.getElementsByTagName("responseHeader")[0]
  70. result = ""
  71. xmlData = ""
  72. isBaihu = "0";
  73. if len(responseBody.childNodes)==0:
  74. mailUtil = MailUtil();
  75. webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
  76. resultMsg = getNodeData(responseHeader,"resultMsg")
  77. if resultMsg =="查询成功,无报告":
  78. isBaihu = "1"
  79. elif resultMsg == "输入的姓名与系统收录的姓名不一致":
  80. isBaihu = "3"
  81. else:
  82. isBaihu = "2"#查询失败
  83. mailUtil.dingtalk("号码:" + xmlFile.split("_")[0] + " 查询失败 ", webhook)
  84. else:
  85. responseBodyText = responseBody.childNodes[0].data
  86. decrpyt_bytes = base64.b64decode(responseBodyText)
  87. xmlData = gunzip_bytes_obj(decrpyt_bytes)
  88. # print(xmlData)
  89. #remove by chenqiwang 1105
  90. xmlPath = xmlFile+".txt"
  91. # 生成xml格式报告
  92. with open(xmlPath, 'w', encoding='utf-8') as fp:
  93. fp.write(xmlData)
  94. # 非小赢需要解析
  95. productNum = getNodeData(request, "productNum")
  96. # print("a")
  97. # print(productNum + "cc")
  98. # print("b")
  99. sqlMap = []
  100. if productNum != productNumXy:
  101. if xmlData !="":
  102. if productNum == productNumHsz:
  103. result,sqlMap = parseHsz(xmlData)
  104. # print("HSZ")
  105. else:
  106. #跑数据的时候改为parseHsz
  107. result,sqlMap = parse(xmlData)
  108. data = {
  109. "businessNum":getNodeData(request,"businessNum"),
  110. "coopBusinessNum": getNodeData(request, "coopBusinessNum"),
  111. "customerNum":getNodeData(request,"customerNum"),
  112. "certificateNum": getNodeData(request, "certificateNum"),
  113. "productNum": productNum,
  114. "creditXml":xmlData,
  115. "extend": getNodeData(request, "extend"),
  116. "result":result,
  117. "isBaihu":isBaihu,
  118. "sqlMap":sqlMap
  119. }
  120. return data
  121. #解析xml报文
  122. def parse(xmlData):
  123. xmlParse = XmlParser()
  124. result = ""
  125. try:
  126. result,sqlMap = xmlParse.parse(xmlData)
  127. except:
  128. info = sys.exc_info()
  129. logger.error(info[0])
  130. logger.error(info[1])
  131. logger.error(traceback.extract_tb(info[2], 1))
  132. return result,sqlMap
  133. #解析xml报文 汇算帐
  134. def parseHsz(xmlData):
  135. xmlParseHsz = XmlParserHsz()
  136. result = ""
  137. try:
  138. result = xmlParseHsz.parse(xmlData)
  139. except:
  140. info = sys.exc_info()
  141. logger.error(info[0])
  142. logger.error(info[1])
  143. logger.error(traceback.extract_tb(info[2], 1))
  144. return result
  145. def getNodeData(request,key):
  146. data = request.getElementsByTagName(key)[0].childNodes[0].data
  147. return data;
  148. # if __name__ == '__main__':
  149. # businessInfo = getBusinessInfo('./test.xml')
  150. # print(businessInfo)
  151. # xml = ""
  152. # data = base64.b64encode(xml.encode("UTF-8"))
  153. # print(str(data))
  154. #调用http
  155. def process(businessInfo,basePath,xml_path,file_name):
  156. file_name = file_name
  157. productNum = businessInfo["productNum"]
  158. print("产品号:"+productNum)
  159. if productNumXy.find(productNum) >= 0:
  160. print("操作1")
  161. try:
  162. result = xyHttp.call_credit(businessInfo)
  163. # result = json.loads(result);
  164. # logger.info(result)
  165. #上传审批结果
  166. jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
  167. logger.info(jsonPath)
  168. with open(jsonPath, 'w', encoding='utf-8') as fp:
  169. fp.write(result)
  170. uploadJsonFile(businessInfo,jsonPath)
  171. #移动xml文件
  172. try:
  173. dayStrPath = basePath+productNum+"/"+time.strftime('%Y%m%d', time.localtime(time.time()))+"/";
  174. descXmlPath = dayStrPath +"xml/"+ os.path.basename(xml_path)
  175. descJsonPath = dayStrPath+"txt/" + os.path.basename(jsonPath)
  176. if not os.path.exists(basePath+productNum):
  177. os.mkdir(basePath+productNum)
  178. if not os.path.exists(dayStrPath):
  179. os.mkdir(dayStrPath)
  180. if not os.path.exists(dayStrPath+"xml/"):
  181. os.mkdir(dayStrPath + "xml/")
  182. if not os.path.exists(dayStrPath+"txt/"):
  183. os.mkdir(dayStrPath+"txt/")
  184. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  185. if isPlt == "1":
  186. move(xml_path, descXmlPath)
  187. shutil.move(jsonPath, descJsonPath)
  188. except:
  189. logger.error(businessInfo["certificateNum"]+"#创建文件夹或者移动文件失败,不影响业务")
  190. logger.error(traceback.print_exc())
  191. logger.error(traceback.format_exc())
  192. except:
  193. logger.error(traceback.print_exc())
  194. logger.error(traceback.format_exc())
  195. mailUtil = MailUtil();
  196. webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
  197. mailUtil.dingtalk("号码:" + businessInfo["certificateNum"] + " 调用xy服务失败 ", webhook)
  198. elif productNumQk.find(productNum) >= 0 or productNumHsz.find(productNum) >= 0 or productNumHc.find(productNum) >= 0 \
  199. or productNumJzA.find(productNum) >= 0 or productNumRd.find(productNum) >= 0 or productNumHcNew.find(productNum) >= 0:#洽客
  200. # print("操作2")
  201. txtPath = xml_path.replace(".xml", ".txt")
  202. result = ""
  203. if businessInfo["isBaihu"] != "3":
  204. with open(txtPath, 'w', encoding='utf-8') as fp:
  205. fp.write(businessInfo["result"])
  206. if productNumQk.find(productNum) >= 0:
  207. result = xyHttp.callQk(businessInfo)
  208. if productNumHc.find(productNum) >= 0:
  209. result = xyHttp.callHc(businessInfo)
  210. elif productNumHsz.find(productNum) >= 0:
  211. result = xyHttp.callHsz(businessInfo)
  212. # print(result)由于目标计算机积极拒绝,无法连接。
  213. elif productNumJzA.find(productNum) >= 0:
  214. result = xyHttp.callJz(businessInfo)
  215. elif productNumRd.find(productNum) >= 0:
  216. result = xyHttp.callRd(businessInfo)
  217. elif productNumHcNew.find(productNum) >= 0:
  218. result = pboc_hc.renhang_rules(businessInfo)
  219. # result = json.loads(result);
  220. #上传审批结果
  221. jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
  222. logger.info(jsonPath)
  223. if businessInfo["isBaihu"] == "3":
  224. result = "{'errCode':-1,errMsg:'输入的姓名与系统收录的姓名不一致'}"
  225. logger.info(result)
  226. with open(jsonPath, 'w', encoding='utf-8') as fp:
  227. fp.write(result)
  228. uploadJsonFile(businessInfo,jsonPath)
  229. #移动xml文件
  230. dayStrPath = basePath+productNum+"/"+time.strftime('%Y%m%d', time.localtime(time.time()))+"/";
  231. descXmlPath = dayStrPath +"xml/"+ os.path.basename(xml_path)
  232. descJsonPath = dayStrPath+"txt/" + os.path.basename(jsonPath)
  233. descTxtPath = dayStrPath + "txt/" + os.path.basename(txtPath)
  234. if not os.path.exists(basePath+productNum):
  235. os.mkdir(basePath+productNum)
  236. if not os.path.exists(dayStrPath):
  237. os.mkdir(dayStrPath)
  238. if not os.path.exists(dayStrPath+"xml/"):
  239. os.mkdir(dayStrPath + "xml/")
  240. if not os.path.exists(dayStrPath+"txt/"):
  241. os.mkdir(dayStrPath+"txt/")
  242. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  243. if isPlt == "1":
  244. move(xml_path, descXmlPath)
  245. shutil.move(jsonPath, descJsonPath)
  246. shutil.move(txtPath, descTxtPath)
  247. else:
  248. # print("产品号:"+productNum)
  249. #走jar包逻辑
  250. # print(businessInfo["result"])
  251. txtPath = xml_path.replace(".xml",".txt")
  252. # print("txt路径"+txtPath)
  253. with open(txtPath, 'w', encoding='utf-8') as fp:
  254. fp.write(businessInfo["result"])
  255. if productNum == productNumJz:#桔子
  256. print("桔子")
  257. invokePboc(businessInfo, txtPath)
  258. #移动xml文件
  259. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  260. if not os.path.exists(basePath + "execed_new/"):
  261. os.mkdir(basePath + "execed_new/")
  262. if isPlt == "1":
  263. move(xml_path, descXmlPath)
  264. elif productNum == productNumXxw:#新希望
  265. invokeXxw(businessInfo, txtPath);
  266. jsonPath = basePath + businessInfo["certificateNum"] + ".txt"
  267. #移动xml文件
  268. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  269. if not os.path.exists(basePath + "execed_new/"):
  270. os.mkdir(basePath + "execed_new/")
  271. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  272. if isPlt == "1":
  273. move(xml_path, descXmlPath)
  274. elif productNum == productNumFb or productNum== productNumKcd or productNum500.find(productNum)>=0:#没有java包 #快车道和风暴 上传500个字段
  275. logger.info(businessInfo["productNum"])
  276. uploadJsonFile(businessInfo,txtPath)
  277. # 移动xml文件
  278. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  279. if not os.path.exists(basePath + "execed_new/"):
  280. os.mkdir(basePath + "execed_new/")
  281. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  282. if isPlt == "1":
  283. move(xml_path, descXmlPath)
  284. elif productNumJy.find(productNum)>=0:#简营
  285. logger.info(businessInfo["productNum"])
  286. jsonPath = txtPath.replace(".txt","_json.txt")
  287. #写入数据到文件
  288. xyHttp.buildJyData(businessInfo,jsonPath)
  289. uploadJsonFile(businessInfo, jsonPath)
  290. # 移动xml文件
  291. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  292. if not os.path.exists(basePath + "execed_new/"):
  293. os.mkdir(basePath + "execed_new/")
  294. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  295. if isPlt == "1":
  296. descTxtPath = basePath + "execed_txt/" + os.path.basename(jsonPath)
  297. try:
  298. shutil.move(jsonPath, descTxtPath)
  299. except Exception:
  300. pass
  301. move(xml_path, descXmlPath)
  302. elif productNum == productNumFd:#分蛋 白户审批通过
  303. if businessInfo["result"]!="":
  304. result = xyHttp.callNewModel(businessInfo)
  305. uploadAudit(result,businessInfo["businessNum"],productNum)
  306. else:
  307. result = {"approveResult":"1","rule":"白户"}
  308. uploadAudit(result, businessInfo["businessNum"], productNum)
  309. # 移动xml文件
  310. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  311. if not os.path.exists(basePath + "execed_new/"):
  312. os.mkdir(basePath + "execed_new/")
  313. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  314. if isPlt == "1":
  315. move(xml_path, descXmlPath)
  316. elif productNumKn.find(productNum)>=0 :#快牛本地jar包,本地jar改为逗号配置
  317. if businessInfo["result"]!="":
  318. result = xyHttp.callLocal(businessInfo)
  319. uploadAudit(result,businessInfo["businessNum"],productNum)
  320. else:
  321. result = {"approveResult":"0","rule":"白户"}
  322. uploadAudit(result, businessInfo["businessNum"], productNum)
  323. # 移动xml文件
  324. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  325. if not os.path.exists(basePath + "execed_new/"):
  326. os.mkdir(basePath + "execed_new/")
  327. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  328. if isPlt == "1":
  329. move(xml_path, descXmlPath)
  330. elif productNum == productNumHst:#海盛通
  331. if businessInfo["result"]!="":
  332. result = hst_rule_set.callLocal(businessInfo)
  333. uploadAudit(result,businessInfo["businessNum"],productNum)
  334. else:
  335. result = {"approveResult":"0","rule":"白户"}
  336. uploadAudit(result, businessInfo["businessNum"], productNum)
  337. # 移动xml文件
  338. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  339. if not os.path.exists(basePath + "execed_new/"):
  340. os.mkdir(basePath + "execed_new/")
  341. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  342. if isPlt == "1":
  343. move(xml_path, descXmlPath)
  344. else:
  345. customModel= CustomModel();
  346. res=customModel.doCustomModel(productNum,businessInfo,xml_path,file_name);
  347. print("res是"+str(res))
  348. if res==3:
  349. jsonPath = xml_path.replace(".xml", "_json.txt")
  350. dayStrPath = basePath + productNum + "/" + time.strftime('%Y%m%d', time.localtime(time.time())) + "/";
  351. descXmlPath = dayStrPath + "xml/" + os.path.basename(xml_path)
  352. descJsonPath = dayStrPath + "txt/" + os.path.basename(jsonPath)
  353. descTxtPath = dayStrPath + "txt/" + os.path.basename(txtPath)
  354. if not os.path.exists(basePath + productNum):
  355. os.mkdir(basePath + productNum)
  356. if not os.path.exists(dayStrPath):
  357. os.mkdir(dayStrPath)
  358. if not os.path.exists(dayStrPath + "xml/"):
  359. os.mkdir(dayStrPath + "xml/")
  360. if not os.path.exists(dayStrPath + "txt/"):
  361. os.mkdir(dayStrPath + "txt/")
  362. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  363. if isPlt == "1":
  364. move(xml_path, descXmlPath)
  365. shutil.move(jsonPath, descJsonPath)
  366. shutil.move(txtPath, descTxtPath)
  367. else :
  368. descXmlPath = basePath + "execed_new/" + os.path.basename(xml_path)
  369. if not os.path.exists(basePath + "execed_new/"):
  370. os.mkdir(basePath + "execed_new/")
  371. logger.info("移动文件 from " + xml_path + " to " + descXmlPath)
  372. if isPlt == "1":
  373. move(xml_path, descXmlPath)
  374. # if(res):
  375. # result["approveResult"]="1"
  376. #
  377. # print(result);
  378. # 结果返回
  379. # uploadAudit(res, businessInfo["businessNum"], productNum)
  380. # 这个地方嵌进去结果
  381. i=0
  382. #本地jar
  383. if isPlt == "1":
  384. if not os.path.exists(basePath + "execed_txt/"):
  385. os.mkdir(basePath + "execed_txt/")
  386. descTxtPath = basePath + "execed_txt/" + os.path.basename(txtPath)
  387. shutil.move(txtPath, descTxtPath)
  388. #调用jar包
  389. def move(xml_path, descXmlPath):
  390. try:
  391. shutil.move(xml_path, descXmlPath)
  392. if not os.path.exists(basePath + "execed_xml/"):
  393. os.mkdir(basePath + "execed_xml/")
  394. shutil.move(xml_path+".txt", descXmlPath.replace("execed_new","execed_xml")+".txt")
  395. # os.remove(xml_path+".txt")#删除生成的xml.txt文件
  396. except:
  397. logger.info("移动文件 from " + xml_path + " to " + descXmlPath +" error")
  398. def invokePboc(businessInfo,txtPath):
  399. # ===================================
  400. try:
  401. # print(businessInfo)
  402. businessNum = businessInfo["businessNum"]
  403. coopBusinessNum = businessInfo["coopBusinessNum"]
  404. pboc = PBOC()
  405. jarTxt = pboc.calc(txtPath,coopBusinessNum);
  406. result = json.loads(jarTxt)
  407. logger.info(result)
  408. if result.get("errcode")== None:
  409. uploadAudit(result,businessNum,businessInfo["productNum"])
  410. else:
  411. if businessInfo["isBaihu"]=="1":
  412. result = {"approveResult":"1"}
  413. uploadAudit(result, businessNum, businessInfo["productNum"])
  414. logger.error(result["errmsg"])
  415. except:
  416. logger.error("certificateNum=" + businessInfo["coopBusinessNum"])
  417. info = sys.exc_info()
  418. logger.error(info[0])
  419. logger.error(info[1])
  420. # logging.log(logging.ERROR, info[2])
  421. logger.error(traceback.extract_tb(info[2], 1))
  422. #调用xxwjar包
  423. def invokeXxw(businessInfo,txtPath):
  424. try:
  425. businessNum = businessInfo["businessNum"]
  426. coopBusinessNum = businessInfo["coopBusinessNum"]
  427. customerNum = businessInfo["customerNum"]
  428. certificateNum = businessInfo["certificateNum"]
  429. pboc = PBOC()
  430. jarTxt = pboc.calcXxw(coopBusinessNum,customerNum,txtPath);
  431. logger.info("jarTxt:"+jarTxt)
  432. result = json.loads(jarTxt)
  433. jsonPath = basePath+certificateNum+".txt"
  434. # logger.info(jsonPath)
  435. with open(jsonPath, 'w', encoding='utf-8') as fp:
  436. fp.write(jarTxt)
  437. uploadJsonFile(businessInfo,jsonPath)
  438. if not os.path.exists(basePath + "execed_txt/"):
  439. os.mkdir(basePath + "execed_txt/")
  440. descJsonPath = basePath + "execed_txt/" + os.path.basename(jsonPath)
  441. shutil.move(jsonPath, descJsonPath)
  442. except:
  443. logger.error("certificateNum=" + businessInfo["coopBusinessNum"])
  444. info = sys.exc_info()
  445. logger.error(info[0])
  446. logger.error(info[1])
  447. logger.error(traceback.extract_tb(info[2], 1))
  448. #上传审批结果
  449. def uploadAudit(result,businessNum,productNum):
  450. global approResult
  451. approvalType = result["approveResult"]
  452. if productNum == productNumJz:
  453. if approvalType=="1":
  454. approvalOpinion = "征信通过"
  455. approvalType = "4"
  456. else:
  457. approvalOpinion = "征信拒绝"
  458. approvalType = "3"
  459. elif productNumKn.find(productNum)>=0 or productNum == productNumHst or productNum == productNumFd:
  460. if approvalType=="1":
  461. approvalOpinion = "征信通过"
  462. approvalType = "4"
  463. else:#快牛 需要添加拒绝原因
  464. approvalOpinion = "征信拒绝" + "#" + result["rule"]
  465. approvalType = "3"
  466. else:#自定义模型情况yuan
  467. if approvalType == "1":
  468. approvalOpinion = "征信通过"
  469. print("yuan上传审批征信通过")
  470. approvalType = "4"
  471. else:
  472. approvalOpinion = "征信拒绝"
  473. approvalType = "3"
  474. taskKey = config.get("baseconf","taskKey")
  475. appoveApiUrl = config.get("baseconf","appoveApiUrl")
  476. key = config.get("baseconf", "AESKey")
  477. data = {"header":{
  478. "ticket": "2938123198320412343",
  479. "timestamp": int(int(round(time.time() * 1000+60*1000))),
  480. "nonce": config.get("baseconf", "nonce")
  481. },
  482. "body":{"approvalType": approvalType, "businessNum": businessNum,"taskKey":taskKey,"approvalOpinion":approvalOpinion}}
  483. access_token = dbController.getToken();
  484. if access_token == "":#获取token失败重新获取
  485. access_token = dbController.getToken();
  486. appoveApiUrl = appoveApiUrl+"?access_token="+access_token
  487. headers = {"Content-Type": "application/json"}
  488. jsonStr = json.dumps(data);
  489. jsonStr = jsonStr.replace('"',"\\\"")#必须替换才行
  490. logger.info(jsonStr)
  491. pboc = PBOC();
  492. encryData = pboc.encrypt(jsonStr,key)
  493. encryData = encryData[0:len(encryData)-2]
  494. logger.info(encryData)
  495. response = requests.post(appoveApiUrl, data=encryData,headers=headers)
  496. text = response.text
  497. pboc = PBOC();
  498. resultText = pboc.decrypt(text, config.get("baseconf", "AESKey"))
  499. print(businessNum + "#" + "uploadAudit upload_result:" + resultText)
  500. logger.info(businessNum + "#" + "uploadAudit upload_result:" + resultText)
  501. #上传解析json
  502. def uploadJsonFile(businessInfo,json_path):
  503. # ===================================
  504. try:
  505. fileName = os.path.basename(json_path)
  506. #上传文件逻辑
  507. logger.info(json_path+"#"+"准备上传文件")
  508. uploadApiUrl = config.get("baseconf", "uploadApiUrl");
  509. token = dbController.getToken();
  510. if token == "":#如果获取失败,重新获取
  511. token = dbController.getToken();
  512. uploadApiUrl = uploadApiUrl + "?access_token=" + token
  513. files = {'file': open(json_path, 'rb')}
  514. logger.info(fileName+"#"+"businessNum:"+businessInfo["businessNum"])
  515. data = {'docType': "23", 'businessNum': businessInfo["businessNum"]}
  516. response = requests.post(uploadApiUrl, files=files, data=data,timeout=15)
  517. text = response.text
  518. logger.info("上传结果:"+text)
  519. pboc = PBOC();
  520. resultText = pboc.decrypt(text,config.get("baseconf", "AESKey"))
  521. logger.info(fileName+"#"+"uploadJsonFile:" + resultText)
  522. except:
  523. logger.error("certificateNum="+businessInfo["coopBusinessNum"])
  524. info = sys.exc_info()
  525. logger.error(info[0])
  526. logger.error(info[1])
  527. # logging.log(logging.ERROR, info[2])
  528. logger.error(traceback.extract_tb(info[2], 1))
  529. mailUtil = MailUtil();
  530. webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
  531. # mailUtil.dingtalk("号码:" + businessInfo["certificateNum"]+"-"+businessInfo["businessNum"] + " 上传文件失败 ", webhook)
  532. if __name__ == '__main__':
  533. basePath = "D:/jin_rong/test_data/"
  534. # basePath = "D:/mydocument/myprojects/creditreport/parse/"
  535. # file_name = sys.argv[1]
  536. file_name = "樊术生_432924196512260092_525976302319050756-20221116100213782.xml"
  537. #
  538. # file_name = "周平强_360122197901070610_255387334772537344.xml"
  539. # file_name = "lwl_450803199507215834_254603000272664585.xml"
  540. # # file_name="dqy_320821199205184730_255559091387119623.xml"
  541. # file_name='zl_342425199204087911_255220233202055177.xml'
  542. # file_name="sxg_330719197909242017_257564808331673603.xml"
  543. # file_name="pxy_522401199510147022_258623031256039426.xml"
  544. # file_name = "任赞_130185199601221319_257538384191307779.xml"
  545. # file_name="hrh_430722198805068479_255677390955493378.xml"
  546. # file_name="杨同山_340406197907213451_236806485030479874.xml"
  547. # # file_name = "1_210303197510273014_269873665141647369-202012091702117200.xml"
  548. # # file_name="任赞_130185199601221319_257538384191307779"
  549. # file_name="艾红平_520202198707150427_384652376306363396-202110221031275368.xml"
  550. # # file_name = "王彬彬_150429198902200911_5.xml"
  551. # file_name="裴增计_140522196602121517_331131028938695682-202105271756329018.xml"
  552. # file_name = "胡龙德_370829197506094916_389014816133485574-202111031126048397.xml"
  553. # file_name="周子彪_533024199501184513_257703742621630467.xml"
  554. xml_path = basePath + file_name
  555. start = timeit.default_timer();
  556. # if len(sys.argv) > 1:
  557. # basePath = sys.argv[1]
  558. # xml_path = basePath + sys.argv[2]
  559. # file_name = sys.argv[2]
  560. logger.info(xml_path+" 解析开始")
  561. print(xml_path+ " 解析开始")
  562. businessInfo = getBusinessInfo(xml_path)
  563. # uploadJsonFile(businessInfo,"D:/jin_rong/test_data/朱家铎_410922199111210030_255632073002334212.txt")
  564. # with open('D:/jin_rong/test_data/朱传光_371425199305027971_256979050910728199.txt', 'r', encoding='utf-8')as fp:
  565. # businessInfo['result'] = fp.read();
  566. # logger.info(businessInfo)
  567. if businessInfo["isBaihu"]!="2":#白户不上传1211
  568. try:
  569. process(businessInfo,basePath,xml_path,file_name)
  570. except:
  571. logger.error(traceback.print_exc())
  572. logger.error(traceback.format_exc())
  573. # if approResult==0:
  574. # print("征信通过")
  575. # dbController.getConn()
  576. # # print(len(sqlMap))
  577. # sql = "INSERT INTO credit_approval(approval_result,credit_name) VALUES ('征信通过', '" + file_name + "')"
  578. # print(sql)
  579. # dbController.execSql(sql)
  580. # # if i==1:
  581. # # break
  582. # dbController.commit()
  583. s = timeit.default_timer() - start;
  584. logger.info(str(s) + " 秒")
  585. logger.info(xml_path+" 解析完成")
  586. # 执行sql开始
  587. logger.info(xml_path + " 执行sql解析开始")
  588. print("this is a result")
  589. sqlMap = businessInfo["sqlMap"]
  590. # 执行sql完成
  591. # logger.info(sqlMap)
  592. try:
  593. start = timeit.default_timer();
  594. dbController.getConn()
  595. # print(len(sqlMap))
  596. for sql in sqlMap:
  597. # i +=1
  598. dbController.execSql(sql)
  599. # if i==1:
  600. # break
  601. dbController.commit()
  602. s = timeit.default_timer() - start;
  603. logger.info(xml_path+str(s) + " 秒")
  604. except:
  605. logger.error(traceback.print_exc())
  606. logger.error(traceback.format_exc())
  607. logger.info(xml_path + " 执行sql解析失败")
  608. logger.info(xml_path + " 执行sql解析完成")