コード例 #1
0
def sms_captcha():
    '''
    实现:
    1. telephone
    2. timestamp
    3. md5(ts+telephone+salt)
    :return:
    '''
    # 1. 申明验证表单验证对象
    form = SMSCaptchaForm(request.form)
    # 2. 通过验证
    if form.validate():
        # 2.1 拿到手机号
        telephone = form.telephone.data
        # 2.2 生成验证码
        captcha = Captcha.gene_text(number=4)
        print('发送的短信验证码是:', captcha)
        # 2.3 发送验证码,成功时:
        if alidayu.send_sms(telephone, code=captcha):

            # ⚠️:这里将验证码保存在缓存服务器中
            zlcache.set(telephone, captcha, timeout=60)

            return restful.success()
        # 发送验证码,失败时:
        else:
            return restful.params_error()
    else:
        return restful.params_error(message='参数错误!')
コード例 #2
0
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        code = Captcha.gene_text()
        cache.set(key=telephone, value=code)
        send_sms_captcha(telephone=telephone, message=code)
        return restful.success(message='短信发送成功')  #Celery 异步发送
コード例 #3
0
def sms_captcha():
    telephone = request.args.get('telephone')
    if not telephone:
        return restful.parmaserror(message='请传入手机号码!')
    captcha = Captcha.gene_text(number=4)
    if alidayu.send_sms(telephone, code=captcha):
        return restful.success()
    else:
        return restful.parmaserror(message='短信验证码发送失败!')
コード例 #4
0
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        print('发送的短信验证码是:', captcha)
        send_sms_captcha(telephone, captcha)
        return restful.success()
    else:
        return restful.params_error(message='参数错误!')
コード例 #5
0
ファイル: views.py プロジェクト: GavinYGM/zlbbs
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        capt = Captcha.gene_text(number=4)
        # 发送验证码
        zlcache.set(telephone, capt)
        print("向手机{}发送验证码:{}".format(telephone, capt))
        return restful.success()
    else:
        return restful.params_error("手机号码格式有误")
コード例 #6
0
ファイル: views.py プロジェクト: ForsetiRe/seven_cms
def sms_captcha(request):
    code = Captcha.gene_text(4)  # 生成随机字符串
    print("短信验证码:%s" % code)
    # 接收手机号
    # /sms_captcha/?telephone=xxxxxxxxxxxx
    telephone = request.GET.get('telephone')
    cache.set(telephone, code, 5 * 60)

    # 调用第三方发送短信验证码的接口
    send_sms(telephone, code)
    return restful.success()
コード例 #7
0
 def get(self):
     #/smscode?tel=xxxxx
     telephone = request.args.get("tel")
     # telephone = request.values.get("tel")
     accountSid="8a216da86f17653b016f3b4046b218ab"
     accountToken = "ac156972012a43dab1782f1f89995ac9"
     appId ="8a216da86f17653b016f3b40471818b2"
     rest = CCPRestSDK.REST(accountSid,accountToken,appId)
     captcha = Captcha.gene_text(number=4)
     result = rest.sendTemplateSMS(telephone, [captcha], "1")
     # result= rest.sendTemplateSMS(telephone,["1234"],"1")
     print(result)
     return Response("success")
コード例 #8
0
ファイル: views.py プロジェクト: spxfen17/xfbbs
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        if alidayu.send_sms(telephone,code=captcha):
            xfcache.set(telephone,captcha)
            return restful.success()
        else:
            # return restful.params_error()
            return restful.success()
    else:
        return restful.params_error(message='参数错误!')
コード例 #9
0
def sms_captcha():
    #teltphone
    #timestamp
    #md5(timestamp+teltphone+salt)
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        zlcache.set(telephone, captcha)
        #感觉此处应该加delay老师没加
        send_sms_captcha.delay(telephone, captcha)
        return restful.success()
    else:
        return restful.params_error(message='参数错误!')
