Coder Social home page Coder Social logo

wechatpy's Introduction

  ___       __   _______   ________  ___  ___  ________  _________  ________  ___    ___
 |\  \     |\  \|\  ___ \ |\   ____\|\  \|\  \|\   __  \|\___   ___\\   __  \|\  \  /  /|
 \ \  \    \ \  \ \   __/|\ \  \___|\ \  \\\  \ \  \|\  \|___ \  \_\ \  \|\  \ \  \/  / /
  \ \  \  __\ \  \ \  \_|/_\ \  \    \ \   __  \ \   __  \   \ \  \ \ \   ____\ \    / /
   \ \  \|\__\_\  \ \  \_|\ \ \  \____\ \  \ \  \ \  \ \  \   \ \  \ \ \  \___|\/  /  /
    \ \____________\ \_______\ \_______\ \__\ \__\ \__\ \__\   \ \__\ \ \__\ __/  / /
     \|____________|\|_______|\|_______|\|__|\|__|\|__|\|__|    \|__|  \|__||\___/ /
                                                                            \|___|/

Financial Contributors on Open Collective GitHub Actions codecov.io Documentation Status PyPI Downloads Reviewed by Hound

微信(WeChat) 公众平台第三方 Python SDK。

v1.x: 【阅读文档】 【快速入门】 master: 【阅读文档】 【快速入门】

功能特性

  1. 普通公众平台被动响应和主动调用 API
  2. 企业微信 API
  3. 微信支付 API
  4. 第三方平台代公众号调用接口 API
  5. 小程序云开发 API

安装

推荐使用 pip 进行安装:

pip install wechatpy

升级版本:

pip install -U wechatpy

使用示例

使用示例参见 examples

贡献代码

请阅读 贡献代码指南

支持项目

如果觉得本项目对您有帮助,请考虑捐赠支持项目开发

问题反馈

我们主要使用 GitHub issues 进行问题追踪和反馈。

QQ 群:176596300

wechatpy QQ 群

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

wechatpy's People

Contributors

007gzs avatar brightcells avatar cclauss avatar cloverstd avatar cysnake4713 avatar deepsource-autofix[bot] avatar faceair avatar filosfino avatar huimingz avatar hunter007 avatar iblogc avatar jeremylam avatar lau-jay avatar ldsink avatar lipengfei911 avatar lki avatar messense avatar mia503 avatar noogel avatar nullying avatar prowayne avatar ramwin avatar sum1201 avatar tssujt avatar winturn avatar wwwjfy avatar xavier-lam avatar yqkcn avatar zephyrrr avatar zthxxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wechatpy's Issues

图文消息回复时图文个数一直在递增

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')

20150514160140435

模版群发消息事件推送msg.id没有

模版消息事件推送过来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 = ''

这样改可以吗

windows 下用 pip 安装报错

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).
----------------------------------------

群发视频上传报错

报错信息

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
qq 20150521164218

企业号我用这代码回调没反应啊

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)

关于发送模板消息的问题

下面的"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"
}
})

遇到了一些问题

  1. 图片消息缺少 media_id
  2. 下载多媒体文件时,返回的不是 json,应该是文件 stream,对应的 requests 中应该是 r.content,

以上均在企业号中使用遇到的问题

PS:真是想不明白为什么『弹出系统拍照发图的事件推送』这个事件中微信不返回图片的 media_id,而是图片的 md5。

还有一个问题是『弹出拍照或者相册发图的事件推送』,在选择相册图片后,微信没有按照它规定的格式发过来 count 和 PicList,发过来的 PicList 为空,并且 count 为 0,造成了wechatpy 解析消息后得到的 PicList 为 None

找不到 create_menu 方法

你好,又来请教。

我在使用 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 是可以找到的。请帮忙。谢谢

继承了 WeChatClient,但是 __new__ 并没有正确的执行

Hi,
我继承了 WeChatClient,重写了 init,access_token,fetch_access_token 这三个方法,但是我发现 BaseWeChatClient 的 new 并没有正确的执行,导致 api._client 为 None

我尝试在继承的类中手动执行 WeChatClient.new 也没有用

sae环境部署的时候出现如下错误,哪位高手能指点一二,谢谢

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

回复音乐消息报错

代码

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

回复文章报错

#这是调用的地方相关的几句
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)

望尽快解决~~~

缺少一个多客服获取聊天记录的API方法

文档如下
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')

微信开放平台

作者可以看看有没有可能转成新的方式

原先方式 新方式(登录授权)
公众号是否需要提供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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.