Skip to content

Commit 4506a02

Browse files
committed
add appstore
1 parent 9e5b5e5 commit 4506a02

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

appstore/requirement.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Python 3 requirements.txt
2+
3+
requests==2.26.0
4+
requests-toolbelt==0.9.1

appstore/upgradeAppVersion.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
import random
3+
import time
4+
import requests
5+
import hmac
6+
import hashlib
7+
8+
AppID = 'Your AppID'
9+
AppKey = 'Your AppKey'
10+
11+
# doc : https://developer.sunmi.com/docs/zh-CN/cdixeghjk491/faceghjk502
12+
url = 'https://openapi.sunmi.com/v2/appstore/appstore/app/upgradeAppVersion'
13+
package_name = 'Your package name'
14+
15+
# sign method
16+
def sign(json_body, timestamp, nonce, appID, appKey):
17+
message = (json_body + appID + timestamp + nonce).encode('utf-8') # encode to bytes
18+
print('message=', message)
19+
return hmac.new(appKey.encode('utf-8'), message, hashlib.sha256).hexdigest()
20+
21+
# get current timestamp
22+
timestamp = str(int(time.time())) # example: '1700044792'
23+
nonce = str(random.randint(100000, 999999)) # example: '123456'
24+
25+
26+
# example:
27+
obj = {
28+
"package_name": package_name
29+
}
30+
31+
json_body = json.dumps(obj)
32+
print('json_body=', json_body)
33+
sign_str = sign(json_body, timestamp, nonce, AppID, AppKey)
34+
print('sign_str=', sign_str)
35+
36+
headers = {
37+
'Content-Type': 'application/json',
38+
'User-Agent': 'Python3-Sunmi-Demo',
39+
'Sunmi-Timestamp': timestamp,
40+
'Sunmi-Sign': sign_str,
41+
'Sunmi-Nonce': nonce,
42+
'Sunmi-Appid': AppID,
43+
}
44+
45+
response = requests.post(url, json=obj, headers=headers)
46+
print(response.status_code)
47+
print(response.json())

appstore/uploadApk.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This is a sample Python script.
2+
import json
3+
import random
4+
import time
5+
import requests
6+
import hmac
7+
import hashlib
8+
from requests_toolbelt.multipart.encoder import MultipartEncoder
9+
10+
AppID = 'Your AppID'
11+
AppKey = 'Your AppKey'
12+
13+
# doc : https://developer.sunmi.com/docs/zh-CN/cdixeghjk491/faceghjk502
14+
url = "https://openapi.sunmi.com/v2/midplat/filecore/file/uploadApk"
15+
file_path = 'your_apk.apk'
16+
file_path = 'application.apk'
17+
18+
19+
# sign method
20+
def sign(json_body, timestamp, nonce, appID, appKey):
21+
message = (json_body + appID + timestamp + nonce).encode('utf-8') # encode to bytes
22+
print('message=', message)
23+
return hmac.new(appKey.encode('utf-8'), message, hashlib.sha256).hexdigest()
24+
25+
26+
# calculate file md5
27+
def calculate_md5(file_path):
28+
with open(file_path, 'rb') as f:
29+
data = f.read()
30+
md5_hash = hashlib.md5(data).hexdigest()
31+
return md5_hash
32+
33+
34+
# get current timestamp
35+
timestamp = str(int(time.time())) # example: '1700044792'
36+
nonce = str(random.randint(100000, 999999)) # example: '123456'
37+
json_body = json.dumps({
38+
'md5': calculate_md5(file_path),
39+
'file_type_key': 'appstore_apk',
40+
})
41+
42+
sign_str = sign(json_body, timestamp, nonce, AppID, AppKey)
43+
# sign_str = sign(json.dumps(obj), timestamp, nonce, AppID, AppKey)
44+
print('sign_str=', sign_str)
45+
46+
# 创建一个MultipartEncoder对象
47+
multipart_data = MultipartEncoder(
48+
fields={
49+
'check': 'no',
50+
'params': json_body,
51+
'file': (file_path, open(file_path, 'rb'), 'application/octet-stream')
52+
}
53+
)
54+
55+
headers = {
56+
'User-Agent': 'Python3-Sunmi-Demo',
57+
'Content-Type': multipart_data.content_type,
58+
'Sunmi-Timestamp': timestamp,
59+
'Sunmi-Nonce': nonce,
60+
'Sunmi-Appid': AppID,
61+
'Sunmi-Sign': sign_str,
62+
}
63+
64+
response = requests.post(url, data=multipart_data, headers=headers)
65+
print(response.status_code)
66+
print(response.json())
67+
print('apk_uuid=', response.json()['data']['uuid'])

0 commit comments

Comments
 (0)