コード例 #10
0
ファイル: views.py プロジェクト: Erick-LONG/flbbs
def sms_captcha():
    #telephone
    #timestamp
    #md5(ts +telephone+salt)
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        if alidayu.send_sms(telephone, code=captcha):
            return restful.success()
        else:
            return restful.params_error(message='短信验证码发送失败')
    else:
        return restful.params_error(message='参数错误')
コード例 #11
0
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(4)
        if send_sms_captcha(telephone, captcha):
            zlcache.set(telephone,captcha)
            print('本次的手机验证码是:%s' %captcha)
            return restful.success()
        else:
            zlcache.set(telephone, captcha)
            return restful.params_error(message='参数错误')
    else:
        return restful.params_error(message='参数错误')
コード例 #12
0
ファイル: views.py プロジェクト: PythonWebProject/Flask_BBS
def sms_captcha():
    form = SMSCaptchaForm(request.form)

    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(4)
        print('发送的短信验证码:{}'.format(captcha))
        if send_msg.send_mobile_msg(telephone, captcha) == 0:
            clcache.save_captcha(telephone, captcha)
            return restful.success()
        else:
            return restful.params_error(message='发送失败')
    else:
        return restful.params_error(message='参数错误')
コード例 #13
0
def index():
    # md5(timesleep+telephone+salt)
    form = SMSCaptcha(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        print('sms is {}'.format(captcha))
        if alidayu.send_sms(telephone, code=captcha):
            zlcache.set(telephone, captcha)
            return restful.success()
        # return restful.params_error(message='短信验证码发送失败')
        zlcache.set(telephone, captcha)
        return restful.success()
    return restful.params_error(message='参数错误')
コード例 #14
0
ファイル: views.py プロジェクト: sancklan/rmbbsDemo
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        # result = alidayuSMS.sendSMS(telephone, code=captcha)
        result = send_sms_captcha.delay(telephone=telephone, code=captcha)
        if result:
            print("短信验证码:" + captcha)
            rmcache.set(telephone, captcha, timeout=600)  #手机号作为key
            return restful.success()
        else:
            return restful.param_error(message="验证码发送失败!")
    else:
        return restful.param_error(message=form.get_error())
コード例 #15
0
def sms_captcha():
    form = SmsForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)

        if alidayu.send_sms(telephone, captcha=captcha):
            # 把验证码放入memcache,与用户提交的对比
            mbcache.set(telephone, captcha)
            return restful.success()
        else:
            mbcache.set(telephone, captcha)
            return restful.success()
    else:
        return restful.params_error(message='参数错误')
コード例 #16
0
ファイル: views.py プロジェクト: ewenliu/Python_Lesson_Learn
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        print('发送的短信验证码是:', captcha)
        # if smssender.send(telephone, captcha=captcha):
        # 屏蔽短信发送用以测试
        if True:
            blog_cache.set(telephone, captcha)
            return restful.success()
        else:
            return restful.params_error(message='短信验证码发送失败')
    else:
        return restful.params_error(message='参数错误!')
コード例 #17
0
ファイル: views.py プロジェクト: zzzz123321/BBS
def sms_captcha():
    #     telephone+timestamp+salt
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        if alidayu.send_sms(telephone, code=captcha):
            zlcache.set(telephone, captcha)  # 验证码保存到缓存中
            return restful.success()
        else:
            # return restful.paramas_error(message='参数错误')
            zlcache.set(telephone, captcha)  # 测试用
            return restful.success()
    else:
        return restful.params_error(message='参数错误')
コード例 #18
0
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        print(captcha)
        if sendsms.send_sms(telephone, captcha):
            rds.set(telephone, captcha)
            return restful.restful_success()
        else:
            # return restful.restful_servererror('服务器错误')
            rds.set(telephone, captcha)
            return restful.restful_success()
    else:
        return restful.restful_parameserror('参数错误')
