reInvokeJar.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #coding=utf-8
  2. import shutil
  3. import pdfplumber
  4. import pandas as pd
  5. import numpy as np;
  6. import sys
  7. import os
  8. import traceback
  9. from prp import PrpCrypt
  10. #指标相关
  11. import loanIndexParser as lip;
  12. import payRcdIndexParser as prp;
  13. import creditCardIndexParser as cip
  14. import queryInfoIndexParser as qip
  15. import requests
  16. import utils;
  17. import time;
  18. import consts;
  19. import math
  20. import dfParser;
  21. import gc
  22. import json
  23. from dbController import DbController
  24. from pboc.invokePboc import PBOC
  25. from ini_op import Config;
  26. base_dir = os.path.dirname(os.path.abspath(__file__))
  27. config = Config(base_dir+"/config.ini");
  28. isPlt = config.get("baseconf", "isPlt");
  29. productNumJz = config.get("baseconf","productNumJz")
  30. productNumXy = config.get("baseconf", "productNumXy")
  31. #连接数据库
  32. dbController = DbController();
  33. pd.set_option('mode.chained_assignment', None)
  34. import log
  35. logger = log.logger
  36. import pymysql;
  37. from DBUtils.PooledDB import PooledDB;
  38. import xyHttp
  39. import json
  40. if isPlt == "1":
  41. db = "crt_plt"
  42. pwd = "888888"
  43. else:
  44. db = "crt"
  45. pwd = "root"
  46. pool = PooledDB(pymysql,10,host='localhost',user='root',passwd=pwd,db=db,port=3306,charset="utf8");
  47. def getProductNum(cerf_id):
  48. product_num = "";
  49. try:
  50. conn = pool.connection();
  51. cursor = conn.cursor()
  52. sql = "select product_num from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
  53. res = cursor.execute(sql);
  54. data = cursor.fetchone();
  55. if data !=None and len(data)>0:
  56. product_num = data[0]
  57. except:
  58. logger.error(" getBussinessNum error" + sql)
  59. info = sys.exc_info()
  60. logger.error(info[0])
  61. logger.error(info[1])
  62. # logging.log(logging.ERROR, info[2])
  63. logger.error(traceback.extract_tb(info[2], 1))
  64. finally:
  65. cursor.close();
  66. conn.close();
  67. return product_num;
  68. def getBizNum(cerf_id):
  69. product_num = "";
  70. try:
  71. conn = pool.connection();
  72. cursor = conn.cursor()
  73. sql = "select business_num from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
  74. res = cursor.execute(sql);
  75. data = cursor.fetchone();
  76. if data !=None and len(data)>0:
  77. product_num = data[0]
  78. except:
  79. logger.error(" getBussinessNum error" + sql)
  80. info = sys.exc_info()
  81. logger.error(info[0])
  82. logger.error(info[1])
  83. # logging.log(logging.ERROR, info[2])
  84. logger.error(traceback.extract_tb(info[2], 1))
  85. finally:
  86. cursor.close();
  87. conn.close();
  88. return product_num;
  89. #调用jar包
  90. def invokePboc(queryInfoCardId,txt_path):
  91. # ===================================
  92. try:
  93. # logger.error(pdf_path)
  94. # fileName = os.path.basename(pdf_path)
  95. # logger.error(fileName)
  96. # jsonFileName = fileName.replace("pdf", 'txt')
  97. coopNum = dbController.getCoopBussinessNum(queryInfoCardId); # 根据身份证获取业务编号
  98. productNum = dbController.getProductNum(queryInfoCardId);
  99. pboc = PBOC()
  100. # print(queryInfoCardId)
  101. if productNum == "CPA0100743":
  102. jarTxt = pboc.calc(txt_path,coopNum);
  103. logger.info(jarTxt)
  104. except:
  105. info = sys.exc_info()
  106. logger.error(info[0])
  107. logger.error(info[1])
  108. # logging.log(logging.ERROR, info[2])
  109. logger.error(traceback.extract_tb(info[2], 1))
  110. def invokeLocal(queryInfoCardId,txt_path):
  111. try:
  112. productNum = getProductNum(queryInfoCardId)
  113. bizNum = getBizNum(queryInfoCardId)
  114. if productNum == "CPA0100734":#快牛
  115. businessInfo = {}
  116. with open(txt_path,encoding='utf-8') as file_obj:
  117. content = file_obj.read()
  118. businessInfo["result"]=content
  119. jarTxt = xyHttp.callLocal(businessInfo)
  120. if jarTxt["approveResult"]=="3":
  121. logger.info(bizNum+"\t"+"拒绝\t"+jarTxt["rule"])
  122. else:
  123. logger.info(bizNum+"\t"+"通过")
  124. print(txt_path+file)
  125. except:
  126. info = sys.exc_info()
  127. logger.error(info[0])
  128. logger.error(info[1])
  129. # logging.log(logging.ERROR, info[2])
  130. logger.error(queryInfoCardId)
  131. logger.error(traceback.extract_tb(info[2], 1))
  132. logger.error(traceback.print_exc())
  133. logger.error(traceback.format_exc())
  134. #上传审批结果
  135. def uploadAudit(result,businessNum):
  136. approvalType = result["approveResult"]
  137. if approvalType=="1":
  138. approvalOpinion = "征信通过"
  139. approvalType = "4"
  140. else:
  141. approvalOpinion = "征信拒绝"
  142. approvalType = "3"
  143. taskKey = config.get("baseconf","taskKey")
  144. appoveApiUrl = config.get("baseconf","appoveApiUrl")
  145. key = config.get("baseconf", "AESKey")
  146. data = {"header":{
  147. "ticket": "2938123198320412343",
  148. "timestamp": int(int(round(time.time() * 1000+60*1000))),
  149. "nonce": config.get("baseconf", "nonce")
  150. },
  151. "body":{"approvalType": approvalType, "businessNum": businessNum,"taskKey":taskKey,"approvalOpinion":approvalOpinion}}
  152. access_token = dbController.getToken()
  153. appoveApiUrl = appoveApiUrl+"?access_token="+access_token
  154. headers = {"Content-Type": "application/json"}
  155. jsonStr = json.dumps(data);
  156. jsonStr = jsonStr.replace('"',"\\\"")#必须替换才行
  157. logger.info(jsonStr)
  158. pboc = PBOC();
  159. encryData = pboc.encrypt(jsonStr,key)
  160. encryData = encryData[0:len(encryData)-2]
  161. logger.info(encryData)
  162. response = requests.post(appoveApiUrl, data=encryData,headers=headers)
  163. text = response.text
  164. p = PrpCrypt(key)
  165. resultText = p.decrypt(text)
  166. logger.info(businessNum + "#" + "upload_result:" + resultText)
  167. if __name__ == '__main__':
  168. txt_path = "D:/mydocument/myprojects/creditreport/parse/kcdTxt/"
  169. txt_path= "D:/mydocument/myproject/git/parse/"
  170. if isPlt=="1":
  171. txt_path = "D:/KcdTxt/"
  172. # invokePboc("23012719900301108X", txt_path + "张玉峰_370628197901034617.txt")
  173. dirList = ""
  174. for file in os.listdir(txt_path):
  175. if file.endswith("txt"):
  176. arF = file.split("_")
  177. if len(arF)>=2:
  178. print(arF[1].replace(".txt",""))
  179. # invokePboc(arF[1].replace(".txt",""), txt_path+file)
  180. invokeLocal(arF[1].replace(".txt",""), txt_path+file)