1,使用rj_ca登录服务器,输入账号密码
2,新建一个文件夹,wechat
3,打开一个main.py 文件,然后输入
vim main.py
# -*- coding: utf-8 -*- # filename: main.py import web urls = ( ‘/wx‘, ‘Handle‘, ) class Handle(object): def GET(self): return "hello, this is a test" if __name__ == ‘__main__‘: app = web.application(urls, globals()) app.run()
注意,vim退出时,要Esc,然后冒号+wq,保存退出。
4,这里运行main.py会提示没有安装web.py
sudo easy_install web.py
5,显示http://0.0.0.0:8080/
浏览器中输入购买的服务器的外网IP:8080/wx
就可以看到返回的字符了
*************
由于进ubuntu的与服务器,是普通用户,所以用不了80端口
切换到root用户: sudo su
这样就可以 python main.py 80 了
*****************
6,进入微信公众号网页,开发--基本配置---修改配置
具体参考:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1472017492_58YV5
提交失败需要改动main.py
7,打开vim 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()
8,增加handle.py文件
vim 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 = "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
9,重新启动python main.py
10, main.py文件不改变,handle.py 需要增加一下代码,增加新的文件receive.py, reply.py
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1472017492_58YV5
11,
但是公众号配置那里一直不行!
时间: 2024-10-13 06:31:39