admin管理员组文章数量:1278976
I'm trying to read the message about the correct or incorrect sending of an sms message by the Yeastar TG200 gateway. In the browser I get this message in html form:
<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
Response: Success
Message: Commit successfully!
</pre></body></html>
When I try to do this via axios or fetch I always get an error with headers: SMS sending error: Parse Error: Invalid header token Despite error, text message sends correctly.
const smsConfig = {
ip: "192.168.1.10",
user: "user",
pass: "password1q!",
port: "1",
};
async function sendDirect(phoneNumber, message, port = "1") {
if (!phoneNumber || !message) {
throw new Error("Provide a phone number and the content of the message");
}
if (port !== "1" && port !== "2") {
throw new Error("The port must be 1 or 2");
}
//Replace spaces in the body of the message with “+” characters
const encodedMessage = message.replace(/ /g, '+');
const url = `http://${smsConfig.ip}/cgi/WebCGI?1500101=account=${smsConfig.user}&password=${smsConfig.pass}&port=${port}&destination=${phoneNumber}&content=${encodedMessage }`;
console.log(`sending to: ${url}`);
try {
const response = await axios.get(url, {
timeout: 30000,
});
console.log("Response from the gate:", response.data);
if (response.data.toLowerCase().includes("response: success")) {
console.log(`✅ SMS sent successfully to ${phoneNumber}`);
} else {
console.error(`❌ Error when sending SMS: ${response.data}`);
}
} catch (error) {
console.error("SMS sending error:", error.message);
}
}
async function main() {
await sendDirect("555555555", "Test Test2");
}
main();
本文标签: nodejsValidation of sending sms through sms gatewayYeastarStack Overflow
版权声明:本文标题:node.js - Validation of sending sms through sms gateway - Yeastar - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741269421a2368996.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论