让您全面了解并上手亿速云产品
常见入门级使用教程
对外 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