123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import subprocess
- import chardet
- import sys
- import json
- import os;
- class PBOC(object):
- # def __init__(self):
- # self.jsonFile = jsonFile
- # self.coop_business_num = coop_business_num
- def calc(self,jsonFile,coop_business_num):
- command = 'java -cp ".;rms-credit-1.0.1-SNAPSHOT-jar-with-dependencies.jar" -Dfile.encoding=UTF-8 JuziMain "'+jsonFile+'" "'+coop_business_num+'"'
- # arg0 = os.path.abspath(os.path.dirname(__file__))
- # cmd = ["cd "+arg0+"\n",command]
- # new_cmd = "\n".join(cmd)
- stdout,stderr = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
- encoding = chardet.detect(stdout)["encoding"]
- result = stdout.decode(encoding)
- return result
- def calcXxw(self,coopBussinessNum,customerNum,jsonFile):
- command = 'java -cp "credit-1.2-SNAPSHOT.jar;fastjson-1.2.62.jar" -Dfile.encoding=UTF-8 com.jf.credit.CreateUtils "'+coopBussinessNum+'" "'+customerNum+'" "'+jsonFile+'" '
- # arg0 = os.path.abspath(os.path.dirname(__file__))
- # cmd = ["cd "+arg0+"\n",command]
- # new_cmd = "\n".join(cmd)
- stdout,stderr = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
- encoding = chardet.detect(stdout)["encoding"]
- result = stdout.decode(encoding)
- return result
- def encrypt(self,data,key):
- command = 'java -cp ".;" -Dfile.encoding=UTF-8 AesUtils "' + data+'" "'+ key+'" "encrypt"'
- stdout, stderr = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
- print(stdout)
- encoding = chardet.detect(stdout)["encoding"]
- print(encoding)
- encoding = "ascii" #yuan,java调用有问题
- result = stdout.decode(encoding)
- return result
- def decrypt(self,data,key):
- command = 'java -cp ".;" -Dfile.encoding=UTF-8 AesUtils "' + data+'" "'+ key+'" "decrypt"'
- stdout, stderr = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
- encoding = chardet.detect(stdout)["encoding"]
- print("encoding是")
- print(encoding)
- # encoding = "utf-8"
- result = stdout.decode(encoding)
- return result
- # javac - cp
- # ".;credit-1.1-SNAPSHOT.jar;fastjson-1.2.62.jar"
- # Main.java
- # java - cp
- # ".;credit-1.1-SNAPSHOT.jar;fastjson-1.2.62.jar" - Dfile.encoding = UTF - 8
- # Main
- # pause
- if __name__ == '__main__':
- pboc = PBOC()
- result = json.loads(pboc.calc("D:/mydocument/myprojects/creditreport/parse/安静513723198707074647.txt","coop_business_num"))
- result = pboc.encrypt('java -cp ".;" -Dfile.encoding=UTF-8 AesUtils "{\"header\": {\"ticket\": \"2938123198320412343\", \"timestamp\": 1591948699998, \"nonce\": \"DJi23ishd723ai\"}, \"body\": {\"approvalType\": \"3\", \"businessNum\": \"\", \"taskKey\": \"WF1001HUABEI1002HTSQ\", \"approvalOpinion\": \"\u5f81\u4fe1\u5ba1\u6279\u901a\u8fc7\"}}"')
- print(result)
|