微信二次開發源碼
發布時間: 2023-07-13 20:14:21
⑴ 如何用python進行微信二次開發
創建步驟:
1.申請免費且支持python的伺服器,新浪雲sae,新建SAE應用之後,有兩種代碼提交方式,建議使用SVN(因為git支持代碼提交,但不支持環境配置);
2.將對應版本的信息復制到微信開發-基本配置-URL,提交顯示錯誤,因為還沒有寫代碼,可以先用web框webpy架寫個網頁;
查看webpy使用說明:http://www.webpy.org/install.zh-cn
查看ase進行python開發入門說明:http://www.sinacloud.com/doc/sae/python/index.html
3.配置信息,告訴新浪雲需要什麼運行環境。點擊代碼管理-編輯代碼,將用到的第三方庫信息寫入config.yaml,注意破折號,冒號後面空格!!
libraries:
-name:webpy
version:"0.36"
-name:lxml
version:"2.3.4"
在index.wsgi文件中寫入python啟動程序
新建文件,寫入接受微信get請求驗證的Python文件
4.在index.wgsi中寫入以下信息:
#coding=utf-8
importos
importsae
importweb#配置web的路由
urls=(
'/weixin','WeixinInterface'
)
#拼接路徑
app_root=os.path.dirname(__file__)
templates_root=os.path.join(app_root,'templates')
#渲染模版
render=web.template.render(templates_root)
#啟動app
app=web.application(urls,globals()).wsgifunc()
application=sae.create_wsgi_app(app)
5.在自己編寫的Python文件中寫入微信驗證和接受信息的程序
#coding=utf-8
importhashlib
importweb
importtime
importos
fromlxmlimportetree
#hashlib用於加密,md5,hash等
#lxml用來解析xml文件
classWeixinInterface(object):
#初始化
def__init__(self):
#拼接路徑
self.app_root=os.path.dirname(__file__)
self.templates_root=os.path.join(self.app_root,'templates')
#渲染模版
self.render=web.template.render(self.templates_root)
#使用get方法,接收微信的get請求,看開發者文檔的說明
#http://mp.weixin.qq.com/wiki/8/.html
defGET(self):
data=web.input()
signature=data.signature#微信加密簽名
timestamp=data.timestamp#時間戳
nonce=data.nonce#隨機數
echostr=data.echostr#隨即字元串
token='zq90857'#自己設置的token
#將token、timestamp、nonce三個參數進行字典序排序
list=[token,timestamp,nonce]
list.sort()
#將三個參數字元串拼接成一個字元串進行sha1加密
sha1=hashlib.sha1()
map(sha1.update,list)
temStr=sha1.hexdigest()#加密
#判斷
iftemStr==signature:
returnechostr
6.假設接收文字信息,按照開發者文檔的要求,配置template文件夾下reply_text.xml文件
$defwith(toUser,fromUser,createtime,content)
<xml>
<ToUserName><![CDATA[$toUser]]></ToUserName>
<FromUserName><![CDATA[$fromUser]]></FromUserName>
<CreateTime>$createtime</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[$content]]></Content>
</xml>
⑵ 通過手機點了這個鏈接之後可以跳轉到微信支付,這個源碼怎麼寫
微信公司平台帳號注冊後官方首頁很簡單,沒有導航欄目頁面新建等功能。需要通過三方軟體與微信介面做二次開發。首先要在現在微信開個介面,這是要工商局認證的。
熱點內容