wechatpy / wechatpy Goto Github PK
View Code? Open in Web Editor NEWWeChat SDK for Python
Home Page: https://www.wechatpy.org
License: MIT License
WeChat SDK for Python
Home Page: https://www.wechatpy.org
License: MIT License
作者可以看看有没有可能转成新的方式
原先方式 | 新方式(登录授权) | |
---|---|---|
公众号是否需要提供appid和appsecret | 需要 | 不需要 |
公众号是否需要配置服务器url和token | 需要 | 不需要 |
可接入几个第三方开发服务 | 1个 | 5个(消息与菜单权限集只能授权给一家) |
https://open.weixin.qq.com/cgi-bin/frame?t=home/wx_plugin_tmpl&lang=zh_CN
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&lang=zh_CN
ref issue #52
Traceback (most recent call last):
File "/data1/www/htdocs/196/flyzhu/4/index.wsgi", line 4, in
from myapp import app
File "/data1/www/htdocs/196/flyzhu/4/myapp.py", line 10, in
from wechatpy.enterprise.crypto import WeChatCrypto
File "/data1/www/htdocs/196/flyzhu/4/site-packages/wechatpy/enterprise/init.py", line 5, in
from .crypto import WeChatCrypto # NOQA
File "/data1/www/htdocs/196/flyzhu/4/site-packages/wechatpy/enterprise/crypto.py", line 12, in
from Crypto.Cipher import AES
File "/data1/www/htdocs/196/flyzhu/4/site-packages/Crypto/Cipher/AES.py", line 50, in
from Crypto.Cipher import _AES
ImportError: cannot import name _AES
Log 如下,Python 3.4。为什么会用到 Visual C++?如果一定要的话,那怎样才能部署到服务器上去呢?刚开始学习,请多指教
creating build\lib.win32-3.4\Crypto\Signature
copying lib\Crypto\Signature\PKCS1_v1_5.py -> build\lib.win32-3.4\Crypto\Signature
copying lib\Crypto\Signature\__init__.py -> build\lib.win32-3.4\Crypto\Signature
Skipping implicit fixer: buffer
Skipping implicit fixer: idioms
Skipping implicit fixer: set_literal
Skipping implicit fixer: ws_comma
running build_ext
building 'Crypto.Random.OSRNG.winrandom' extension
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).
----------------------------------------
链接里多了/cgi-bin/
这是我打印的https://api.weixin.qq.com/cgi-bin/customservice/kfaccount/add
这是官方api里的:https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN
添加更新删除上传头像试过都报错
有空再加上呗
你好,又来请教。
我在使用 client.py 去创建菜单的时候,总提示找不到任何定义的方法,比如 create_menu, send_text_message 等。
代码如下:
from wechatpy import WeChatClient
client = WeChatClient(APPID, AESKEY)
print(client.API_BASE_URL)
client.send_text_message(TOKEN,"123456")
提示
AttributeError: 'WeChatClient' object has no attribute 'send_text_message'
如何把 send_text_message 换成 WeChatClient 的其他方法,也会出现相应的错误 。但是 API_BASE_URL 是可以找到的。请帮忙。谢谢
文档如下
http://dkf.qq.com/document-1_1.html
以下是我写的代码,还么有具体测试。
def get_records(self, starttime, endtime, openid, pagesize=20, pageindex=1):
"""
获取客服聊天记录接口
详情请参考
http://mp.weixin.qq.com/wiki/19/7c129ec71ddfa60923ea9334557e8b23.html
:return: 返回的 JSON 数据包
"""
data = NotNoneDict()
data['starttime'] = starttime
data['endtime'] = endtime
data['openid'] = openid
data['pagesize'] = pagesize
data['pageindex'] = pageindex
res = self._post('customservice/getrecord', data=data)
return res.get('recordlist')
以上均在企业号中使用遇到的问题
PS:真是想不明白为什么『弹出系统拍照发图的事件推送』这个事件中微信不返回图片的 media_id,而是图片的 md5。
还有一个问题是『弹出拍照或者相册发图的事件推送』,在选择相册图片后,微信没有按照它规定的格式发过来 count 和 PicList,发过来的 PicList 为空,并且 count 为 0,造成了wechatpy 解析消息后得到的 PicList 为 None
下面的"TM00015" 是否要手动获取模板ID,请问在wechatpy API 中没有获取模板ID的封装接口吗?
一下代码返回错误码:Error code: 40037, message: invalid template_id
client.message.send_template(open_id, "TM00015", "http://127.0.0.1:5000/", "#FF0000",
{
"first": {
"value": u"恭喜您下单成功!",
"color": "#173177"
},
"orderMoneySum": {
"value": u"10000",
"color": "#173177"
},
"orderProductName": {
"value": u"这是商品名",
"color": "#173177"
},
"remark": {
"value": u"欢迎再次购买!",
"color": "#173177"
}
})
看了下好像没看到消息加密解密的代码:smile:
https://mp.weixin.qq.com/wiki/0/61c3a8b9d50ac74f18bdf2e54ddfc4e0.html
Hi,
我继承了 WeChatClient,重写了 init,access_token,fetch_access_token 这三个方法,但是我发现 BaseWeChatClient 的 new 并没有正确的执行,导致 api._client 为 None
我尝试在继承的类中手动执行 WeChatClient.new 也没有用
if isinstance(message, TextMessage):
print u'文本消息'
reply = ArticlesReply(message=message)
reply.add_article({
'title': '猫',
'description': '描述文字……',
'image': 'http://a.hiphotos.baidu.com/image/w%3D310/sign=595a29f639c79f3d8fe1e2318aa0cdbc/43a7d933c895d1433d2c882a71f082025aaf0764.jpg',
'url': 'http://www.baidu.com'
})
return HttpResponse(reply, mimetype='application/javascript')
weMedia = WeChatMedia(client)
fo = open("E:\hh.jpg", 'rb+')
try:
imageJson = weMedia.upload('image', fo )
finally:
pass
报错I/O operation on closed file
如题
望有空再看下,加进项目里
我试过,一直删除失败 -1 系统繁忙
代码
reply = MusicReply(music=message.media_id,
thumb_media_id='YS4DH6hXNLgkcuOUVFFDmlr8A9tngYL5zak0k6CSrQGDG6fc_pHKG57Cmmou8h_m',
title=u'音乐回复测试', description='description',
music_url='http://sc1.111ttt.com/2015/6/04/11/97111815180.mp3',
hq_music_url='http://sc1.111ttt.com/2015/6/04/11/97111815180.mp3',
message=message)
报错信息
AttributeError: Unknown argument: thumb_media_id
回复视频消息也有
AttributeError: Unknown argument: title
删除接口最后访问的链接为:
https://api.weixin.qq.com/customservice/kfaccount/del?access_token=xxxxxxxxx&kf_account=aa11111%5C%40wiicome
requests自动编码符号@为%40,然后就报错了:无效客服账号(invalid kf_account)
模版消息事件推送过来msg.id没有
模版消息,群发消息的推送:
<MsgID>200163840</MsgID>
文本消息的推送:
<MsgId>1234567890123456</MsgId>
原来的:
class BaseMessage(six.with_metaclass(MessageMetaClass)):
"""Base class for all messages and events"""
type = 'unknown'
id = IntegerField('MsgId', 0)
event加一行id:
class BaseEvent(BaseMessage):
"""Base class for all events"""
id = IntegerField('MsgID', 0)
type = 'event'
event = ''
这样改可以吗
报错信息
SSLError: hostname 'file.api.weixin.qq.com' doesn't match either of 'game.weixin.qq.com', 'long.open.weixin.qq.com', 'open.weixin.qq.com', 'api.weixin.qq.com', 'a.weixin.qq.com', 'mp.weixinbridge.com', 'mp.weixin.qq.com'
调用此接口时出错
https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token=ACCESS_TOKEN
好像是证书问题
http://cn.python-requests.org/en/latest/user/advanced.html#ssl
例如:
[FIX]表示 修复类
[IMP]表示 improve, 在原有功能上进行的优化和更新
[NEW]表示新增了功能
#这是调用的地方相关的几句
articles = [
{
'title':u'test',
'description': u'test',
'image': 'http://www.test.com/logo_s2.png',
'url': "http://www.test.com/"
}
]
reply = create_reply(articles, message=msg)
return reply.render()
#报错信息
root.py", line 60, in wechat
return reply.render()
python2.7/site-packages/wechatpy/replies.py", line 73, in render
node_xml = field.to_xml(value)
python2.7/site-packages/wechatpy/fields.py", line 172, in to_xml
title = self.converter(article.get('title', ''))
AttributeError: 'unicode' object has no attribute 'get'
我追查了下,传进去的articles本来是个list,但是被存到self._fields里之后就变成了unicode了,取出来再get自然就报错。不止article,其他传入list的回复类型也会报错。
不知道如何从根本解决,我这样临时改了包里的源码,你看了就理解我的意思了:
def render(self):
"""Render reply from Python object to XML string"""
tpl = '<xml>\n{data}\n</xml>'
nodes = []
msg_type = '<MsgType><![CDATA[{msg_type}]]></MsgType>'.format(
msg_type=self.type
)
nodes.append(msg_type)
for name, field in self._fields.items():
value = getattr(self, name, field.default)
#========我加的=========
if name == 'articles':
try:
value = eval(value)
except Exception,exp:
pass
#========我加的END=========
node_xml = field.to_xml(value)
nodes.append(node_xml)
data = '\n'.join(nodes)
return tpl.format(data=data)
望尽快解决~~~
from __future__ import absolute_import, unicode_literals
from flask import Flask, request, abort, make_response
from wechatpy.enterprise.crypto import WeChatCrypto
from wechatpy.exceptions import InvalidSignatureException
from wechatpy.enterprise.exceptions import InvalidCorpIdException
from wechatpy.enterprise import parse_message, create_reply
TOKEN = '123456'
EncodingAESKey = ''
CorpId = ''
app = Flask(__name__)
@app.route('/wechat', methods=['GET', 'POST'])
def wechat():
signature = request.args.get('msg_signature', '')
timestamp = request.args.get('timestamp', '')
nonce = request.args.get('nonce', '')
crypto = WeChatCrypto(TOKEN, EncodingAESKey, CorpId)
if request.method == 'GET':
echo_str = request.args.get('echostr', '')
try:
echo_str = crypto.check_signature(
signature,
timestamp,
nonce,
echo_str
)
except InvalidSignatureException:
abort(403)
return echo_str
else:
try:
msg = crypto.decrypt_message(
request.data,
signature,
timestamp,
nonce
)
except (InvalidSignatureException, InvalidCorpIdException):
abort(403)
msg = parse_message(msg)
if msg.type == 'text':
reply = create_reply(msg.content, msg).render()
else:
reply = create_reply('Can not handle this for now', msg).render()
res = make_response(crypto.encrypt_message(reply, nonce, timestamp))
res.headers['Content-Type'] = 'application/xml'
return res
if __name__ == '__main__':
app.run('127.0.0.1', 5001, debug=True)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.