From 36af2421efb8f36ca576349a0713208ed7ea8051 Mon Sep 17 00:00:00 2001 From: Hetian Huo Date: Mon, 3 Jul 2017 16:33:21 +0800 Subject: [PATCH 1/2] Update templatemsgs.py --- itchatmp/controllers/mpapi/mp/templatemsgs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/itchatmp/controllers/mpapi/mp/templatemsgs.py b/itchatmp/controllers/mpapi/mp/templatemsgs.py index a860c5a..42aa449 100644 --- a/itchatmp/controllers/mpapi/mp/templatemsgs.py +++ b/itchatmp/controllers/mpapi/mp/templatemsgs.py @@ -64,11 +64,12 @@ def _wrap_result(result): def send(templateId, msgDict, toUserId, accessToken=None): ''' send template to your massive platform users ''' - msgDict = copy.deepcopy(msgDict) - msgDict['touser'], msgDict['template_id'] = toUserId, templateId + url = msgDict.pop('url', None) + msgDict['data'] = copy.deepcopy(msgDict) + msgDict['touser'], msgDict['template_id'], msgDict['url'] = toUserId, templateId, url data = encode_send_dict(msgDict) if data is None: return ReturnValue({'errcode': -10001}) - r = requests.post('%s/cgi-bin/template/del_private_template?access_token=%s' % + r = requests.post('%s/cgi-bin/message/template/send?access_token=%s' % (SERVER_URL, accessToken), data=data) def _wrap_result(result): return ReturnValue(result.json()) From d33a17a6e7c5166165b74805fb5203c9216013b3 Mon Sep 17 00:00:00 2001 From: Hetian Huo Date: Mon, 3 Jul 2017 16:37:29 +0800 Subject: [PATCH 2/2] Update messages.md --- docs/apis/messages.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/apis/messages.md b/docs/apis/messages.md index 8a8ecd6..a7a7c14 100644 --- a/docs/apis/messages.md +++ b/docs/apis/messages.md @@ -105,13 +105,22 @@ itchatmp.messages.send_all(TEXT, 'this is a sendall') ```python templateId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' msgDict = { - 'title': 'Title', - 'user': 'User', - 'content': 'Content', } + 'title': {'value': 'Title'}, + 'user': {'value': 'User'}, + 'content': {'value': 'Content', 'color': '#173177'}, } toUserName = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' r = itchatmp.templatemsgs.send(templateId, msgDict, toUserName) print(r) ``` +如果想在模版中加入可点链接, 在msgDict中加入url: +```python +msgDict = { + 'title': {'value': 'Title'}, + 'user': {'value': 'User'}, + 'content': {'value': 'Content', 'color': '#173177'}, + 'url': 'www.github.com', } + ``` + [mp-wiki]: https://mp.weixin.qq.com/wiki