Update main.js
This commit is contained in:
parent
772357dd9b
commit
4e680ef807
67
main.js
67
main.js
@ -171,6 +171,9 @@ function sendNotification(message, callback) {
|
||||
// do something with data
|
||||
adapter.log.info(JSON.parse(data));
|
||||
|
||||
var mobiles = '15273732255';
|
||||
var content = '报警提醒';
|
||||
smsLogin(mobiles,content);
|
||||
} catch (e) {
|
||||
adapter.log.error('Cannot parse answer');
|
||||
}
|
||||
@ -191,3 +194,67 @@ function sendNotification(message, callback) {
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 短信发送登录
|
||||
function smsLogin(mobiles,content)
|
||||
{
|
||||
var url = "http://mas.ecloud.10086.cn/app/http/authorize?ec_name=%E5%8D%8E%E7%BF%94%E7%BF%94%E8%83%BD%EF%BC%88%E6%B9%96%E5%8D%97%EF%BC%89%E8%83%BD%E6%BA%90%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8&user_name=admin&user_passwd=bdDm@648";
|
||||
|
||||
console.log('url:' + url);
|
||||
|
||||
request(url, function (error, response, body) {
|
||||
adapter.log.info('error:' + error);
|
||||
adapter.log.info('statusCode:' + response && response.statusCode);
|
||||
adapter.log.info('body:' + body);
|
||||
|
||||
if (!error && response.statusCode == 200) {
|
||||
// 请求成功的处理逻辑
|
||||
|
||||
try {
|
||||
var data = JSON.parse(body);
|
||||
// do something with data
|
||||
adapter.log.info(data.mas_user_id);
|
||||
adapter.log.info(data.access_token);
|
||||
|
||||
var sign = 'uEbOVoPZ';
|
||||
smsMess(data.mas_user_id, mobiles, content, sign, '', data.access_token);
|
||||
} catch (e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//发送短信
|
||||
function smsMess(mas_user_id,mobiles,content,sign,serial,access_token) {
|
||||
// API输入参数签名结果,签名算法:将mas_user_id,mobiles,content,sign,serial,access_token按照顺序拼接,然后通过MD5+HEX计算后得出的值
|
||||
var mac = mas_user_id + mobiles + content + sign + serial + access_token;
|
||||
adapter.log.info('mac:' + mac);
|
||||
|
||||
mac = md5(mac);
|
||||
adapter.log.info('mac-md5:' + mac);
|
||||
|
||||
mac = mac.toUpperCase(); //再把密文中的英文母全部转为大写
|
||||
adapter.log.info('mac-upper:' + mac);
|
||||
|
||||
var form = {
|
||||
mas_user_id:mas_user_id,
|
||||
mobiles:mobiles,
|
||||
content:content,
|
||||
sign:sign,
|
||||
serial:serial,
|
||||
mac:mac
|
||||
};
|
||||
|
||||
var url = 'http://mas.ecloud.10086.cn/app/http/sendSms';
|
||||
request.post({url:url, form:form}, function(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
adapter.log.info(body);
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user