大藍鯨微信公眾號開發
阿新 • • 發佈:2017-11-01
div data repl times cati 代碼 fun sta log
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.pyimport 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,
但是公眾號配置那裏一直不行!
大藍鯨微信公眾號開發