公众号开发首次验证显示token验证失败
发布于 4 年前 作者 guiying88 1133 次浏览 来自 官方Issues
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
2 回复

微信有token吗?

直接返回echostr 都不行,有人遇到了嘛?

回到顶部