login.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # coding=utf-8
  2. import base64
  3. from Crypto.PublicKey import RSA
  4. from Crypto.Cipher import PKCS1_v1_5
  5. from library.yinkayo.api.base import ApiBase
  6. from library.yinkayo.constants import PUBLIC_KEY
  7. class Login(ApiBase):
  8. @staticmethod
  9. def _get_cipher_text(*args):
  10. pubK = "-----BEGIN RSA PUBLIC KEY-----\n" + PUBLIC_KEY + "\n-----END RSA PUBLIC KEY-----"
  11. encryptor = PKCS1_v1_5.PKCS115_Cipher(RSA.importKey(pubK))
  12. cipherS = ",".join(args)
  13. encrypted_data = encryptor.encrypt(cipherS.encode("ISO-8859-1"))
  14. cipherT = base64.b64encode(encrypted_data)
  15. return cipherT
  16. def login(self):
  17. customer, operator, password = self._client.load_login_info()
  18. cipherT = self._get_cipher_text(customer, operator, password)
  19. publicK = PUBLIC_KEY
  20. data = {
  21. "JKeypublic": publicK,
  22. "Loginciphertext": cipherT,
  23. }
  24. response = self._post("/WebAPI/Login/ClientLogin", **data)
  25. cookies = response.cookies.get_dict()
  26. return cookies