예제 #1
0
def send_sms(phone,code):
    x = YunTongXin(settings.SMS_ACCOUNT_ID,
                   settings.SMS_ACCOUNT_TOKEN,
                   settings.SMS_APP_ID,
                   settings.SMS_TEMPLATE_ID)
    res = x.run(phone, code)
    return res
예제 #2
0
def sms_view(request):

    json_str = request.body
    json_obj = json.loads(json_str)
    phone = json_obj['phone']

    #检查 手机号是否已经注册

    #检查 当前手机号 有没有 已存在的验证码
    cache_key = 'sms_%s'%(phone)
    old_code = cache.get(cache_key)
    if old_code:
        result = {'code':10112, 'error':'qing shaohou zailai'}
        return JsonResponse(result)

    code = random.randint(1000, 9999)
    #存储验证码
    cache.set(cache_key, code, 65)
    print('---send code %s'%(code))
    #TODO 发送
    x = YunTongXin(settings.SMS_ACCOUNT_ID, settings.SMS_ACCOUNT_TOKEN, settings.SMS_APP_ID, settings.SMS_TEMPLATE_ID)
    res = x.run(phone, code)
    print('---send sms result is %s'%(res))

    return JsonResponse({'code':200})
예제 #3
0
def sms_view(request):
    # 获取前端提交的数据
    json_str = request.body
    # 反序列化
    json_obj = json.loads(json_str)
    # 获取手机号码
    phone = json_obj['phone']
    print(phone)
    # 生成随机的验证码发给手机
    code = random.randint(100000, 999999)
    # 将验证码放到redis中
    cache_key = f'sms_{phone}'
    cache.set(cache_key, code, 180)  # 有效时间3分钟,和前端同步
    # 向指定的手机号发送短信验证
    # account_id = '8aaf0708773733a8017741b5dc9904ae'
    # auth_token = 'e7ca8f6377ef406ea0afec3f73e28d36'
    # AppId = '8aaf0708773733a8017741b5dd6804b4'
    # template_id = '1'
    # 这些都写到配置文件里面去
    account_id = settings.ACCOUNT_ID
    auth_token = settings.AUTH_TOKEN
    AppId = settings.APPID
    template_id = settings.TEMPLATE_ID
    # 不能用内置的setting? why
    # 必须全大写!!!!!
    # setting里设置的变量必须全大写

    x = YunTongXin(account_id, auth_token, AppId, template_id)
    res = x.run(phone, code)
    print(res)
    # {"statusCode":"000000","templateSMS":{"smsMessageSid":"31a508ec301d44e6a3e8dc1e7a82d683","dateCreated":"20210127143926"}}

    return JsonResponse({'code': 200})
예제 #4
0
파일: tasks.py 프로젝트: gary-gggggg/gary
def send_sms(phone, code):
    # 1创建云通信对象
    x = YunTongXin(settings.ACCOUNT_SID, settings.AUTH_TOKEN, settings.APP_ID,
                   settings.TID)
    # 2发送通信
    res = x.run(phone, code)
    # 3 打印返回信息
    print(res)
예제 #5
0
def send_sms(phone, code):
    config = {
        'accountSid': '8aaf0708762cb1cf01772441bc5657d5',
        'accountToken': '6a07a9fe6c5c49899d9b29e53d430773',
        'appId': '8aaf0708762cb1cf01772441bd3a57dc',
        'templateId': '1',
    }
    yun = YunTongXin(**config)
    res = yun.run(phone, code)
    return res
예제 #6
0
파일: views.py 프로젝트: seabedforest/study
def send_sms(phone, code):
    config = {
        "accountSid": settings.SMS_ACCOUNT_ID,
        "accountToken": settings.SMS_ACCOUNT_TOKEN,
        "appId": settings.SMS_APP_ID,
        "templateId": settings.SMS_TEMPALE_ID,
    }
    f = YunTongXin(**config)
    res = f.run(phone, code)
    print(res)
예제 #7
0
파일: tasks.py 프로젝트: 18372689867/bo_ke
def send_sms(phone, code):
    # 一般情况下,写到配置文件中
    aid = '8a216da87380115d017389546bb802f5'
    atoken = '12444d5592d247b2af0e5cc10bf666a0'
    appid = '8a216da87380115d017389546c9e02fb'
    tid = '1'

    # 1 创建云通信对象
    x = YunTongXin(aid, atoken, appid, tid)
    # 2 发送短信
    res = x.run(phone, code)
    # 3 返回信息
    print(res)
