Python

Updated by lei_jiang

import base64
import hashlib
import json
import logging
import random
import string
import time

import requests
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad

APPID = 'xxxxxx'
SECRETKEY = 'xxxxxxxxx'
BASEURL = 'http://local.morelogin.com:40000'


def generateRandom(length=6):
characters = string.ascii_letters + string.digits
random_string = ''.join(random.choice(characters) for _ in range(length))
return random_string


def generateNonceId():
return str(int(time.time()* 1000)) + generateRandom()


def md5Encode(nonceId):
md5 = hashlib.md5()
md5.update((APPID + nonceId + SECRETKEY).encode('utf-8'))
return md5.hexdigest() # Get the encrypted string


def requestHeader():
nonceId = generateNonceId()
md5Str = md5Encode(nonceId)
return {
'X-Api-Id': APPID,
'Authorization': md5Str,
'X-Nonce-Id': nonceId
}


def uploadFile(): //Cloud Phone-Uploading files
requestPath = '/api/cloudphone/uploadFile' # todo
filePath = 'D:/tmp/test.xlsx'
filename = 'text.xlsx'
data = {'id': '1563844316954857'}
headers = requestHeader()
response = requests.post(BASEURL + requestPath, files={'file': (filename,open(file=filePath, mode='rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')}, data=data, headers=headers)
print(response.content)


def create(): //Creating a Cloud Phone Profile
requestPath = '/api/cloudphone/create' # todo
data = {'quantity': 1}
headers = requestHeader()
headers['Content-Type'] ='application/json'
response = requests.post(BASEURL + requestPath, json=data, headers=headers)
print(response.content)



if __name__ == '__main__':
uploadFile()
# create()


How did we do?