flask测试微信公众号的配置与连接

环境:腾讯云+flask+微信公众号

微信公众号端配置

使用腾讯云提供的公网地址:

URL     http://公网IP/wechat8000
Token   toohoo2019

使用flask编写配置信息测试代码:

#!/usr/bin/env python
# -*-encoding:UTF-8-*-

from flask import Flask, request, abort
import hashlib

# wechat token
WECHAT_TOKEN = "toohoo2019"

app = Flask(__name__)


@app.route("/wechat8000",methods=['GET','POST'])
def wechat():
    # recive the args
    signature = request.args.get("signature")
    timestamp = request.args.get("timestamp")
    nonce = request.args.get("nonce")
    echostr = request.args.get("echostr")

    # check the args
    if not all([signature, timestamp, nonce, echostr]):
        abort(400)

    # compute signature through the wechat process
    li = [WECHAT_TOKEN, timestamp, nonce]
    # sort
    li.sort()

    tmp_str = "".join(li).encode('utf-8')
    # sha1 encode, and get the correct sign
    sign = hashlib.sha1(tmp_str).hexdigest()

    # check if equal
    if signature != sign:
        # it is not from wechat
        abort(403)
    else:
        return echostr

if __name__ == '__main__':
    # visit private net from public net 
    app.run(host="内网IP",port=80, debug=True)

最后点击页面的配置页面的提交按钮即可,弹出配置成功即表示微信认可了后端主机,配置页面连接为:
https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值