我正在尝试使用 at 命令发送多部分消息,单部分工作正常,特殊字符也是如此,但是当其多部分超过 160 个字符时,它说已发送,但没有收到任何内容。
async sendSMS(msisdn, message) {
message += " ";
// Determine if message uses characters outside the GSM 7-bit default alphabet
const useUCS2 = !isGSMCharacterSet(message);
// Set character set based on message content
const characterSet = useUCS2 ? GSM.CharacterSet.UCS2 : GSM.CharacterSet.GSM;
await this.setCharacterSet(characterSet);
await this.setMessageFormat(GSM.MessageFormat.PDU);
// Generate PDUs for the message. Assume generateSubmit handles segmentation if needed.
const encoding = useUCS2 ? 'ucs2' : 'gsm';
const pdus = smsPdu.generateSubmit(msisdn, message, { encoding });
// Send each PDU segment sequentially
const results = [];
for (const pdu of pdus) {
// Send length of the PDU in bytes, not the message length
let length = pdu.length
await this.runCommand(`AT+CMGS=${length}`);
// Send the PDU and store the result
const result = await this.runCommand(`${pdu.hex}${CTRL_Z}`);
if (result.startsWith('+CMGS:')) {
console.log('Segment sent successfully:', result);
} else {
console.error('Error sending segment:', result);
break; // Consider handling this situation more gracefully
}
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 2 seconds before sending the next part
results.push(result);
}
return (results, pdus);
}
这是我发送命令的代码,它是 NodeGSM 模块的一个分支,我使用 node-sms-pdu 来创建 pdu 这是来自服务器的响应,包括 pdu,但没有收到任何内容 Sending SMS COM18 79429010 testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
段发送成功:+CMGS:149 分段发送成功:+CMGS:150 检查 COM17 的状态 Sending SMS COM18 79429010 testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
段发送成功:+CMGS:149 分段发送成功:+CMGS:150 检查 COM17 的状态
回应2:[
{
缓冲区:
消息从 COM18 成功发送至 79429010。 消息已成功从 COM18 发送到 79429010。
尝试更改每条消息之间的时间,更改不同的模式,更改数字或消息的格式,但仍然没有任何效果
已解决 - 问题是 node-gsm-pdu 没有创建唯一的参考号,所以我每次都将值从 00 更改为唯一的数字。