コード例 #19
0
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)  #生成4位短信验证码
        print("发送的短信验证码是%s" % captcha)
        if alidayu.send_sms(telephone, code=captcha):
            zlcache.set(telephone,
                        captcha)  #将手机验证码存储到memcached种,telephone为KEY,captcha为值
            return restful.success()
        else:
            #return restful.parames_error("参数错误")
            zlcache.set(telephone, captcha)  ### 为了测试 就算阿里大于发送失败也存储到memcached
            return restful.success()  #用于测这里设置为成功!!!
    else:
        return restful.parames_error(message="参数错误")
コード例 #20
0
ファイル: views.py プロジェクト: zdwger/flask_bbsproject
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        print('发送短信验证码是:', captcha)
        send_sms_captcha(telephone, captcha=captcha)
        # if alidayu.send_sms(telephone,code=captcha):
        #     zlcache.set(telephone,captcha)
        #     return restful.success()
        # else:
        #     zlcache.set(telephone, captcha)
        #     # return restful.params_error()
        #     return restful.success()
    else:
        return restful.params_error(message='参数错误')
コード例 #21
0
ファイル: views.py プロジェクト: CZ2016/zedd
def sms_captcha():
     # 前台要发送过来的数据:
     # telephone
     # timestamp
     # md5(ts+telephone+salt)
     form=SMSCaptchaForm(request.form)
     if form.validate():
          telephone=form.telephone.data
          captcha=Captcha.gene_text(number=4)
          send_sms_captcha.delay(telephone,captcha) #使用celery异步发送
          # if Send_sms.send_sms(telephone,text=captcha):
          zlache.set(telephone,captcha,timeout=120)
          return restful.success()
          # else:
          #      return restful.paramserror(message='短信验证码发送失败')
     else:
          return restful.paramserror(message='参数错误')
コード例 #22
0
def sms_captcha():
#     telephone+timestamp+salt
    form=SMSCaptchaForm(request.form)
    if form.validate():
        telephone=form.telephone.data
        captcha=Captcha.gene_text(number=4)
        print('生成的短信验证码:%s'%captcha)
        # if alidayu.send_sms(telephone,code=captcha):
        #     zlcache.set(telephone,captcha)
        #     return restful.success()
        # else:
        #     # return restful.paramas_error(message='参数错误')
        #     zlcache.set(telephone,captcha)
        send_sms_captcha.delay(telephone,captcha)
        return restful.success()
    else:
        return restful.paramas_error(message='参数错误')
コード例 #23
0
ファイル: views.py プロジェクト: XiongYN/cnblog_bbs
def sms_captcha():
    sms_captcha_form = SmsCaptchaForm(request.form)
    if sms_captcha_form.validate():
        telephone = sms_captcha_form.telephone.data
        #生成随机的验证,之前图片那里有方法实现了,我们直接调用就行,生成6位的验证码
        radom_code = Captcha.gene_text(6)
        cont = '测试bbs,您的验证码为:%s' % (radom_code)
        params = {'code': cont}
        result = send_sms(telephone, params)
        dict_res = json.loads(result)
        if dict_res['code'] == 0:
            xcache.set(telephone,radom_code) #把手机号作为key
            return xjson.json_sucess('短信发送成功')
        else:
            return xjson.json_server_error('短信发送失败')
    else:
        return xjson.json_params_error('参数错误')
コード例 #24
0
ファイル: views.py プロジェクト: Flask-bbs/Flask--BBS_project
def sms_captcha():
    form = SMSCaptchaForm(request.form)               # 收集form表单信息
    
    if form.validate():                               # 表单信息存在
        # 接收数据
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)         # 生成4位验证码,这里生成的是验证码,要发送到手机端的,不能是图形验证码
        print("发送的手机验证码是:{}".format(captcha))
        
        # 验证发送成功状态码
        if send_phone_msg(telephone, captcha) == 0:                          # 返回成功的状态码为 0
            redis_captcha.redis_set(telephone, captcha)                      # 将telephone对应的手机验证码保存在Redis数据库中
            
            return restful.success()                                         # 返回成功信息提示框
        else:
            return restful.params_error("手机验证码发送失败")                 # 手机验证码发送失败
    else:
        return restful.params_error(message="参数错误")
