newmediamonitoring/polls/utils.py

30 lines
1004 B
Python

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import random
def sent_sms_code(phone):
client = AcsClient('LTAIBfgqfC2fpIDF', 'ocBzC2UvguYbyR6coNGYdPiV5HdWbC', 'cn-hangzhou')
request = CommonRequest()
request.set_accept_format('json')
request.set_domain('dysmsapi.aliyuncs.com')
request.set_method('POST')
request.set_protocol_type('https') # https | http
request.set_version('2017-05-25')
request.set_action_name('SendSms')
request.add_query_param('RegionId', "cn-hangzhou")
request.add_query_param('PhoneNumbers', "13993199566")
request.add_query_param('SignName', "短信验证")
request.add_query_param('TemplateCode', "SMS_12330409")
request.add_query_param('TemplateParam', '{"number":"1111"}')
response = client.do_action(request)
print(type(response.decode('utf8')))
def generate_code():
return random.randint(1000, 9999)
if __name__ == '__main__':
sent_sms_code('13993199566')