@微信
微信提供客服接口,用戶給用戶發送消息。在 wetchat.py
中封裝成WeChatMessage
。
注意:未認證的訂閱號和公衆號,是沒有該接口權限的app
發送消息前,先獲取粉絲的open_id,這裏取巧,直接在公衆號後臺拿
curl
wx.message.send_text(user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw",content="我不在我不在我不在.....") Out[25]: {'errcode': 0, 'errmsg': 'ok'} wx.message.send_text(user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw",content="我不在我不在我不在.....") Out[26]: {'errcode': 0, 'errmsg': 'ok'}
效果以下:ide
[danger] 注意,會話須要由用戶先發起,不然會出現45015:回覆時間超過限制的錯誤。測試
wx.message.send_image(user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw",media_id="BzzIfj9NcYYTuaPR_j133jbk4KxYuPvhoZx68usaDi0") Out[28]: {'errcode': 0, 'errmsg': 'ok'}
效果以下:
url
wx.message.send_articles( user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw", articles="BzzIfj9NcYYTuaPR_j133mW-veyn3sNRANnduEtdnss" ) Out[29]: {'errcode': 0, 'errmsg': 'ok'}
wx.message.send_articles( user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw", articles=[ { "title": "Happy Day", "description": "Is Really A Happy Day", "url": "https://www.kancloud.cn/@guanfuchang", "picurl": "http://mmbiz.qpic.cn/mmbiz_png/QuFmLYzPJ2DK93uoeUAibJSqQBmgeR1uhdicrQKxT3QzZVdfWUIHa6fmFfuaibLNibqYGVHQcwyzCbsbPWTN82Vs9g/0?wx_fmt=png" } ] ) Out[30]: {'errcode': 0, 'errmsg': 'ok'}
wx.message.send_articles(user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw", articles=wx.media.upload_articles( articles=[ { "thumb_media_id": wx.media.upload("image", open("D://666.png", "rb")).get("media_id"), "author": "觀小魚", "title": "圖文標題", "content_source_url": "https://www.kancloud.cn/@guanfuchang", "content": "圖文詳情內容", "digest": "圖文概要描述", "show_cover_pic": 1, "need_open_comment": 1, "only_fans_can_comment": 1 } ]).get("media_id")) Out[32]: {'errcode': 0, 'errmsg': 'ok'}
wx.message.send_music( user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw", url="https://od.qingting.fm/m4a/5a8e82757cb89146f20a287b_8762416_64.m4a", hq_url="https://od.qingting.fm/m4a/5a8e82757cb89146f20a287b_8762416_64.m4a", thumb_media_id=wx.media.upload("thumb", open("D://music.jpg","rb")).get("thumb_media_id"), title="夢想明月曲", description="崔子格", ) Out[35]: {'errcode': 0, 'errmsg': 'ok'}
wx.message.send_video( user_id="oiQF0tzMZ5Md5HaAlKvrZo9OIGBw", media_id="BzzIfj9NcYYTuaPR_j133ietkr1Oy2009whI6vdTLR8", ) Out[36]: {'errcode': 0, 'errmsg': 'ok'}
wx.message.send_mass_text( group_or_users=None, content="羣發消息", is_to_all=True ) Out[37]: {'errcode': 0, 'errmsg': 'send job submission success', 'msg_id': 1000000002}
[info] 更多羣發接口就不一一舉例,參考源代碼
message
類中,send_mass_xxx 方法便可。3d
:-:
微信掃一掃,關注「python測試開發圈」,獲取更多測試開發分享!code