Example #1
0
File: sms.py Project: nancb/mywk
def new_phone_code(phone):
    code = ''.join([str(random.randint(0, 9)) for _ in range(4)])
    print(phone, code)
    # 保存到cache
    phone1 = "*" + phone
    rd.set(phone1, code)
    # 发送验证给用户
    send_sms_code(phone, code)
Example #2
0
def create_traffic_order():
    token = request.get_json().get('token', None)
    if cache.check_token(token):
        # 获取请求参数
        user_id_id = cache.get_token_user_id(token)
        req_data = request.get_json()
        payasset = req_data.get('payasset', None)
        tel = req_data.get('tel', None)
        if not all((payasset, tel)):
            return jsonify({
                'code': 401,
                'msg': '手机号和流量数值必须上传',
            })
        # payasset = get_tra_asset(phonetra)
        dao = cart_orderDao()
        cart_cal_rel = payasset
        # 优惠券ID
        voucher_id = request.get_json().get('voucher_id', None)
        vou_resp = dao.check_vou(user_id_id, voucher_id)
        if vou_resp:
            if vou_resp[0]['vuc'] == 0:
                vou_price = vou_resp[0]['minusprice']
                cart_cal_rel = payasset - vou_price

            if vou_resp[0]['vuc'] == 1:
                vou_price = vou_resp[0]['minusprice']
                if payasset > 200 and payasset < 500:
                    cart_cal_rel = payasset - vou_price
                elif payasset > 500 and payasset < 1000:
                    cart_cal_rel = payasset - vou_price
                elif payasset > 1000:
                    cart_cal_rel = payasset - vou_price

        # 将订单写入数据库
        o_num = get_order_num()
        dict1 = {
            "o_num": o_num,
            "o_addr": '不需要地址',
            "o_conn": tel,
            "o_time": datetime.datetime.now(),
            "o_status": 0,
            "o_total": payasset,
            "o_relpay": cart_cal_rel,
            "o_shopper_id": 'phonetraffic',
            "o_user_id": user_id_id
        }
        print(dict1)
        dao.save_detail(**dict1)

        rd.set(cart_cal_rel, o_num)
        rd.expire(cart_cal_rel, 2 * 60 * 60)
        # dao.delete_vou(user_id_id, voucher_id)
        data = {"orderID": o_num, "total": cart_cal_rel}
        return jsonify({'code': 200, 'msg': '订单生成成功', 'data': data})

    else:
        return jsonify({'code': 400, 'msg': '您还未登陆,请先登录'})
Example #3
0
File: sms.py Project: nancb/mywk
def new_code(phone):
    """
    获取验证码
    :param phone:
    :return:
    """
    code = ''.join([str(random.randint(0, 9)) for _ in range(4)])
    print(phone, code)
    # 保存到cache
    rd.set(phone, code)
    # 发送验证给用户
    send_sms_code(phone, code)
Example #4
0
def new_code(phone):
    """
    获取验证码
    :param phone:
    :return:
    """
    code = ''.join([str(random.randint(0, 9)) for _ in range(6)])
    rd.set(phone,code)          #将生成的验证码保存在redis中

    rd.expire(phone, 120)  # 有效时间: 12小时
    # 发送验证给用户
    send_sms_code(phone, code)
Example #5
0
def user_login():
    # 登录
    req_data = request.get_json()
    code = get_code()
    if not all((req_data.get('tel', False), req_data.get('idtf', False))):
        phone = str(req_data.get('tel'))
        result = check_login_tel(phone).get_json()
        if result.get('code') == 300:
            resp = send_sms_code(phone, code).decode()
            if resp[-4:-2] == "OK":
                rd.set(phone, code)
                rd.expire(phone, 120)
                return jsonify({
                    'code': 200,
                    'msg': '验证码发送成功',
                })
            else:
                return jsonify({'code': 400, 'msg': '验证码发送失败'})
        else:
            return jsonify({'code': 403, 'msg': '该手机号尚未注册注册!'})
    else:
        phone = req_data.get('tel')
        idtf = str(req_data.get('idtf'))
        temp2 = rd.get(phone)
        if not temp2:
            return jsonify({
                'code': 404,
                'msg': '验证码已过期',
            })
        temp2 = temp2.decode()
        if temp2 == idtf:
            token = cache.new_token()
            data = UserDao().get_jd_user(phone)
            user_id = data[0]['user_id']
            pay_pwd = data[0]['pay_pwd']
            if pay_pwd is None:
                result_pwd = False
            else:
                result_pwd = True
            rd.set(token, user_id)
            rd.expire(token, 3600 * 12)
            return jsonify({
                'code': 200,
                'msg': '登录成功!',
                'token': token,
                'data': data[0],
                'bool_pay_pwd': result_pwd
            })
        else:
            return jsonify({'code': 400, 'msg': '注册失败,验证码错误'})
Example #6
0
def user_regist():
    code = get_code()
    req_data = None
    print(code)
    api_logger.info(request.headers)

    if request.headers['Content-Type'].startswith('application/json'):
        req_data = request.get_json()

    if req_data is None:
        api_logger.warn('%s 请求参数未上传-json' % request.remote_addr)
        return jsonify({'code': 400, 'msg': '请上传json数据,且参数必须按api接口标准给定'})

    api_logger.debug(req_data)
    if not all((req_data.get('tel', False), req_data.get('idtf', False))):

        phone = str(req_data.get('tel'))
        ret = re.match(r"^1[35678]\d{9}$", phone)
        if ret:
            result = check_login_tel(phone).get_json()
            if result.get('code') == 400:
                resp = send_sms_code(phone, code).decode()
                if resp[-4:-2] == "OK":
                    rd.set(phone, code)
                    rd.expire(phone, 120)
                    return jsonify({
                        'code': 200,
                        'msg': '验证码发送成功',
                    })
                else:
                    return jsonify({'code': 400, 'msg': '验证码发送失败'})
            else:
                return jsonify({'code': 403, 'msg': '该账号已注册'})
        else:
            return jsonify({'code': 400, 'msg': '请输入正确的手机号'})
    else:
        phone = req_data.get('tel')
        idtf = str(req_data.get('idtf'))
        temp2 = rd.get(phone).decode()
        if temp2 == idtf:
            user_id = get_uid()
            dao = UserDao()
            req_data = {
                'tel': phone,
                'user_id': user_id,
                'user_name': user_id,
                'auth_string': 'jd' + phone,
                "asset": 0,
                "u_intg": 100
            }
            dao.save(**req_data)
            token = cache.new_token()
            rd.set(token, user_id)
            rd.expire(token, 3600 * 12)
            req_data = {
                'tel': phone,
                'user_id': user_id,
                'user_name': user_id,
                'auth_string': 'jd' + phone,
                "u_intg": 100,
                "asset": 0,
                "token": token,
                'bool_pay_pwd': False
            }
            return jsonify({'code': 200, 'msg': '注册成功', 'data': req_data})
        else:
            return jsonify({'code': 400, 'msg': '注册失败,验证码错误'})
Example #7
0
def save_token(token, user_id):
    # 保存token
    rd.set(token, user_id)
    rd.expire(token, 12 * 3600)  # 有效时间: 12小时