invokePboc.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import subprocess
  2. import chardet
  3. import sys
  4. import json
  5. import os;
  6. class PBOC(object):
  7. # def __init__(self):
  8. # self.jsonFile = jsonFile
  9. # self.coop_business_num = coop_business_num
  10. def calc(self,jsonFile,coop_business_num):
  11. command = 'java -cp ".;rms-credit-1.0.1-SNAPSHOT-jar-with-dependencies.jar" -Dfile.encoding=UTF-8 JuziMain "'+jsonFile+'" "'+coop_business_num+'"'
  12. # arg0 = os.path.abspath(os.path.dirname(__file__))
  13. # cmd = ["cd "+arg0+"\n",command]
  14. # new_cmd = "\n".join(cmd)
  15. stdout,stderr = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
  16. encoding = chardet.detect(stdout)["encoding"]
  17. result = stdout.decode(encoding)
  18. return result
  19. def calcXxw(self,coopBussinessNum,customerNum,jsonFile):
  20. command = 'java -cp "credit-1.2-SNAPSHOT.jar;fastjson-1.2.62.jar" -Dfile.encoding=UTF-8 com.jf.credit.CreateUtils "'+coopBussinessNum+'" "'+customerNum+'" "'+jsonFile+'" '
  21. # arg0 = os.path.abspath(os.path.dirname(__file__))
  22. # cmd = ["cd "+arg0+"\n",command]
  23. # new_cmd = "\n".join(cmd)
  24. stdout,stderr = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
  25. encoding = chardet.detect(stdout)["encoding"]
  26. result = stdout.decode(encoding)
  27. return result
  28. def encrypt(self,data,key):
  29. command = 'java -cp ".;" -Dfile.encoding=UTF-8 AesUtils "' + data+'" "'+ key+'" "encrypt"'
  30. stdout, stderr = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  31. print(stdout)
  32. encoding = chardet.detect(stdout)["encoding"]
  33. print(encoding)
  34. encoding = "ascii" #yuan,java调用有问题
  35. result = stdout.decode(encoding)
  36. return result
  37. def decrypt(self,data,key):
  38. command = 'java -cp ".;" -Dfile.encoding=UTF-8 AesUtils "' + data+'" "'+ key+'" "decrypt"'
  39. stdout, stderr = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  40. encoding = chardet.detect(stdout)["encoding"]
  41. print("encoding是")
  42. print(encoding)
  43. # encoding = "utf-8"
  44. result = stdout.decode(encoding)
  45. return result
  46. # javac - cp
  47. # ".;credit-1.1-SNAPSHOT.jar;fastjson-1.2.62.jar"
  48. # Main.java
  49. # java - cp
  50. # ".;credit-1.1-SNAPSHOT.jar;fastjson-1.2.62.jar" - Dfile.encoding = UTF - 8
  51. # Main
  52. # pause
  53. if __name__ == '__main__':
  54. pboc = PBOC()
  55. result = json.loads(pboc.calc("D:/mydocument/myprojects/creditreport/parse/安静513723198707074647.txt","coop_business_num"))
  56. 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\"}}"')
  57. print(result)