update: sms service
This commit is contained in:
@@ -53,29 +53,34 @@ const axios = require('axios')
|
|||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const smsCredential = {
|
|
||||||
secretKey: 'drtime@A!@#',
|
|
||||||
apiKey: '569ee43ed0d9ac27708ce43d',
|
|
||||||
patternCode: '83604',
|
|
||||||
url: 'https://RestfulSms.com/api/UltraFastSend/direct'
|
|
||||||
}
|
|
||||||
module.exports.SMS = async (mobile, message) => {
|
module.exports.SMS = async (mobile, message) => {
|
||||||
try {
|
const smsService = new SmsService('QkkNxhyXZ6GtEf1soOTtikomO3mA4LaNQDH8mol8huDIwh00')
|
||||||
const smsData = {
|
return await smsService.sendOTPSms(message, mobile)
|
||||||
Mobile: mobile,
|
}
|
||||||
TemplateId: smsCredential.patternCode,
|
|
||||||
ParameterArray: [{ Parameter: 'code', ParameterValue: message }],
|
class SmsService {
|
||||||
UserApiKey: smsCredential.apiKey,
|
constructor(apiKey) {
|
||||||
SecretKey: smsCredential.secretKey
|
this.API_URL_FAST = 'https://api.sms.ir/v1'
|
||||||
|
this.OTP_PATTERN = '83604'
|
||||||
|
this.SMS_API_KEY = apiKey
|
||||||
}
|
}
|
||||||
const { data } = await axios.post(smsCredential.url, smsData, {
|
|
||||||
|
async sendOTPSms(otp, phone) {
|
||||||
|
const smsData = {
|
||||||
|
Parameters: [{ name: 'code', value: `${otp}` }],
|
||||||
|
Mobile: phone,
|
||||||
|
TemplateId: this.OTP_PATTERN
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const { data } = await axios.post(`${this.API_URL_FAST}/send/verify`, smsData, {
|
||||||
headers: {
|
headers: {
|
||||||
|
'X-API-KEY': this.SMS_API_KEY,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return data.IsSuccessful
|
return data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error in sms module', error)
|
console.error('Error in sending OTP SMS', error)
|
||||||
throw new Error('error in sms module')
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user