import random
from django.shortcuts import render, HttpResponse
from gongju.tengxun.sms import send_sms_single
# Create your views here.
def 短信(request):
code = random.randrange(1000, 9999) # 生成随机的验证码,在1000和9999之间
res = send_sms_single("18888888888", "548760", [code, ]) # 实例化单发送短信的对象
# print(res) {'result': 1014, 'errmsg': 'package format error, sdkappid not have this tpl_id', 'ext': ''}
if res['result'] == 0:
return HttpResponse('发送成功')
return HttpResponse(res['errmsg'])
def 短信(request):
code = random.randrange(1000, 9999) # 生成随机的验证码,在1000和9999之间
tpl = request.GET.get('tpl') # 得到用户从浏览器传入的值
tpl_id = settings.TENGXUN_SMS_MUBAN.get(tpl)
if not tpl_id:
return HttpResponse('模板不存在')
res = send_sms_single("16633360886", tpl_id, [code, ]) # 实例化单发送短信的对象
# print(res) {'result': 1014, 'errmsg': 'package format error, sdkappid not have this tpl_id', 'ext': ''}
if res['result'] == 0:
return HttpResponse('发送成功')
return HttpResponse(res['errmsg'])
手机号还需要完善