Restore 0098 SOAP SMS with link fallback and clearer errors
This commit is contained in:
+14
-8
@@ -1,18 +1,17 @@
|
||||
import 'dotenv/config';
|
||||
|
||||
const username = process.env.SMS_USERNAME;
|
||||
const password = process.env.SMS_PASSWORD;
|
||||
const password = process.env.SMS_PASSWORD ?? process.env.SMS_API_KEY;
|
||||
const sender = process.env.SMS_SENDER;
|
||||
|
||||
if (!username || !password || !sender) {
|
||||
console.error('Missing SMS env vars');
|
||||
console.error('Set SMS_USERNAME, SMS_PASSWORD (or SMS_API_KEY), and SMS_SENDER in .env');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const text = 'Montime code: 123456';
|
||||
const targets = process.argv.slice(2).length
|
||||
? process.argv.slice(2)
|
||||
: ['09397439581', '09128081392'];
|
||||
: ['09397439581'];
|
||||
|
||||
function escapeXml(value) {
|
||||
return String(value)
|
||||
@@ -23,9 +22,11 @@ function escapeXml(value) {
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
const text = 'کد ورود منتایم: 123456';
|
||||
|
||||
for (const mobile of targets) {
|
||||
const soapBody = `<?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:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body>
|
||||
<SendSMS xmlns="http://tempuri.org/">
|
||||
<username>${escapeXml(username)}</username>
|
||||
@@ -44,10 +45,15 @@ for (const mobile of targets) {
|
||||
SOAPAction: 'http://tempuri.org/SendSMS',
|
||||
},
|
||||
body: soapBody,
|
||||
signal: AbortSignal.timeout(20000),
|
||||
signal: AbortSignal.timeout(20_000),
|
||||
});
|
||||
|
||||
const body = await res.text();
|
||||
const match = body.match(/<SendSMSResult[^>]*>([^<]*)<\/SendSMSResult>/);
|
||||
console.log(mobile, 'HTTP', res.status, 'RESULT', match?.[1] ?? body.slice(0, 200));
|
||||
const match = body.match(/<SendSMSResult[^>]*>([^<]*)<\/SendSMSResult>/i);
|
||||
const code = match?.[1]?.trim() ?? '?';
|
||||
|
||||
console.log(`mobile=${mobile} http=${res.status} RESULT=${code}`);
|
||||
if (code !== '0') {
|
||||
console.log(body.slice(0, 400));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user