This commit is contained in:
HAM!DREZA
2025-02-16 19:36:01 +03:30
+22 -17
View File
@@ -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) => {
try {
const smsData = {
Mobile: mobile,
TemplateId: smsCredential.patternCode,
ParameterArray: [{ Parameter: 'code', ParameterValue: message }],
UserApiKey: smsCredential.apiKey,
SecretKey: smsCredential.secretKey
const smsService = new SmsService('QkkNxhyXZ6GtEf1soOTtikomO3mA4LaNQDH8mol8huDIwh00')
return await smsService.sendOTPSms(message, mobile)
}
class SmsService {
constructor(apiKey) {
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: {
'X-API-KEY': this.SMS_API_KEY,
'Content-Type': 'application/json'
}
})
return data.IsSuccessful
return data
} catch (error) {
console.log('error in sms module', error)
throw new Error('error in sms module')
console.error('Error in sending OTP SMS', error)
}
}
}