MCPcopy Create free account
hub / github.com/doraemonext/wechat-python-sdk / send_article_message

Method send_article_message

wechat_sdk/basic.py:692–737  ·  view source on GitHub ↗

发送图文消息 详情请参考 http://mp.weixin.qq.com/wiki/7/12a5a320ae96fecdf0e15cb06123de9f.html :param user_id: 用户 ID, 就是你收到的 WechatMessage 的 source :param articles: list 对象, 每个元素为一个 dict 对象, key 包含 `title`, `description`, `picurl`, `url` :param media_id: 待发送的图文 Media ID

(self, user_id, articles=None, media_id=None)

Source from the content-addressed store, hash-verified

690 )
691
692 def send_article_message(self, user_id, articles=None, media_id=None):
693 """
694 发送图文消息
695 详情请参考 http://mp.weixin.qq.com/wiki/7/12a5a320ae96fecdf0e15cb06123de9f.html
696 :param user_id: 用户 ID, 就是你收到的 WechatMessage 的 source
697 :param articles: list 对象, 每个元素为一个 dict 对象, key 包含 `title`, `description`, `picurl`, `url`
698 :param media_id: 待发送的图文 Media ID
699 :return: 返回的 JSON 数据包
700 """
701 # neither 'articles' nor 'media_id' is specified
702 if articles is None and media_id is None:
703 raise TypeError('must provide one parameter in "articles" and "media_id"')
704
705 # articles specified
706 if articles:
707 articles_data = []
708 for article in articles:
709 article = Article(**article)
710 articles_data.append({
711 'title': article.title,
712 'description': article.description,
713 'url': article.url,
714 'picurl': article.picurl,
715 })
716 return self.request.post(
717 url='https://api.weixin.qq.com/cgi-bin/message/custom/send',
718 data={
719 'touser': user_id,
720 'msgtype': 'news',
721 'news': {
722 'articles': articles_data,
723 },
724 }
725 )
726
727 # media_id specified
728 return self.request.post(
729 url='https://api.weixin.qq.com/cgi-bin/message/custom/send',
730 data={
731 'touser': user_id,
732 'msgtype': 'mpnews',
733 'mpnews': {
734 'media_id': media_id,
735 },
736 }
737 )
738
739 def create_qrcode(self, data):
740 """

Callers 1

Calls 2

ArticleClass · 0.85
postMethod · 0.80

Tested by 1