微信二次开发源码
发布时间: 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>
⑵ 通过手机点了这个链接之后可以跳转到微信支付,这个源码怎么写
微信公司平台帐号注册后官方首页很简单,没有导航栏目页面新建等功能。需要通过三方软件与微信接口做二次开发。首先要在现在微信开个接口,这是要工商局认证的。
热点内容