Commit c4125e0e by v_vjyjiang

d

parent bc8e3354
...@@ -23,7 +23,7 @@ class VCodeCache extends CacheBase { ...@@ -23,7 +23,7 @@ class VCodeCache extends CacheBase {
var signName = items ? items[0] : ""; var signName = items ? items[0] : "";
var vcode = await this.smsUtil.getUidStr(6, 10); var vcode = await this.smsUtil.getUidStr(6, 10);
if (!tmplCode && !signName) { if (!tmplCode && !signName) {
console.log("=====================================") console.log("=====================================", mobile, vcode)
this.smsUtil.sendMsg(mobile, vcode); this.smsUtil.sendMsg(mobile, vcode);
} //tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码 } //tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
else { else {
......
const system=require("../system"); const system = require("../system");
const Core = require('@alicloud/pop-core'); const Core = require('@alicloud/pop-core');
class SmsClient{ class SmsClient {
constructor(){ constructor() {
this.smsTeml="http://123.57.156.109:4103/api/Send"; this.smsTeml = "http://123.57.156.109:4103/api/Send";
this.restClient=system.getObject("util.restClient"); this.restClient = system.getObject("util.restClient");
this.aliclient=new Core({ this.aliclient = new Core({
accessKeyId: 'LTAI4FtNp3wcqFzaADvo1WtZ', accessKeyId: 'LTAI4FtNp3wcqFzaADvo1WtZ',
accessKeySecret: 'VBKn1Anx4UmMF0LKNz7PVaCFG1phcg', accessKeySecret: 'VBKn1Anx4UmMF0LKNz7PVaCFG1phcg',
endpoint: 'https://dysmsapi.aliyuncs.com', endpoint: 'https://dysmsapi.aliyuncs.com',
apiVersion: '2017-05-25' apiVersion: '2017-05-25'
}); });
}
async aliSendMsg(to,tmplcode,signName,jsonContent){ }
var params = {
"RegionId": "default", async aliSendMsg (to, tmplcode, signName, jsonContent) {
"PhoneNumbers": to, var params = {
"SignName": signName, "RegionId": "default",
"TemplateCode": tmplcode, "PhoneNumbers": to,
"TemplateParam": jsonContent "SignName": signName,
} "TemplateCode": tmplcode,
var requestOption = { "TemplateParam": jsonContent
method: 'POST'
};
this.aliclient.request('SendSms', params, requestOption).then((result) => {
console.log(JSON.stringify(result));
}, (ex) => {
console.log(ex);
})
} }
var requestOption = {
method: 'POST'
};
this.aliclient.request('SendSms', params, requestOption).then((result) => {
console.log(JSON.stringify(result));
}, (ex) => {
console.log(ex);
})
}
async sendMsg(to,content){ async sendMsg (to, content) {
var txtObj ={ var txtObj = {
"appId":8, "appId": 8,
"mobilePhone":to, "mobilePhone": to,
"content":content "content": content
}
return this.restClient.execPost(txtObj,this.smsTeml);
} }
async getUidStr(len, radix) { return this.restClient.execPost(txtObj, this.smsTeml);
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); }
var uuid = [], i; async getUidStr (len, radix) {
radix = radix || chars.length; var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
if (len) { var uuid = [], i;
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; radix = radix || chars.length;
} else { if (len) {
var r; for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; } else {
uuid[14] = '4'; var r;
for (i = 0; i < 36; i++) { uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
if (!uuid[i]) { uuid[14] = '4';
r = 0 | Math.random() * 16; for (i = 0; i < 36; i++) {
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; if (!uuid[i]) {
} r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
} }
} }
return uuid.join('');
} }
return uuid.join('');
}
} }
module.exports=SmsClient; module.exports = SmsClient;
// var sms=new SmsClient(); // var sms=new SmsClient();
// sms.aliSendMsg("13381139519","SMS_173946419","iboss",JSON.stringify({code:"hello"})); // sms.aliSendMsg("13381139519","SMS_173946419","iboss",JSON.stringify({code:"hello"}));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment