开发流程
- 公众号申请
- 接入服务器
- api接口方式生成菜单(需要认证才可以使用,个人公众号无法使用)
1. 公众号申请
登录公众号平台https://mp.weixin.qq.com/并注册公众号账号即可(略)
2. 接入服务器
官方文档https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html
https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Getting_Started_Guide.html
其中服务器端的实现,可以用python脚本搞定
分别创建main.py和handle.py两个脚本文件,输入以下内容,然后启动(python main.py 80 &)即可完成接入服务器的开发。
#main.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()
# handle.py
# -*- 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 = "xxxxx" #请按照公众平台官网\基本配置中信息填写
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
网友评论