コード例 #25
0
ファイル: views.py プロジェクト: peppamintz/bbs-
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=6)
        print('发送的短信验证码是:', captcha)
        resp = sms.send(telephone, {'code': captcha})
        print(resp.decode())
        data = sms.convert(resp)

        if data == 'OK':
            cache.set(telephone, captcha)
            print(cache.get(telephone))
            return restful.success()
        else:
            return restful.params_error(message='短信验证码发送失败!')
    else:
        return restful.params_error(message='参数错误')
コード例 #26
0
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data

        # 获取4为随机内容,范围为a-z, A-Z, 0-9
        captcha = Captcha.gene_text(number=4)
        # 发送短信
        result = yunpian.send_captcha(telephone, captcha=captcha)
        if result['code'] == 0:
            zlcache.set(telephone, captcha, 600)  # 存入memcache中
            return restful.success()
        elif result['code'] == 1:
            return restful.params_error(message=result['message'])
        else:
            return restful.params_error(message='服务器离家出走了,请稍后再试')
    else:
        return restful.params_error(message='参数错误')
コード例 #27
0
def sms_captcha():
    # telephone , timeStamp
    # md5(timeStamp + telephone + salt)
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        zlcache.set(telephone, captcha.lower())
        send_sms_captcha(telephone, captcha)
        return restful.success()
        # print(f"短信验证码: {captcha}", type(captcha))
        # if juheshuju.send(telephone, captcha=captcha):
        #     zlcache.set(telephone, captcha.lower())
        #     print(f"发送成功, 短信验证码: {captcha}", type(captcha))
        #     return restful.success()
        # else:
        #     # print(f"发送失败, 短信验证码: {captcha}", type(captcha))
        #     return restful.paramError('发送失败,请稍后再试!')
    return restful.paramError(message='参数错误!')
コード例 #28
0
def smsCaptcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(4)
        # sms_alidayu.send_sms(telephone, template_param=u"{'code':'%s'}" % captcha)
        # send_captcha(telephone, template_param=u"{'code':'%s'}" % captcha)
        resp = json.loads(
            send_captcha(telephone, template_param=u"{'code':'%s'}" % captcha))
        print(resp)
        if resp.get('Code') == 'OK':
            # 保存验证码到内存中
            cache.set(telephone, captcha.lower())

            return restful.success('发送成功')
        else:
            return restful.params_error(message='验证码发送失败')
    else:
        return restful.params_error(message='参数错误!')
コード例 #29
0
def sms_captcha():
#     telephone+timestamp+salt
    form=SMSCaptchaForm(request.form)
    if form.validate():
        telephone=form.telephone.data
        captcha=Captcha.gene_text(numbers=4).replace(" ","")
        print("发送的验证码是:",captcha)
        send_sms_captcha(telephone,captcha)
        # if alidayu.send_sms(telephone,code=captcha):
        #     #手机号码作为key,验证码作为value存到memcache中
        #     zlcache.set(telephone,captcha)
        #     return restful.success()
        # else:
        #      # return restful.paramas_error(message='参数错误')
        #      #开发中,失败的时候也写入进memcache
        #     zlcache.set(telephone,captcha)
        #     return restful.success()
    else:
        return restful.params_error(message='参数错误')
コード例 #30
0
def sms_captcha():
    """
    前台将手机号和时间戳和盐封装成一个字符串传给表单验证,通过验证才能发送验证码
    以手机号为键、短信验证码为值保存到redis缓存中
    :return:
    """
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        # 制作验证码时中间有空格字符串,需要使用空字符串代替空格字符串
        captcha = Captcha.gene_text(numbers=4).replace(" ", "")
        # 定义阿里类实例,使用api即可
        alidayu = Alidayu()
        if alidayu.send_sms(telephone, captcha):
            # 将相关的信息保存的redis缓存中
            cpcache.set(telephone, captcha, 60)
            return restful.success()
        else:
            return restful.params_error(message="参数错误!")
    return restful.params_error(message="参数错误!")