讓您全面了解并上手億速云產品
常見入門級使用教程
對外 API 開發文檔中心
您歷史提交的工單
您的每一條意見,我們都嚴謹處理
您的每一條建議,我們都認真對待
import requests
import json
import random
import urllib
import time
import base64
import hmac
from hashlib import sha1
def hash_hmac(key, code, sha1):
hmac_code = hmac.new(key.encode(), code.encode(), sha1)
return hmac_code.digest()
def send():
url = 'https://api.yisu.com/sms/sendSms'
accessId = '*****'
accessSecret = '*****'
params = {
'accessId': accessId,
'templateCode' : 100001,
'nonce': random.randint(10000000, 99999999),
'phone' : '13800000000',
'timestamp' : int(time.time()),
'templateVars' : json.dumps({"code":"123123","min":5}, separators=(',', ':'))
}
params_keys = list(params.keys())
params_keys.sort()
params_str = ""
for key in params_keys:
params_str += key + '=' + str(params[key]) + '&'
params_str = params_str[:-1]
sign = base64.b64encode(hash_hmac(accessSecret, params_str, sha1))
params['signature'] = str(sign,'utf-8')
res = requests.post(url, data=params, verify=False)
print(res.text)
if __name__ == '__main__':
send()
Copyright ? Yisu Cloud Ltd. All Rights Reserved. 2018 版權所有
廣州億速云計算有限公司 粵ICP備17096448號-1 粵公網安備 44010402001142號 增值電信業務經營許可證編號:B1-20181529