Skip to content

Commit

Permalink
caizhibang:20180910 modify sms auth
Browse files Browse the repository at this point in the history
  • Loading branch information
caizhibang committed Sep 10, 2018
1 parent f6a900e commit d7adabf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 68 deletions.
122 changes: 68 additions & 54 deletions controller/setting/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,41 @@ class Setting {
if(req.body.weixin.ssid == null){
req.body.weixin.ssid = 'ApFreeWiFiDog';
}
if(req.body.sms.appId == null){
req.body.sms.appId = null;
req.body.sms.appSecret = null;
req.body.sms.smsSignName = null;
req.body.sms.smsTemplateCode = null;
}else if(req.body.sms.wyAppId == null){
req.body.sms.wyAppId = null;
req.body.sms.wyAppSecret = null;
req.body.sms.wyTemplateId = null;
if(req.body.sms.selected == 'ali'){
var gwidSetting = {
'channelPath': channelPath,
'wificoin.toAddress': req.body.wificoin.toAddress,
'wificoin.toAmount': req.body.wificoin.toAmount*1000000,
'weixin.appId': req.body.weixin.appId,
'weixin.shopId': req.body.weixin.shopId,
'weixin.secretKey': req.body.weixin.secretKey,
'weixin.ssid': req.body.weixin.ssid,
'sms.appId': req.body.sms.appId,
'sms.appSecret': req.body.sms.appSecret,
'sms.smsSignName': req.body.sms.smsSignName,
'sms.smsTemplateCode': req.body.sms.smsTemplateCode,
'sms.selected': req.body.sms.selected,
'portalUrl': req.body.portalUrl,
'duration': req.body.duration*3600
};
}else if(req.body.sms.selected == 'wy'){
var gwidSetting = {
'channelPath': channelPath,
'wificoin.toAddress': req.body.wificoin.toAddress,
'wificoin.toAmount': req.body.wificoin.toAmount*1000000,
'weixin.appId': req.body.weixin.appId,
'weixin.shopId': req.body.weixin.shopId,
'weixin.secretKey': req.body.weixin.secretKey,
'weixin.ssid': req.body.weixin.ssid,
'sms.wyAppId': req.body.sms.wyAppId,
'sms.wyAppSecret': req.body.sms.wyAppSecret,
'sms.wyTemplateId':req.body.sms.wyTemplateId,
'sms.selected': req.body.sms.selected,
'portalUrl': req.body.portalUrl,
'duration': req.body.duration*3600
};
}

var gwidSetting = {
'channelPath': channelPath,
'wificoin.toAddress': req.body.wificoin.toAddress,
'wificoin.toAmount': req.body.wificoin.toAmount*1000000,
'weixin.appId': req.body.weixin.appId,
'weixin.shopId': req.body.weixin.shopId,
'weixin.secretKey': req.body.weixin.secretKey,
'weixin.ssid': req.body.weixin.ssid,
'sms.appId': req.body.sms.appId,
'sms.appSecret': req.body.sms.appSecret,
'sms.smsSignName': req.body.sms.smsSignName,
'sms.smsTemplateCode': req.body.sms.smsTemplateCode,
'sms.wyAppId': req.body.sms.wyAppId,
'sms.wyAppSecret': req.body.sms.wyAppSecret,
'sms.wyTemplateId':req.body.sms.wyTemplateId,
'portalUrl': req.body.portalUrl,
'duration': req.body.duration*3600
};
const result = await ChannelPathModel.findOneAndUpdate({'channelPath': channelPath}, gwidSetting, {new:true});
if(!result){
res.send({ret_code: 1002, ret_msg: 'FAILED', extra:'设置失败'});
Expand Down Expand Up @@ -85,34 +91,41 @@ class Setting {
if(req.body.weixin.ssid == null){
req.body.weixin.ssid = 'ApFreeWiFiDog';
}
if(req.body.sms.appId == null){
req.body.sms.appId = null;
req.body.sms.appSecret = null;
req.body.sms.smsSignName = null;
req.body.sms.smsTemplateCode = null;
}else if(req.body.sms.wyAppId == null){
req.body.sms.wyAppId = null;
req.body.sms.wyAppSecret = null;
req.body.sms.wyTemplateId = null;
if(req.body.sms.selected == 'ali'){
var gwidSetting = {
'channelPath': channelPath,
'wificoin.toAddress': req.body.wificoin.toAddress,
'wificoin.toAmount': req.body.wificoin.toAmount*1000000,
'weixin.appId': req.body.weixin.appId,
'weixin.shopId': req.body.weixin.shopId,
'weixin.secretKey': req.body.weixin.secretKey,
'weixin.ssid': req.body.weixin.ssid,
'sms.appId': req.body.sms.appId,
'sms.appSecret': req.body.sms.appSecret,
'sms.smsSignName': req.body.sms.smsSignName,
'sms.smsTemplateCode': req.body.sms.smsTemplateCode,
'sms.selected': req.body.sms.selected,
'portalUrl': req.body.portalUrl,
'duration': req.body.duration*3600
};
}else if(req.body.sms.selected == 'wy'){
var gwidSetting = {
'channelPath': channelPath,
'wificoin.toAddress': req.body.wificoin.toAddress,
'wificoin.toAmount': req.body.wificoin.toAmount*1000000,
'weixin.appId': req.body.weixin.appId,
'weixin.shopId': req.body.weixin.shopId,
'weixin.secretKey': req.body.weixin.secretKey,
'weixin.ssid': req.body.weixin.ssid,
'sms.wyAppId': req.body.sms.wyAppId,
'sms.wyAppSecret': req.body.sms.wyAppSecret,
'sms.wyTemplateId':req.body.sms.wyTemplateId,
'sms.selected': req.body.sms.selected,
'portalUrl': req.body.portalUrl,
'duration': req.body.duration*3600
};
}
var channelPathSetting = {
'channelPath': channelPath,
'wificoin.toAddress': req.body.wificoin.toAddress,
'wificoin.toAmount': req.body.wificoin.toAmount*1000000,
'weixin.appId': req.body.weixin.appId,
'weixin.shopId': req.body.weixin.shopId,
'weixin.secretKey': req.body.weixin.secretKey,
'weixin.ssid': req.body.weixin.ssid,
'sms.appId': req.body.sms.appId,
'sms.appSecret': req.body.sms.appSecret,
'sms.smsSignName': req.body.sms.smsSignName,
'sms.smsTemplateCode': req.body.sms.smsTemplateCode,
'sms.wyAppId': req.body.sms.wyAppId,
'sms.wyAppSecret': req.body.sms.wyAppSecret,
'sms.wyTemplateId':req.body.sms.wyTemplateId,
'portalUrl': req.body.portalUrl,
'duration': req.body.duration*3600
};

const result = await ChannelPathModel.findOneAndUpdate({'channelPath': channelPath}, channelPathSetting, {new:true});
if(!result){
res.send({ret_code: 1002, ret_msg: 'FAILED', extra:'设置失败'});
Expand Down Expand Up @@ -152,6 +165,7 @@ class Setting {
smsWyAppId: channelPath.sms.wyAppId,
smsWyAppSecret: channelPath.sms.wyAppSecret,
smsWyTemplateId: channelPath.sms.wyTemplateId,
smsSelected: channelPath.sms.selected,
portalUrl: channelPath.portalUrl,
duration: channelPath.duration/3600
};
Expand Down
29 changes: 15 additions & 14 deletions controller/wifidog/wifidog.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,25 +370,15 @@ class Wifidog {
return Math.floor(Math.random()*10);
}).join('');

var nonce = function () {
return Math.random().toString(36).substr(2, 15);
};

var curTime = function () {
return parseInt(new Date().getTime() / 1000) + "";
};

const channelPath = await device.deviceSetting(gwId);
if (channelPath == null) {
res.send({ ret_code: 1002, ret_msg: 'FAILED', extra: '网关设备不存在' });
return;
}

var accessKeyId = channelPath.sms.appId;
var secretAccessKey = channelPath.sms.appSecret;
var wyAppId = channelPath.sms.wyAppId;
var wyAppSecret = channelPath.sms.wyAppSecret;
if(accessKeyId){
if(channelPath.sms.selected == 'ali'){
var accessKeyId = channelPath.sms.appId;
var secretAccessKey = channelPath.sms.appSecret;
var smsClient = new SMSClient({accessKeyId,secretAccessKey});
smsClient.sendSMS({
PhoneNumbers: phoneNumber,
Expand Down Expand Up @@ -417,13 +407,24 @@ class Wifidog {
console.log(err);
res.send({ ret_code: 1002, ret_msg: 'FAILED', extra: err.message });
});
}else if(wyAppId){
}else if(channelPath.sms.selected == 'wy'){
var wyAppId = channelPath.sms.wyAppId;
var wyAppSecret = channelPath.sms.wyAppSecret;
var post_data = {
templateid: channelPath.sms.wyTemplateId,
mobile: phoneNumber,
authCode: randomstr
};

var nonce = function () {
return Math.random().toString(36).substr(2, 15);
};

var curTime = function () {
return parseInt(new Date().getTime() / 1000) + "";
};


var content = qs.stringify(post_data);
var Nonce = nonce();
var CurTime = curTime();
Expand Down
1 change: 1 addition & 0 deletions models/setting/channelpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const channelPathSchema = new Schema({
wyAppId: {type: String, default: ''},
wyAppSecret: {type: String, default: ''},
wyTemplateId: {type: String, default: ''},
selected: {type:String, default: ''},
},
portalUrl: {type: String, default: 'https://talkblock.org/'},
duration: {type: Number, default: 3600}
Expand Down

0 comments on commit d7adabf

Please sign in to comment.