SAE 搭建微信公眾平臺
阿新 • • 發佈:2018-11-16
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
最近在玩微信公眾賬號,開發者模式需要驗證,自己沒有公網伺服器,於是考慮通過免費的雲伺服器解決了
下面是通過新浪雲SAE進行的微信公眾平臺開發者模式的驗證方法。
index.wsgi
# coding: UTF-8 import saeimport osimport webfrom weixinInterface import WeixinInterface urls = ( '/', 'Hello', '/weixin','WeixinInterface') class Hello: def GET(self): return ("你好, Sunboy_2050") app = web.application(urls, globals()).wsgifunc()application = sae.create_wsgi_app(app)
weixinInterface.py
#coding:UTF-8import hashlibimport webclass WeixinInterface: def GET(self): data = web.input() # 獲取輸入引數 signature = data.signature timestamp = data.timestamp nonce = data.nonce echostr = data.echostr token="sunboy_2050" # 自己的token list=[token,timestamp,nonce] # 字典序排序 list.sort() sha1=hashlib.sha1() # sha1加密演算法 map(sha1.update, list) hashcode=sha1.hexdigest() if hashcode == signature: # 如果是來自微信的請求,則回覆echostr return echostr # print "true"
執行結果:
在瀏覽器輸入網址: http://weixin.ithomer.net
驗證微信
成為微信公眾平臺開發者,需要進行驗證,輸入URL和Token
在SAE上,已經配置了Token(sunboy_2050),URL連線為 http://weixin.ithomer.net/weixin
點選“提交”按鈕,自動進行驗證,驗證結果如下:
搭建的微信公眾賬號: ithomer
參考推薦:
SAE Python環境(SAE官方)
微信開發者接入平臺(微信官方)