注意:在微信公衆號的開發者基本配置以後,用戶發送的消息將自動轉發到該設置地址,而且在網站中設置的自動回覆和自定義的菜單都將失效!python
1) 公衆平臺官網登陸以後,找到「基本配置」菜單欄web
2) 填寫配置vim
url填寫:http://外網IP:端口號/wx 。外網IP請到騰訊雲購買成功處查詢, http的端口號固定使用80,不可填寫其餘。服務器
Token:自主設置,這個token與公衆平臺wiki中常提的access_token不是一回事。這個token只用於驗證開發者服務器。微信
3) 如今選擇提交確定是驗證token失敗,由於還須要完成代碼邏輯。改動原先main.py文件,新增handle.py網絡
# -*- coding: utf-8 -*- # filename: main.py import web from handle import Handle urls = ( '/wx', 'Handle', ) if __name__ == '__main__': app = web.application(urls, globals()) app.run()
先附加邏輯流程圖app
# -*- coding: utf-8 -*- # filename: handle.py import hashlib import web class Handle(object): def GET(self): try: data = web.input() if len(data) == 0: return "hello, this is handle view" signature = data.signature timestamp = data.timestamp nonce = data.nonce echostr = data.echostr token = "xxxx" #請按照公衆平臺官網\基本配置中信息填寫 list = [token, timestamp, nonce] list.sort() sha1 = hashlib.sha1() map(sha1.update, list) hashcode = sha1.hexdigest() print "handle/GET func: hashcode, signature: ", hashcode, signature if hashcode == signature: return echostr else: return "" except Exception, Argument: return Argument
4) 從新啓動成功後(python main.py 80),點擊提交按鈕。若提示」token驗證失敗」, 請認真檢查代碼或網絡連接等。若token驗證成功,會自動返回基本配置的主頁面,點擊啓動按鈕網站