公众号开发首次验证显示token验证失败
class Wechat(Resource):
def get(self):
TOKEN = "lk2ikklsdoi3uj4nj1"
logger.info("[wechat] check enter [%s]" % (request.args))
signature = request.args.get("signature", "")
timestamp = request.args.get("timestamp", "")
nonce = request.args.get("nonce", "")
echostr = request.args.get("echostr", "")
logger.info("[wechat] check - [%s] - [%s] - [%s]" % (signature, timestamp, nonce))
if not signature or not timestamp or not nonce:
return False
tmp_str = "".join(sorted([TOKEN, timestamp, nonce]))
tmp_str = str(hashlib.sha1(tmp_str.encode('UTF-8')).hexdigest())
logger.info("[wechat] signature - [%s] - [%s]" % (tmp_str, signature))
if tmp_str == signature:
logger.info("[wechat] signature - succeess - [%s]" % (echostr))
return echostr
else:
logger.info("[wechat] signature - fail")
return False