初次进行微信开发,服务号绑定成功,但是就是获取不到关注/取关的消息推送……测试代码贴上,大佬帮忙解惑
from flask import Flask, request, redirect from hashlib import sha1 app = Flask(__name__) TOKEN = 'XXXXXXXXXXXXXXXXX' @app .route( '/wx' , methods = [ 'GET' , 'POST' ]) def weixin_test(): if request.method = = 'POST' : print (request.get_data()) return 'success' elif request.method = = 'GET' : signature = request.args.get( 'signature' ) timestamp = request.args.get( 'timestamp' ) nonce = request.args.get( 'nonce' ) echostr = request.args.get( 'echostr' ) params_list = [TOKEN, timestamp, nonce] params_list.sort() param_str = ''.join(params_list) s1 = sha1() s1.update(param_str.encode()) hash_result = s1.hexdigest() print ( 'hash_result' , hash_result) print ( 'signature' , signature) print ( 'timestamp' , timestamp) print ( 'nonce' , nonce) if hash_result = = signature: print ( 'success' ) return echostr else : print ( '验证失败' ) return False if __name__ = = '__main__' : app.run(host = "0.0.0.0" , port = 80 , debug = True ) |
看不懂你的开发语言,建议你用postman发送post请求到你的接口,你先自己测试测试哟。浏览器里边敲地址,都是get请求哟
最终是因为愚蠢的没有开启接管……粗心大意害死人呐,耗了几个小时处理