prettierrc
This commit is contained in:
parent
3a228b7af8
commit
c82f2af88b
16
.prettierrc.js
Normal file
16
.prettierrc.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
对 VSCode Prettier 有效;建议一直要有本配置文件,否则不同版本的 Prettier 的默认配置会不同,例如 TrailingComma
|
||||||
|
对 VSCode Prettier Standard 无效,似乎是集成了不能修改的配置。
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
printWidth: 160, // default 80
|
||||||
|
tabWidth: 2, // default 2
|
||||||
|
useTabs: false,
|
||||||
|
semi: false, // default true
|
||||||
|
singleQuote: true, // default false
|
||||||
|
trailingComma: 'es5', // none (default in v 1.*), es5 (default in v2.0.0), all
|
||||||
|
bracketSpacing: true, // default true
|
||||||
|
jsxBracketSameLine: false, // default false
|
||||||
|
arrowParens: 'always', // avoid (default in v1.9.0), always (default since v2.0.0)
|
||||||
|
quoteProps: 'as-needed', // as-needed (default), consistent, preserve
|
||||||
|
}
|
154
index.js
154
index.js
@ -1,90 +1,110 @@
|
|||||||
//const Bluebird=require('bluebird'); // http://bluebirdjs.com/
|
//const Bluebird=require('bluebird'); // http://bluebirdjs.com/
|
||||||
const util=require('util')
|
const util = require('util')
|
||||||
const RequestPromise=require('request-promise-native') // request-promise/-native。https://www.npmjs.com/package/request-promise. 还看到一个方法:Bluebird.promisifyAll(require("request"));
|
const RequestPromise = require('request-promise-native') // request-promise/-native。https://www.npmjs.com/package/request-promise. 还看到一个方法:Bluebird.promisifyAll(require("request"));
|
||||||
const NodeMailer=require('nodemailer') // 或者 const smtpTransporter=require('nodemailer').createTransport({host:'', port:25, auth:{user:'',pass:''}})
|
const NodeMailer = require('nodemailer') // 或者 const smtpTransporter=require('nodemailer').createTransport({host:'', port:25, auth:{user:'',pass:''}})
|
||||||
let smtpTransporter = null
|
let smtpTransporter = null
|
||||||
|
|
||||||
let smsClient = null // 在调用时,才创建 smsClient,防止 wo.Config 还没有建立好。
|
let smsClient = null // 在调用时,才创建 smsClient,防止 wo.Config 还没有建立好。
|
||||||
|
|
||||||
module.exports={
|
module.exports = {
|
||||||
sendMail: async function(option){ // 或者如果smtp参数已经确定,就可以直接定义 sendMail: Bluebird.promisify(Smtp.sendMail).bind(Smtp)
|
sendMail: async function (option) {
|
||||||
smtpTransporter=smtpTransporter||NodeMailer.createTransport(wo.Config.SMTP)
|
// 或者如果smtp参数已经确定,就可以直接定义 sendMail: Bluebird.promisify(Smtp.sendMail).bind(Smtp)
|
||||||
|
smtpTransporter = smtpTransporter || NodeMailer.createTransport(wo.Config.SMTP)
|
||||||
return await util.promisify(smtpTransporter.sendMail).call(smtpTransporter, option)
|
return await util.promisify(smtpTransporter.sendMail).call(smtpTransporter, option)
|
||||||
}
|
},
|
||||||
,
|
sendSms: async function (phone, option) {
|
||||||
sendSms: async function(phone, option){ // 通过option对象,对外提供统一的调用参数格式
|
// 通过option对象,对外提供统一的调用参数格式
|
||||||
if (/^\+\d+-\d+$/.test(phone)){
|
if (/^\+\d+-\d+$/.test(phone)) {
|
||||||
option=option||{}
|
option = option || {}
|
||||||
if (option.vendor==='dxton' && option.msg){
|
if (option.vendor === 'dxton' && option.msg) {
|
||||||
return await this.sendSmsDxton(phone, option.msg)
|
return await this.sendSmsDxton(phone, option.msg)
|
||||||
}else if (option.vendor==='aliyun' && option.msgParam && option.templateCode && option.signName){
|
} else if (option.vendor === 'aliyun' && option.msgParam && option.templateCode && option.signName) {
|
||||||
return await this.sendSmsAliyun(phone, option.msgParam, option.templateCode, option.signName)
|
return await this.sendSmsAliyun(phone, option.msgParam, option.templateCode, option.signName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null // 手机号格式错误,或者 option.vendor 错误。
|
return null // 手机号格式错误,或者 option.vendor 错误。
|
||||||
}
|
},
|
||||||
,
|
sendSmsDxton: async function (phone, msg) {
|
||||||
sendSmsDxton: async function(phone, msg){ // 使用 dxton.com 的短信接口。
|
// 使用 dxton.com 的短信接口。
|
||||||
var matches=phone.match(/\d+/g)
|
var matches = phone.match(/\d+/g)
|
||||||
var smsNumber, smsUrl
|
var smsNumber, smsUrl
|
||||||
if (matches[0]==='86'){
|
if (matches[0] === '86') {
|
||||||
smsUrl = wo.Config.SMS.dxton.urlChina
|
smsUrl = wo.Config.SMS.dxton.urlChina
|
||||||
smsNumber=matches[1]
|
smsNumber = matches[1]
|
||||||
}else{
|
} else {
|
||||||
smsUrl = wo.Config.SMS.dxton.urlWorld // 国际短信不需要签名、模板,可发送任意内容。
|
smsUrl = wo.Config.SMS.dxton.urlWorld // 国际短信不需要签名、模板,可发送任意内容。
|
||||||
smsNumber=matches[0]+matches[1]
|
smsNumber = matches[0] + matches[1]
|
||||||
}
|
}
|
||||||
// return Bluebird.promisify(Http.get)(smsUrl+'&mobile='+smsNumber+"&content="+encodeURIComponent(msg));
|
// return Bluebird.promisify(Http.get)(smsUrl+'&mobile='+smsNumber+"&content="+encodeURIComponent(msg));
|
||||||
let returnValue = await RequestPromise.get(smsUrl+'&mobile='+smsNumber+"&content="+encodeURIComponent(msg))
|
let returnValue = await RequestPromise.get(smsUrl + '&mobile=' + smsNumber + '&content=' + encodeURIComponent(msg))
|
||||||
let result = { state:'FAIL', code:returnValue }
|
let result = { state: 'FAIL', code: returnValue }
|
||||||
switch (parseInt(returnValue)) {
|
switch (parseInt(returnValue)) {
|
||||||
// 短信接口代码:http://www.dxton.com/help_detail/2.html
|
// 短信接口代码:http://www.dxton.com/help_detail/2.html
|
||||||
case 100: return { state:'DONE', code:'100', msg:'sendSms: 发送成功 (表示已和我们接口连通)' }
|
case 100:
|
||||||
case 101: result.msg='sendSms: 验证失败(账号、密码可能错误)'
|
return { state: 'DONE', code: '100', msg: 'sendSms: 发送成功 (表示已和我们接口连通)' }
|
||||||
case 102: result.msg='sendSms: 手机号码格式不正确'
|
case 101:
|
||||||
case 103: result.msg='sendSms: 会员级别不够'
|
result.msg = 'sendSms: 验证失败(账号、密码可能错误)'
|
||||||
case 104: result.msg='sendSms: 内容未审核 (试用或小批量应用,只能用系统后台公共模板格式,标点符号都要一致!)'
|
case 102:
|
||||||
case 105: result.msg='sendSms: 内容过多或无合适匹配通道'
|
result.msg = 'sendSms: 手机号码格式不正确'
|
||||||
case 106: result.msg='sendSms: 账户余额不足'
|
case 103:
|
||||||
case 107: result.msg='sendSms: Ip受限'
|
result.msg = 'sendSms: 会员级别不够'
|
||||||
case 108: result.msg='sendSms: 手机号码发送太频繁(一天5个),请换号或隔天再发'
|
case 104:
|
||||||
case 109: result.msg='sendSms: 帐号被锁定'
|
result.msg = 'sendSms: 内容未审核 (试用或小批量应用,只能用系统后台公共模板格式,标点符号都要一致!)'
|
||||||
case 110: result.msg='sendSms: 手机号发送频率持续过高,黑名单屏蔽数日'
|
case 105:
|
||||||
case 120: result.msg='sendSms: 系统升级'
|
result.msg = 'sendSms: 内容过多或无合适匹配通道'
|
||||||
default: console.error(result); return result
|
case 106:
|
||||||
|
result.msg = 'sendSms: 账户余额不足'
|
||||||
|
case 107:
|
||||||
|
result.msg = 'sendSms: Ip受限'
|
||||||
|
case 108:
|
||||||
|
result.msg = 'sendSms: 手机号码发送太频繁(一天5个),请换号或隔天再发'
|
||||||
|
case 109:
|
||||||
|
result.msg = 'sendSms: 帐号被锁定'
|
||||||
|
case 110:
|
||||||
|
result.msg = 'sendSms: 手机号发送频率持续过高,黑名单屏蔽数日'
|
||||||
|
case 120:
|
||||||
|
result.msg = 'sendSms: 系统升级'
|
||||||
|
default:
|
||||||
|
console.error(result)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sendSmsAliyun: async function(phone, msgParam, templateCode, signName){ // msgParam 是消息模板参数对象,例如 { code: "890353" }
|
sendSmsAliyun: async function (phone, msgParam, templateCode, signName) {
|
||||||
smsClient = smsClient || new (require('@alicloud/sms-sdk'))({ // 在调用时,才创建 smsClient,防止 wo.Config 还没有建立好。
|
// msgParam 是消息模板参数对象,例如 { code: "890353" }
|
||||||
accessKeyId:wo.Config.SMS.aliyun.accessKeyId,
|
smsClient =
|
||||||
secretAccessKey:wo.Config.SMS.aliyun.secretAccessKey
|
smsClient ||
|
||||||
|
new (require('@alicloud/sms-sdk'))({
|
||||||
|
// 在调用时,才创建 smsClient,防止 wo.Config 还没有建立好。
|
||||||
|
accessKeyId: wo.Config.SMS.aliyun.accessKeyId,
|
||||||
|
secretAccessKey: wo.Config.SMS.aliyun.secretAccessKey,
|
||||||
})
|
})
|
||||||
|
|
||||||
var matches=phone.match(/\d+/g)
|
var matches = phone.match(/\d+/g)
|
||||||
var smsNumber
|
var smsNumber
|
||||||
if (matches[0]==='86'){
|
if (matches[0] === '86') {
|
||||||
smsNumber=matches[1]
|
smsNumber = matches[1]
|
||||||
}else{
|
} else {
|
||||||
smsNumber='00'+matches[0]+matches[1]
|
smsNumber = '00' + matches[0] + matches[1]
|
||||||
}
|
}
|
||||||
return await smsClient.sendSMS({
|
return await smsClient
|
||||||
PhoneNumbers: smsNumber,//必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时,接收号码格式为00+国际区号+号码,如“0085200000000”
|
.sendSMS({
|
||||||
SignName: signName,//必填:短信签名-可在短信控制台中找到
|
PhoneNumbers: smsNumber, //必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时,接收号码格式为00+国际区号+号码,如“0085200000000”
|
||||||
TemplateCode: templateCode,//必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版
|
SignName: signName, //必填:短信签名-可在短信控制台中找到
|
||||||
TemplateParam: JSON.stringify(msgParam) //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时。
|
TemplateCode: templateCode, //必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版
|
||||||
}).then(
|
TemplateParam: JSON.stringify(msgParam), //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时。
|
||||||
function (res) {
|
})
|
||||||
let {Code}=res
|
.then(
|
||||||
if (Code === 'OK') {
|
function (res) {
|
||||||
return { state:'DONE' }
|
let { Code } = res
|
||||||
}else{
|
if (Code === 'OK') {
|
||||||
return { state:'FAIL', result:res }
|
return { state: 'DONE' }
|
||||||
|
} else {
|
||||||
|
return { state: 'FAIL', result: res }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (err) {
|
||||||
|
return { state: 'ERROR', error: err }
|
||||||
}
|
}
|
||||||
},
|
)
|
||||||
function (err) {
|
},
|
||||||
return { state:'ERROR', error:err }
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user