-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env node | ||
// -*- coding:utf-8 -*- | ||
// File : template-message.js | ||
// Author : bss | ||
// Project : wechat_alerter | ||
// Description : 发送模板消息 | ||
// | ||
|
||
|
||
var request = require('request'); | ||
|
||
var TEMPLATE_URL_PREFIX = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='; | ||
|
||
|
||
/** | ||
* 发送模板消息 | ||
* @param message 消息本体 | ||
* @param accessToken ACCESS_TOKEN | ||
* @param templateId 模板ID | ||
* @param user 要推送的用户 | ||
*/ | ||
function sendTemplateMessage(message, accessToken, templateId, user) { | ||
|
||
var url = TEMPLATE_URL_PREFIX + accessToken; | ||
|
||
var json = { | ||
"touser": user, | ||
"template_id": templateId, | ||
"topcolor": "#FF0000", | ||
"data": { | ||
"Message": { | ||
"value": message, | ||
"color": "#000000" | ||
} | ||
} | ||
}; | ||
|
||
var options = { | ||
url: url, | ||
method: 'POST', | ||
json: true, | ||
body: json | ||
}; | ||
|
||
request(options, function(error, response, data) { | ||
try { | ||
if (data.errcode != 0) { | ||
console.log(data); | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}); | ||
} | ||
|
||
|
||
exports.sendTemplateMessage = sendTemplateMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters