SAE 搭建微信公众平台
时间:2014-01-21 23:43:58
收藏:0
阅读:734
index.wsgi
# coding: UTF-8 import sae import os import web from 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-8 import hashlib import web class 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
点击“提交”按钮,自动进行验证,验证结果如下:
参考推荐:
SAE Python环境(SAE官方)
微信开发者接入平台(微信官方)
原文:http://blog.csdn.net/ithomer/article/details/18560897
评论(0)