最近在玩微信公众账号,开发者模式需要验证,自己没有公网服务器,于是考虑通过免费的云服务器解决了 下面是通过新浪云SAE进行的微信公众平台开发者模式的验证方法。 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 
点击“提交”按钮,自动进行验证,验证结果如下: 
搭建的微信公众账号: ithomer 
参考推荐: 利用SAE搭建微信公众平台
SAE Python环境(SAE官方)
微信开发者接入平台(微信官方)
|