1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import requests import base64 from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5 import os
def encode_RSA(secret): public_key = '''-----BEGIN RSA PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAulJs+6YSbEQIDAQAB -----END RSA PUBLIC KEY----- ''' secret = secret.encode('utf-8') rsakey = RSA.importKey(public_key) cipher = Cipher_pkcs1_v1_5.new(rsakey) cipher_text = base64.b64encode(cipher.encrypt(secret)) return cipher_text
def getToken(secret): url = 'http://ip:1234/api/ec/dev/auth/applytoken' headers = {'appid': 'jictai','secret':secret} response = requests.post(url, headers=headers ) return response
def uploadFile(token,userid,category,path,filename): url = r'http://ip:1234/api/doc/upload/uploadFile2Doc' headers = { 'token': token, 'appid': 'jictai', 'userid' : userid } files=[ ('file',(filename,open(os.path.join(path,filename),'rb'))) ] data = { "category" : category } response = requests.request("POST", url, headers=headers,data=data,files=files) return response if __name__ == '__main__': secret = '81ab3ed5b33' secretRSA = encode_RSA(secret) userid = encode_RSA('683') response = getToken(secretRSA) if response.status_code == 200 : token = response.json()['token'] print(token) result = uploadFile(token=token,userid=userid,category='91',path=r'C:\Users\admin\Downloads',filename='a.jpg') print(result.text)
|