def home(): wheels = [ 'Akali_Splash_0.jpg', 'Akali_Splash_1.jpg', 'Akali_Splash_2.jpg', 'Akali_Splash_3.jpg', 'Akali_Splash_4.jpg' ] # print('**************************************') g.ip = request.remote_addr cache.set('ip', g.ip, timeout=3) goodslist = Goods.query.all() page = request.args.get('page') if page: page = int(page) else: page = 1 paginate = Goods.query.paginate(page, 4) # token状态 token = session.get('token') if token: user = User.query.filter(User.token == token).first() else: user = None return render_template('home.html', wheels=wheels, goodslist=goodslist, paginate=paginate, endpoint='blue.home', user=user)
def post(self): parse = parser.parse_args() user = User() user.name = parse.get('name') user.phone = parse.get('phone') user.email = parse.get('email') user.password = generate_password_hash(password=parse.get('password')) user.token = get_token() responseData = {} users = User.query.filter(User.email == user.email) if users.count > 0: responseData['status'] = 406 responseData['msg'] = '注册失败' responseData['err'] = '邮箱已注册' else: db.session.add(user) db.session.commit() mas = Message(subject='TPP激活邮件', recipients=[user.email]) url_active = 'http://127.0.0.1:5000/api/v1/register/?token=' + user.token body_html = render_template('useractive.html', name=user.name, url_active=url_active) mas.html = body_html mail.send(mas) cache.set(user.token, user.id, timeout=60 * 60) responseData['status'] = 200 responseData['msg'] = '注册成功请逐一查收(需要激活)' responseData['data'] = user return responseData
def post(self): parse = parser.parse_args() email = parse.get('email') password = parse.get('password') responseData = {} users = User.query.filter(User.email == email) if users.count > 0: user = users.first() if user.isdelete == True: return format_response(msg='该用户已被登录', status=404, err='') if check_password_hash(user.password, password): if user.active == False: msg = Message(subject='TPP激活邮件', recipients=[user.email]) active_url = 'http://127.0.0.1:5000/api/v1/register/?token=' + user.token body_html = render_template( 'useractive.html', name=user.name, ) msg.html = body_html mail.send(msg) cache.set(user.token, user.id, timeout=30) return format_response(msg='登录失败', status='406', err='该用户尚未激活,请激活(激活邮件已发送成功)') user.token = get_token() db.session.add(user) db.session.commit()
def testCache(): value = cache.get('ip') #先查找是不是在cache缓存中 if value: return '你又来了--%s' % value ip = request.remote_addr #获取请求的ip cache.set('ip', ip) #set方法存放到cache中,前者设置值的键,后者值 return '欢迎光临……'
def get(self): parse=parser.add_argument() phone=parse.get('phone') appid='' appkey='' template_id='' sms_sign='' num=1 ssender = SmsSingleSender(appid, appkey) random_str = random.randrange(1000, 10000) params = [random_str, num] cache.set(phone,random_str,60*1) try: result = ssender.send_with_param(86, phone, template_id, params, sign=sms_sign, extend="", ext="") # 签名参数未提供或者为空时,会使用默认签名发送短信 return format_response(msg='短信发送成功', status=200) except HTTPError as e: print(e) return format_response(msg='短信发送失败', status=400, err=e) except Exception as e: print(e) return format_response(msg='短信发送失败', status=400, err=e)
def put(self): args = parse.parse_args() if args.get('username'): if User.query.filter( User.username == args.get('username')).first(): return error_info(400, "该用户名已存在") g.user.username = args.get('username') if args.get('name'): g.user.name = args.get('name') if args.get('phone'): g.user.phone = args.get('phone') if args.get('password'): g.user.password = generate_password_hash(args.get('password')) g.user.save() token = generate_user_token() cache.set(token, g.user.id, timeout=60 * 60 * 24 * 7) data = { "data": { "id": g.user.id, "username": g.user.username, "phone": g.user.phone, "status": g.user.status, "token": token }, "meta": { "status": 201, "msg": "信息更改成功" } } return data
def post(self): args = parse_base.parse_args() password = args.get('password') action = args.get('action').lower() if action == USER_ACTION_REGISTER: args_register = parse_base.parse_args() username = args_register.get('username') admin_user = AdminUser() admin_user.username = username admin_user.password = password if username in ADMINS: admin_user.is_super = True if not admin_user.save(): abort(400, msg='创建失败') data = { 'status': HTTP_CREATE_OK, 'msg': '用户创建成功', 'data': admin_user, } return marshal(data, single_admin_user_fields) elif action == USER_ACTION_LOGIN: args_login = parse_base.parse_args() username = args_login.get('username') user = get_admin_user(username) if not user: abort(400, msg='用户不存在') if not user.check_password(password): abort(401, msg='密码错误') if user.is_delete: abort(401, msg='用户不存在') token = generate_admin_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = { 'msg': '登录成功', 'status': HTTP_OK, 'token': token, } return data else: abort(400, msg='请提供正确的参数')
def post(self): args = parse_base.parse_args() password = args.get("password") action = args.get("action").lower() if action == USER_ACTION_REGISTER: args_register = parse_base.parse_args() username = args_register.get("username") admin_user = AdminUser() admin_user.username = username admin_user.password = password if username in ADMINS: admin_user.is_super = True if not admin_user.save(): abort(400, msg="create fail") data = { "status": HTTP_CREATE_OK, "msg": "用户创建成功", "data": admin_user } return marshal(data, single_admin_user_fields) elif action == USER_ACTION_LOGIN: args_login = parse_base.parse_args() username = args_login.get("username") user = get_admin_user(username) if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="密码错误") if user.is_delete: abort(401, msg="用户不存在") token = generate_admin_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": HTTP_OK, "token": token} return data else: abort(400, msg="其提供正确的参数")
def post(self): args = parse_base.parse_args() password = args.get('password') print(password) action = args.get('action').lower() print(action) if action == USER_ACTION_REGISTER: args_register = parse_register.parse_args() phone = args_register.get('phone') username = args_register.get('username') movie_user = MovieUser() movie_user.username = username movie_user.password = password movie_user.phone = phone if not movie_user.save(): abort(400, msg="create fail") data = { "status": HTTP_CREATE_OK, "msg": "用户创建成功", "data": movie_user } return marshal(data, single_movie_user_fields) elif action == USER_ACTION_LOGIN: args_login = parse_login.parse_args() username = args_login.get("username") phone = args_login.get("phone") user = get_movie_user(username) or get_movie_user(phone) if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="密码错误") if user.is_delete: abort(401, msg="用户不存在") token = generate_movie_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": HTTP_OK, "token": token} return data else: abort(400, msg="其提供正确的参数")
def post(self): args = parse_base.parse_args() action = args.get('action') password = args.get('password') if action == 'register': args_register = parse_register.parse_args() phone = args_register.get('phone') email = args_register.get('email') # icon = photos.save(request.files['icon']) # pathname = os.path.join('/static/uploads/icons', icon) boke_user = BokeUserModel() boke_user.u_email = email boke_user.u_phone = phone boke_user.password = password # boke_user.u_icon = pathname if not boke_user.save(): abort(400, msg="create fail") data = {"status": 200, "msg": "用户创建成功", "data": boke_user} return marshal(data, single_boke_user_fields) elif action == 'login': args_login = parse_login.parse_args() email = args_login.get("email") phone = args_login.get("phone") code = args_login.get("code") user = get_boke_user(email) or get_boke_user(phone) print(cache.get(phone)) if cache.get(phone) != code: abort(400, msg='验证码错误') if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="密码错误") if user.is_delete: abort(401, msg="用户不存在") token = generate_boke_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": 200, "token": token} return data else: abort(400, msg="其提供正确的参数")
def get(): args_get = get_parse.parse_args() action = args_get.get('action') if action is None: abort(500, msg='Bad request.') return if action == ApiConstant.PRT_AUTH: # 执行 收集令牌发放逻辑 amt = auth_parse.parse_args().get('amt') if amt is None: abort(500, msg='Bad request.') return token = generate_token(TokenPrefix.PORTRAIT_COLLECT) cache.set(token, amt, timeout=ApiConstant.PRT_TOKEN_TIMEOUT) feedback = { 'msg': 'Success', 'status': ApiConstant.HTTP_OK, 'token': token } return marshal(feedback, auth_feedback_fields) elif action == ApiConstant.PRT_GET: args_content = content_get_parse.parse_args() # 在使用argparser后,若不给参数,无法执行到此处 _id = args_content.get('id') limit = args_content.get('length-limit') if not g.user.is_super and g.user.id != _id: abort(401, msg='You can\'t look up other\'s portrait.') # 执行 图片静态地址映射逻辑 session = get_session() if limit is None: prf = session.query(PortraitFileNames).filter_by(staff_id=_id) elif limit <= 0: abort(403, msg='Invalid limit.') return else: prf = session.query(PortraitFileNames).filter_by( staff_id=_id).limit(limit) if prf is None: abort(404, msg='Not Found.') outer_url = urljoin(NGINX_STATIC_PORTRAIT_URL, str(_id)) url_list = [join(outer_url, fn.staff_portrait_md5) for fn in prf] feedback = { 'msg': 'Success', 'status': ApiConstant.HTTP_OK, 'data': url_list } return marshal(feedback, get_feedback_fields) else: abort(500, msg='Bad request.')
def handle_register(): # 1.拿到用户输入的数据 username = request.form.get("username") password = request.form.get("password") email = request.form.get("email") gender = request.form.get("gender") age = request.form.get("age") # 2.把数据存到数据库 user = User() user.username = username user.password = generate_password_hash(password) user.gender = gender user.age = age user.email = email user.tokon = str(uuid.uuid4()) try: user.save() except Exception as ex: abort(400) # 往缓存里写一对键值对 cache.set(user.tokon, user.id, timeout=60) # 3.给注册的邮箱发送一个激活邮件 # msg = Message( # subject="欢迎注册脸盆网", # recipients=[] # ) # 把发送邮件的过程放到后台去执行 # 创建一个Message对象 # msg = Message() # msg.subject = "欢迎注册脸盆网" # msg.recipients = [email] # msg.body = # 在url_for里面,不认识的参数会自动变成请求参数 active_url = url_for("user.handle_active", _external=True, tokon=user.tokon) # msg.html = render_template("ActivePage.html",username=username,active_url=active_url) # # 把Message发出去 # mail.send(msg) from App.celery_util import send_mail subject = "欢迎注册脸盆网" recipients = [email] html = render_template("ActivePage.html", username=username, active_url=active_url) send_mail.delay(subject=subject, recipients=recipients, html=html) return "恭喜你注册成功"
def post(self): args = parse_base.parse_args() password = args.get("password") action = args.get("action").lower() username = args.get("username") print("*************************************************************", action) if action == USER_ACTION_REGISTER: user_have = get_admin_user(username) user = AdminUser() user.username = username user.password = password if user_have: abort(400, msg="duplicate user") if not user.save(): abort(400, msg="insert not success") token = generator_admin_user_token() cache.set(token, user.id, 60 * 60 * 24 * 100) data = { "status": HTTP_CREATE_OK, "msg": "insert success", "data": user, "token": token } return marshal(data, single_user_fields) elif action == USER_ACTION_LOGIN: user = get_admin_user(username) print(user) if not user: abort(400, msg="该用户不存在") if not user.check_password(password): abort(401, msg="用户名或密码错误,请重新输入") if user.is_delete: abort(401, msg="用户不存在") token = generator_admin_user_token() cache.set(token, user.id, 60 * 60 * 24 * 100) data = { "status": HTTP_OK, "msg": "login success%s" % username, "token": token } return data else: abort(400, msg="请提供正确参数")
def post(self): args = parse_base.parse_args() username = args.get("username") password = args.get("password") action = args.get("action").lower() if action == USER_ACTION_REGISTER: admin_user = AdminUser() admin_user.username = username admin_user.password = password if username in ADMINS: admin_user.is_super = True if not admin_user.save(): abort(400, msg="create fail") data = { "status": HTTP_CREATE_OK, "msg": "user created successfully", "data": admin_user } return marshal(data, single_Admin_user_fields) elif action == USER_ACTION_LOGIN: user = get_admin_user(username) if not user: print("user ="******"user not exist(1)", ) if not user.check_password(password): abort(401, msg="password error") if user.is_delete: abort(401, msg="user not exist") token = generate_admin_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = { "msg": "login success", "status": HTTP_OK, "token": token } return data else: abort(400, msg="please provide correct parameters")
def send_code(): phone = request.args.get("phone") username = request.args.get("username") resp = send_verify_code(phone) print(resp.json()) result = resp.json() if result.get("code") == 200: obj = result.get("obj") cache.set(username, obj) data = {"msg": "ok", "status": 200} return jsonify(data) data = {"msg": "fail", "status": 400} return jsonify(data)
def post(self): """ 用户注册和登录 """ args = parser_base.parse_args() action = args.get("action", "-").lower() password = args.get("password") # 用户注册 if action == USER_ACTION_REGISTER: args_register = parser_register.parse_args() user = MovieUser() user.username = args_register.get("username") user.password = password user.phone = args_register.get("phone") if not user.save(): abort(400, msg="用户注册失败.") data = {"status": HTTP_CREATE_OK, "msg": "用户创建成功", "data": user} return marshal(data, user_fields) # 用户登录 elif action == USER_ACTION_LOGIN: args_login = parser_login.parse_args() username = args_login.get("username") phone = args_login.get("phone") user = get_movie_user(username) or get_movie_user(phone) if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="密码错误") if user.is_deleted: abort(401, msg="用户已标记为注销") token = gen_token_movie_user() cache.set(token, user.id) data = {"msg": "登录成功", "status": HTTP_OK, "token": token} return data else: abort(400, msg="请提供正确的参数!")
def index(): result = cache.get("index") if result: return result result = render_template("GradeList.html") sleep(5) cache.set("index", result, timeout=20) return result
def have_cache(): result = cache.get("have_cache") if result: return result resp = render_template('HaveCache.html') sleep(2) cache.set("have_cache", resp, timeout=10) return resp
def post(self): args = base_parse.parse_args() password = args.get("password") action = args.get("action").lower() if action == USER_ACTION_REGISTER: register_args = register_parse.parse_args() username = register_args.get("username") phone = register_args.get("phone") movie_user = MovieUser() movie_user.user_name = username movie_user.password = password movie_user.phone = phone if not movie_user.save(): abort(400, msg="create fail") data = { "status": HTTP_CREATE_SUCCESS, "msg": "用户创建成功", "data": movie_user } return marshal(data, singe_movie_user_fields) elif action == USER_ACTION_LOGIN: login_args = login_parse.parse_args() username = login_args.get("username") phone = login_args.get("phone") user = get_user(username) or get_user(phone) if not user or user.is_delete: abort(400, msg="用户不存在!") if not user.check_password(password): abort(401, msg="密码错误!") token = uuid.uuid4().hex cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = { "msg": "login success", "status": HTTP_SUCCESS, "token": token } return data else: abort(400, msg="请提供正确的参数!")
def post(self): args = parser_base.parse_args() password = args.get("password") action = args.get("action").lower() if action == USER_ACTION_REGISTER: args_register = parser_register.parse_args() username = args_register.get("username") phone = args_register.get("phone") cinema_user = CinemaUser() cinema_user.username = username cinema_user.password = password cinema_user.phone = phone if not cinema_user.save(): abort(400, msg="创建用户失败") data = { "status": HTTP_CREATE_OK, "msg": "用户创建成功", "data": cinema_user, } return marshal(data, single_cinema_user_fields) elif action == USER_ACTION_LOGIN: args_login = parser_login.parse_args() username = args_login.get("username") phone = args_login.get("phone") user = get_cinema_user(phone) if not user: user = get_cinema_user(username) if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="用户名或密码错误") if user.is_delete: abort(401, msg="用户不存在") token = generate_cinema_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = { "msg": "success", "status": HTTP_OK, "token": token, } return data else: abort(400, msg="参数错误")
def get(self): phone = request.args.get("phone") resp = send_verify_code(phone) result = resp.json() if result.get("code") == 200: obj = result.get("obj") cache.set(phone, obj) print(cache.get(phone)) data = {"msg": "ok", "status": 200} return jsonify(data) data = {"msg": "fail", "status": 400} return jsonify(data)
def post(self): action = request.args.get("action") username = request.form.get("username") password = request.form.get("password") if action == "register": user = User() user.u_name = username user.u_password = password if username in ADMINS: user.is_super = True if not user.save(): abort(401) data = {"msg": "create ok", "status": 201} return data elif action == "login": user = User.query.filter(User.u_name.__eq__(username)).first() if not user: abort(404, msg="user doesn't exist") if not user.verify_password(password): abort(401, msg="password error") token = uuid.uuid4().hex cache.set(token, user.id, timeout=60 * 60) data = { "msg": "login success", "status": 200, "token": token, "data": user } return marshal(data, result_fields) abort(400, msg="must supply action")
def post(self): args = parse_base.parse_args() password = args.get("password") action = args.get("action") if action == USER_ACTION_REGISTER: register = parse_register.parse_args() username = register.get("username") phone = register.get("phone") movie_user = MovieUserModel() movie_user.username = username movie_user.password = password movie_user.phone = phone print("--->", username, password, phone) if not movie_user.save(): abort(400, message="create fail") data = { "status": HTTP_CREATE_OK, "msg": "success", "data": movie_user } return marshal(data, single_movie_user_fields) elif action == USER_ACTION_LOGIN: login = parse_login.parse_args() username = login.get("username") phone = login.get("phone") print("username--phone", login, username, phone) user = get_user(username) or get_user(phone) if not user: abort(400, message="the user isn't exists!") if not user.check_password(password): abort(400, message="password is error!") if user.is_delete: abort(400, msg="the user isn't exists!") token = uuid.uuid4().hex cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": HTTP_OK, "token": token} return data else: abort(400, message="plz input correct args")
def post(self): action = request.args.get("action") if action == "register": c_name, c_password = parse_args() cinema_user = CinemaUser() cinema_user.c_name = c_name cinema_user.c_password = c_password if not cinema_user.save(): abort(400, msg="注册失败") data = {"msg": "ok", "status": 201, "data": cinema_user} return marshal(data, single_user_fields) elif action == "login": c_name, c_password = parse_args() users = CinemaUser.query.filter( CinemaUser.c_name.__eq__(c_name)).all() if not users: abort(404, msg="用户不存在") user = users[0] if not user.check_password(c_password): abort(400, msg="密码错误") if user.is_delete: abort(400, msg="账号已封停") token = generate_cinema_token() cache.set(token, user.id, timeout=60 * 60 * 7 * 24) data = {"msg": "ok", "status": 200, "token": token} return data else: abort(400, msg="请提供正确的动作")
def post(self): args = parse_base.parse_args() password = args.get('password') action = args.get('action').lower() if action == USER_REGISTER: args_registe = parse_regist.parse_args() name = args_registe.get('name') phone = args_registe.get('phone') user = MovieUser() user.name = name user.phone = phone user.password = password if not user.save(): abort(400, msg="create fail") data = { 'msg': "创建成功", 'status': HTTP_CREAT_OK, 'data': user, } return marshal(data, single_movie_user_fileds) elif action == USER_LOGIN: args_login = parse_login.parse_args() name = args_login.get('name') phone = args_login.get('phone') user = get_user(phone) or get_user(name) if not user: abort(400, msg="请输入用户名") if not user.check_password(password): abort(400, msg="密码错误") if user.is_delete: abort(400, msg="用户不存在") token = generate_movie_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = { 'status': HTTP_OK, 'msg': 'http_ok', 'token': token, } return data else: abort(400, msg="请提供正确的参数")
def post(self): args = parse_base.parse_args() password = args.get('password') action = args.get('action').lower() if action == USER_ACTION_REGISTER: args_register = parse_register.parse_args() username = args_register.get('username') phone = args_register.get('phone') cinema_user = CinemaUser() cinema_user.username = username cinema_user.password = password cinema_user.phone = phone if not cinema_user.save(): abort(400, msg='create fail') data = { 'status': HTTP_CREATE_OK, 'msg': '用户创建成功', 'data': cinema_user } return marshal(data, single_cinema_user_fields) elif action == USER_ACTION_LOGIN: args_login = parse_login.parse_args() username = args_login.get('username') phone = args_login.get('phone') user = get_cinema_user(username) or get_cinema_user(phone) if not user: abort(400, msg='用户不存在') if not user.check_password(password): abort(401, msg='用户名或密码错误') if user.is_delete: abort(401, msg='用户不存在') token = generate_cinema_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {'status': HTTP_OK, 'msg': 'login success', 'token': token} return data else: abort(400, msg='请输入正确的参数')
def post(self): args = parse_base.parse_args() password = args.get("password") action = args.get("action") if action == "register": register_args = parse_register.parse_args() username = register_args.get("username") phone = register_args.get("phone") cinema_user = CinemaUser() cinema_user.username = username cinema_user.password = password cinema_user.phone = phone if not cinema_user.save(): abort(400, msg="create fail") data = {"status": '201', "msg": "用户创建成功", "data": cinema_user} return marshal(data, single_cinema_user_fields) elif action == "login": login_args = parse_login.parse_args() username = login_args.get("username") phone = login_args.get("phone") user = get_cinema_user(username) or get_cinema_user(phone) if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="密码错误") if user.is_delete: abort(400, msg="用户不存在") token = generate_cinema_user_token() cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": 200, "token": token} return data else: abort(400, msg="请提供正确的参数")
def post(self): """ 下单 用户 排挡(目前没有) 电影 movieapi 大厅 None 定义一个表 大厅类型 座位类型(0,0) (0,1) 1 - 16 if 一排就是五个位置 0 1 2 3 4 6 7 8 9 11 12 13 14 """ u_token = request.form.get("u_token") mp = request.form.get("mp") seats = request.form.get("seats") order = Order() order.o_user = cache.get(u_token) order.o_movie_plan = mp order.save() seat_list = seats.split("#") for seats_positon in seat_list: ticket = Ticket() ticket.t_order = order.id ticket.t_seat = int(seats_positon) ticket.save() # 将订单放入缓存中并限定过期时间 order_list = cache.get(mp) if not order_list: order_list.append(order.id) cache.set(mp, order_list) data = {"returnCode": "0", "returnValue": order.id} return data
def put(self): parser = parse.parse_args() username = parser.get("username") password = parser.get("password") email = parser.get("email") user = UserModel() user.u_name = username user.u_password = generate_password_hash(password=password) user.u_email = email user.save() u_token = str(uuid.uuid4()) cache.set(u_token, user.id, timeout=60) msg = Message(subject="TestTppActive",sender="*****@*****.**",recipients=["*****@*****.**"]) html = render_template("UserActivate.html", username=username, active_url="http://localhost:5000/users/?action=active&u_token=%s"%u_token) msg.html = html mail.send(msg) return {"msg":"ok","data":user}
def get(self): token = request.args.get('token') user = User.query.filter(User.token == token).first() #### 必备参数 # 短信应用SDK AppID appid = 1400112809 # SDK AppID是1400开头 # 短信应用SDK AppKey appkey = "8d8b808cb9073023631d241951f49fb4" # 需要发送短信的手机号码 phone_numbers = [user.phone] print(phone_numbers[0]) # 短信模板ID,需要在短信应用中申请 template_id = 166915 # NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请 # 签名 sms_sign = "TPP短信验证" # NOTE: 这里的签名"腾讯云"只是一个示例,真实的签名需要在短信控制台中申请,另外签名参数使用的是`签名内容`,而不是`签名ID` ##### 指定模板发送短信 from qcloudsms_py import SmsSingleSender from qcloudsms_py.httpclient import HTTPError ssender = SmsSingleSender(appid, appkey) # 模板: 验证码、超时时间 randomstr = random.randrange(100000,1000000) params = [randomstr, 3] # 当模板没有参数时,`params = []` cache.set(user.token, randomstr, timeout=60*3) # 验证码缓存 token:randomstr try: result = ssender.send_with_param(86, phone_numbers[0], template_id, params, sign=sms_sign, extend="",ext="") # 签名参数未提供或者为空时,会使用默认签名发送短信 except HTTPError as e: print(e) except Exception as e: print(e) return {'msg':'发送验证码成功,请注意查收'}