123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #coding=utf-8
- import shutil
- import pdfplumber
- import pandas as pd
- import numpy as np;
- import sys
- import os
- import traceback
- from prp import PrpCrypt
- #指标相关
- import loanIndexParser as lip;
- import payRcdIndexParser as prp;
- import creditCardIndexParser as cip
- import queryInfoIndexParser as qip
- import requests
- import utils;
- import time;
- import consts;
- import math
- import dfParser;
- import gc
- import json
- from dbController import DbController
- from pboc.invokePboc import PBOC
- from ini_op import Config;
- base_dir = os.path.dirname(os.path.abspath(__file__))
- config = Config(base_dir+"/config.ini");
- isPlt = config.get("baseconf", "isPlt");
- productNumJz = config.get("baseconf","productNumJz")
- productNumXy = config.get("baseconf", "productNumXy")
- #连接数据库
- dbController = DbController();
- pd.set_option('mode.chained_assignment', None)
- import log
- logger = log.logger
- import pymysql;
- from DBUtils.PooledDB import PooledDB;
- import xyHttp
- import json
- if isPlt == "1":
- db = "crt_plt"
- pwd = "888888"
- else:
- db = "crt"
- pwd = "root"
- pool = PooledDB(pymysql,10,host='localhost',user='root',passwd=pwd,db=db,port=3306,charset="utf8");
- def getProductNum(cerf_id):
- product_num = "";
- try:
- conn = pool.connection();
- cursor = conn.cursor()
- sql = "select product_num from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
- res = cursor.execute(sql);
- data = cursor.fetchone();
- if data !=None and len(data)>0:
- product_num = data[0]
- except:
- logger.error(" getBussinessNum error" + sql)
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- # logging.log(logging.ERROR, info[2])
- logger.error(traceback.extract_tb(info[2], 1))
- finally:
- cursor.close();
- conn.close();
- return product_num;
- def getBizNum(cerf_id):
- product_num = "";
- try:
- conn = pool.connection();
- cursor = conn.cursor()
- sql = "select business_num from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
- res = cursor.execute(sql);
- data = cursor.fetchone();
- if data !=None and len(data)>0:
- product_num = data[0]
- except:
- logger.error(" getBussinessNum error" + sql)
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- # logging.log(logging.ERROR, info[2])
- logger.error(traceback.extract_tb(info[2], 1))
- finally:
- cursor.close();
- conn.close();
- return product_num;
- #调用jar包
- def invokePboc(queryInfoCardId,txt_path):
- # ===================================
- try:
- # logger.error(pdf_path)
- # fileName = os.path.basename(pdf_path)
- # logger.error(fileName)
- # jsonFileName = fileName.replace("pdf", 'txt')
- coopNum = dbController.getCoopBussinessNum(queryInfoCardId); # 根据身份证获取业务编号
- productNum = dbController.getProductNum(queryInfoCardId);
- pboc = PBOC()
- # print(queryInfoCardId)
- if productNum == "CPA0100743":
- jarTxt = pboc.calc(txt_path,coopNum);
- logger.info(jarTxt)
- except:
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- # logging.log(logging.ERROR, info[2])
- logger.error(traceback.extract_tb(info[2], 1))
- def invokeLocal(queryInfoCardId,txt_path):
- try:
- productNum = getProductNum(queryInfoCardId)
- bizNum = getBizNum(queryInfoCardId)
- if productNum == "CPA0100734":#快牛
- businessInfo = {}
- with open(txt_path,encoding='utf-8') as file_obj:
- content = file_obj.read()
- businessInfo["result"]=content
- jarTxt = xyHttp.callLocal(businessInfo)
- if jarTxt["approveResult"]=="3":
- logger.info(bizNum+"\t"+"拒绝\t"+jarTxt["rule"])
- else:
- logger.info(bizNum+"\t"+"通过")
- print(txt_path+file)
- except:
- info = sys.exc_info()
- logger.error(info[0])
- logger.error(info[1])
- # logging.log(logging.ERROR, info[2])
- logger.error(queryInfoCardId)
- logger.error(traceback.extract_tb(info[2], 1))
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- #上传审批结果
- def uploadAudit(result,businessNum):
- approvalType = result["approveResult"]
- if approvalType=="1":
- approvalOpinion = "征信通过"
- approvalType = "4"
- else:
- approvalOpinion = "征信拒绝"
- approvalType = "3"
- taskKey = config.get("baseconf","taskKey")
- appoveApiUrl = config.get("baseconf","appoveApiUrl")
- key = config.get("baseconf", "AESKey")
- data = {"header":{
- "ticket": "2938123198320412343",
- "timestamp": int(int(round(time.time() * 1000+60*1000))),
- "nonce": config.get("baseconf", "nonce")
- },
- "body":{"approvalType": approvalType, "businessNum": businessNum,"taskKey":taskKey,"approvalOpinion":approvalOpinion}}
- access_token = dbController.getToken()
- appoveApiUrl = appoveApiUrl+"?access_token="+access_token
- headers = {"Content-Type": "application/json"}
- jsonStr = json.dumps(data);
- jsonStr = jsonStr.replace('"',"\\\"")#必须替换才行
- logger.info(jsonStr)
- pboc = PBOC();
- encryData = pboc.encrypt(jsonStr,key)
- encryData = encryData[0:len(encryData)-2]
- logger.info(encryData)
- response = requests.post(appoveApiUrl, data=encryData,headers=headers)
- text = response.text
- p = PrpCrypt(key)
- resultText = p.decrypt(text)
- logger.info(businessNum + "#" + "upload_result:" + resultText)
- if __name__ == '__main__':
- txt_path = "D:/mydocument/myprojects/creditreport/parse/kcdTxt/"
- txt_path= "D:/mydocument/myproject/git/parse/"
- if isPlt=="1":
- txt_path = "D:/KcdTxt/"
- # invokePboc("23012719900301108X", txt_path + "张玉峰_370628197901034617.txt")
- dirList = ""
- for file in os.listdir(txt_path):
- if file.endswith("txt"):
- arF = file.split("_")
- if len(arF)>=2:
- print(arF[1].replace(".txt",""))
- # invokePboc(arF[1].replace(".txt",""), txt_path+file)
- invokeLocal(arF[1].replace(".txt",""), txt_path+file)
|