wechatapiresource.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:wechat-bot-skeleton-python 作者: edonosotti 项目源码 文件源码
def on_get(self, request, response):
        # Get the parameters from the query string
        signature = request.get_param('signature')
        timestamp = request.get_param('timestamp')
        nonce = request.get_param('nonce')
        echostr = request.get_param('echostr')

        # Compute the signature (note that the shared token is used too)
        verification_elements = [self.token, timestamp, nonce]
        verification_elements.sort()
        verification_string = "".join(verification_elements)
        verification_string = hashlib.sha1(verification_string.encode('utf-8')).hexdigest()

        # If the signature is correct, output the same "echostr" provided by the WeChat server as a parameter
        if signature == verification_string:
            response.status = falcon.HTTP_200
            response.body = echostr
        else:
            response.status = falcon.HTTP_500
            response.body = ""

    # Messages will be POSTed from the WeChat server to the chatbot backend server,
    # see: http://admin.wechat.com/wiki/index.php?title=Common_Messages
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号