环境:腾讯云+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
1929

被折叠的 条评论
为什么被折叠?



