chore: change sms to use sms panel of danak
This commit is contained in:
@@ -98,13 +98,13 @@ function sendConfirmationSMS(userId) {
|
|||||||
user.mobileConfirmationKey = mobileKey
|
user.mobileConfirmationKey = mobileKey
|
||||||
await user.save()
|
await user.save()
|
||||||
|
|
||||||
const smsMsg = [
|
// const smsMsg = [
|
||||||
'این شماره در وبسایت آسان سرویس جهت ارائه خدمات گارانتی ثبت گردیده.',
|
// 'این شماره در وبسایت آسان سرویس جهت ارائه خدمات گارانتی ثبت گردیده.',
|
||||||
' کد تایید شماره همراه: ',
|
// ' کد تایید شماره همراه: ',
|
||||||
mobileKey
|
// mobileKey
|
||||||
]
|
// ]
|
||||||
|
|
||||||
await SMS([user.mobile_number], smsMsg.join(''))
|
await SMS(user.mobile_number, mobileKey)
|
||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -1,53 +1,81 @@
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
|
|
||||||
const accountInfo = {
|
// const accountInfo = {
|
||||||
Username: 'asanservice.sms@gmail.com',
|
// Username: 'asanservice.sms@gmail.com',
|
||||||
Password: '9u&8[Ve9',
|
// Password: '9u&8[Ve9',
|
||||||
Number: '5000467341',
|
// Number: '5000467341',
|
||||||
url: 'http://www.afe.ir/WebService/V4/BoxService.asmx'
|
// url: 'http://www.afe.ir/WebService/V4/BoxService.asmx'
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// /////// http post soap method
|
/// /////// http post soap method
|
||||||
module.exports.SMS = (mobileNumbersArray, message) => {
|
// module.exports.SMS = (mobileNumbersArray, message) => {
|
||||||
return new Promise((resolve, reject) => {
|
// return new Promise((resolve, reject) => {
|
||||||
function renderMobileNumbers(array) {
|
// function renderMobileNumbers(array) {
|
||||||
return array.map(item => `<string>${item}</string>`).join('')
|
// return array.map(item => `<string>${item}</string>`).join('')
|
||||||
}
|
// }
|
||||||
|
|
||||||
const xml = `<?xml version="1.0" encoding="utf-8"?>
|
// const xml = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
// <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||||
<soap:Body>
|
// <soap:Body>
|
||||||
<SendMessage xmlns="http://www.afe.ir/">
|
// <SendMessage xmlns="http://www.afe.ir/">
|
||||||
<Username>${accountInfo.Username}</Username>
|
// <Username>${accountInfo.Username}</Username>
|
||||||
<Password>${accountInfo.Password}</Password>
|
// <Password>${accountInfo.Password}</Password>
|
||||||
<Number>${accountInfo.Number}</Number>
|
// <Number>${accountInfo.Number}</Number>
|
||||||
<Mobile>
|
// <Mobile>
|
||||||
${renderMobileNumbers(mobileNumbersArray)}
|
// ${renderMobileNumbers(mobileNumbersArray)}
|
||||||
</Mobile>
|
// </Mobile>
|
||||||
<Message>${message}</Message>
|
// <Message>${message}</Message>
|
||||||
<Type>1</Type>
|
// <Type>1</Type>
|
||||||
</SendMessage>
|
// </SendMessage>
|
||||||
</soap:Body>
|
// </soap:Body>
|
||||||
</soap:Envelope>`
|
// </soap:Envelope>`
|
||||||
|
|
||||||
axios
|
// console.log('here')
|
||||||
.post(accountInfo.url, xml, {
|
// axios
|
||||||
headers: {
|
// .post(accountInfo.url, xml, {
|
||||||
'Content-Type': 'text/xml; charset=utf-8',
|
// headers: {
|
||||||
SOAPAction: 'http://www.afe.ir/SendMessage'
|
// 'Content-Type': 'text/xml; charset=utf-8',
|
||||||
}
|
// SOAPAction: 'http://www.afe.ir/SendMessage'
|
||||||
})
|
// }
|
||||||
.then(res => {
|
// })
|
||||||
resolve(res)
|
// .then(res => {
|
||||||
})
|
// resolve(res)
|
||||||
.catch(err => {
|
// })
|
||||||
console.log(
|
// .catch(err => {
|
||||||
'this is sms module error ------------------ status code: ',
|
// console.log(
|
||||||
err.response.status,
|
// 'this is sms module error ------------------ status code: ',
|
||||||
'error message: ',
|
// err.response.status,
|
||||||
err.response.data
|
// 'error message: ',
|
||||||
)
|
// err.response.data
|
||||||
resolve(err)
|
// )
|
||||||
})
|
// reject(err)
|
||||||
})
|
// })
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
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 { data } = await axios.post(smsCredential.url, smsData, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return data.IsSuccessful
|
||||||
|
} catch (error) {
|
||||||
|
console.log('error in sms module', error)
|
||||||
|
throw new Error('error in sms module')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user