예제 #8
0
파일: views.py 프로젝트: ywzq87bzx/code
def sms_view(request):
    json_str = request.body
    py_obj = json.loads(json_str)
    phone = py_obj['phone']
    code = random.randint(1000, 9999)
    print(phone, code)
    #1.先验证码暂存,以备注册使用
    #2 发送短信验证码
    x = YunTongXin(settings.SMS_ACCOUNT_ID, settings.SMS_ACCOUNT_TOKEN,
                   settings.SMS_APP_ID, settings.SMS_TEMPLATE_ID)
    res = x.run(phone, code)
    print(res)
    return JsonResponse({'code': 200})
예제 #9
0
파일: views.py 프로젝트: jiangfj/OA
def sendSms(request):
    json_str = request.body
    py_obj = json.loads(json_str)
    phone = py_obj['phone']
    code = random.randint(1000, 9999)
    print(phone, code)
    cache_key = 'sms_%s' % phone
    cache.set(cache_key, code, 200)

    x = YunTongXin(settings.SMS_ACCOUNT_ID, settings.SMS_ACCOUNT_TOKEN,
                   settings.SMS_APP_ID, settings.SMS_TEMPLATE_ID)
    res = x.run(phone, code)
    print(res)
    return JsonResponse({'code': 200})
예제 #10
0
파일: tasks.py 프로젝트: AI888666/blog
def send_sms_c(phone, code):
    """
        发送短息
    :param phone: 手机号
    :param code: 随机码
    :return:
    """
    config = {
        "accountSid": "8aaf070875da65fe0175db622dbd0075",
        "accountToken": "15c26146555946b49ff77b342f2d1289",
        "appId": "8aaf070875da65fe0175db622ed0007b",
        "templateId": "1"
    }
    yun = YunTongXin(**config)
    res = yun.run(phone, code)
    return res
예제 #11
0
def send_sms(phone, code):
    # 向指定的手机号发送短信验证
    # account_id = '8aaf0708773733a8017741b5dc9904ae'
    # auth_token = 'e7ca8f6377ef406ea0afec3f73e28d36'
    # AppId = '8aaf0708773733a8017741b5dd6804b4'
    # template_id = '1'
    # 这些都写到配置文件里面去
    account_id = settings.ACCOUNT_ID
    auth_token = settings.AUTH_TOKEN
    AppId = settings.APPID
    template_id = settings.TEMPLATE_ID
    # 不能用内置的setting? why
    # 必须全大写!!!!!
    # setting里设置的变量必须全大写

    x = YunTongXin(account_id, auth_token, AppId, template_id)
    res = x.run(phone, code)
    return res
예제 #12
0
def sms_views(request):
    # 1 获取前端提交的数据
    json_str = request.body
    # 2 json串转为对象
    json_obj = json.loads(json_str)
    # 3获得手机号
    phone = json_obj['phone']
    # 4 生成随机的验证码
    code = random.randint(100000, 999999)
    # 5 将验证码存进缓存(redis)
    cache_key = f'sms_{phone}'
    cache.set(cache_key, code, 180)
    print(phone, code)
    # 6 向指定的手机号发送短信验证请求
    # 1创建云通信对象
    x = YunTongXin(settings.ACCOUNT_SID, settings.AUTH_TOKEN, settings.APP_ID, settings.TID)
    # 2发送通信
    res = x.run(phone, code)
    # 3 打印返回信息
    print(res)
    return JsonResponse({'code': 200})
예제 #13
0
파일: views.py 프로젝트: chenfang0927/-123
def sms_view(request):
    json_str = request.body
    json_obj = json.loads(json_str)
    phone = json_obj['phone']
    print(phone)
    # 防止用户多次点击按钮重复发送验证码
    cache_key = 'sms_%s' % (phone)
    old_code = cache.get(cache_key)
    if old_code:
        result = {'code': 10112, 'error': '请稍后再来'}
        return JsonResponse(result)
    # 生成随机码
    code = random.randint(1000, 9999)
    print(code)
    # 放到缓存中,有效期65秒
    cache.set(cache_key, code, 65)
    # 同步发送
    x = YunTongXin(settings.SMS_ACCOUNT_ID, settings.SMS_ACCOUNT_TOKEN,
                   settings.SMS_APP_ID, settings.SMS_TEMPLATE_ID)
    res = x.run('18941169596', code)
    print(res)

    return JsonResponse({'code': 200})
예제 #14
0
def send_sms(phone, code):
    yuntongxin = YunTongXin(accountSid=settings.ACCOUNT_ID,
                            accountToken=settings.AUTH_TOKEN,
                            appId=settings.APPID,
                            templateId=settings.TEMPLATE_ID)
    yuntongxin.run(phone, code)