Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions docs/apis/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions itchatmp/controllers/mpapi/mp/templatemsgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down