add polls
This commit is contained in:
parent
e5ebc32cd7
commit
3af6aec8fb
|
@ -1,7 +1,30 @@
|
|||
from aliyunsdkcore.client import AcsClient
|
||||
from aliyunsdkcore.request import CommonRequest
|
||||
|
||||
import random
|
||||
|
||||
def sent_sms_code(phone):
|
||||
pass
|
||||
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)
|
||||
return random.randint(1000, 9999)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sent_sms_code('13993199566')
|
|
@ -66,8 +66,13 @@ def send_code(request):
|
|||
code = generate_code()
|
||||
now = datetime.datetime.now()
|
||||
after_10mins = now + datetime.timedelta(minutes=10)
|
||||
VerifyCode.objects.create(code=code, phone=phone, category=category)
|
||||
return JsonResponse({'status': 'success'})
|
||||
response = send_sms_code(phone, code)
|
||||
result = response.decode('utf8')
|
||||
if "OK" in result:
|
||||
VerifyCode.objects.create(code=code, phone=phone, category=category)
|
||||
return JsonResponse({'status': 'success'})
|
||||
return JsonResponse({'status': 'error', 'message': '验证码发送失败'})
|
||||
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
|
|
|
@ -3,3 +3,5 @@ django-bootstrap3
|
|||
django-simple-captcha
|
||||
psycopg2-binary
|
||||
django-cors-headers
|
||||
aliyun-python-sdk-core-v3
|
||||
|
||||
|
|
Loading…
Reference in New Issue