admin管理员组文章数量:1025217
I am writing application in nodejs for sending and recieving sms in PDU mode.I use wave GSM modem(7-bit encoding) to send sms. It also support 8 bit(AT+CSMP=1,167,0,8) encoding scheme.
I can send alpha numeric character properly.But I can't send some character like ([,],| etc).
Here string :
AT+CMGS=14
0001030C911989890878800004015B
Text String : [
But I recieve some junk character. Any Idea?
And how to send multipart sms. I have refer this, and this but I does not get desired output. can anyone suggest 8-bit(7-bit encoding scheme) text encoding scheme? Please Help me...
I am writing application in nodejs for sending and recieving sms in PDU mode.I use wave GSM modem(7-bit encoding) to send sms. It also support 8 bit(AT+CSMP=1,167,0,8) encoding scheme.
I can send alpha numeric character properly.But I can't send some character like ([,],| etc).
Here string :
AT+CMGS=14
0001030C911989890878800004015B
Text String : [
But I recieve some junk character. Any Idea?
And how to send multipart sms. I have refer this, and this but I does not get desired output. can anyone suggest 8-bit(7-bit encoding scheme) text encoding scheme? Please Help me...
Share Improve this question asked May 1, 2012 at 13:46 Paresh ThummarParesh Thummar 9287 silver badges20 bronze badges 1- have you tried escaping the characters yet? – Gonçalo Vieira Commented May 11, 2012 at 8:21
2 Answers
Reset to default 4 +50According to this page (see section Sending an Unicode SMS message), the 8bit encoding is in fact UCS-2.
I don't know enough about nodejs to give you the full implementation, but here is a .NET sample:
string EncodeSmsText(string text)
{
// Convert input string to a sequence of bytes in BigEndian UCS-2 encoding
// 'Hi' -> [0, 72, 0, 105]
var bytes = Encoding.BigEndianUnicode.GetBytes(text);
// Encode bytes to hex representation
// [0, 72, 0, 105] -> '00480069'
return BitConverter.ToString(bytes).Replace("-", "");
}
Please note that according to this post my code will not work for characters encoded as surrogate pairs, because Encoding.BigEndianEncoding
is UTF-16 (not UCS-2).
Edit
Here is NodeJS version that uses the built-in UCS2 converter in Buffer class:
function swapBytes(buffer) {
var l = buffer.length;
if (l & 0x01) {
throw new Error('Buffer length must be even');
}
for (var i = 0; i < l; i += 2) {
var a = buffer[i];
buffer[i] = buffer[i+1];
buffer[i+1] = a;
}
return buffer;
}
function encodeSmsText(input) {
var ucs2le = new Buffer(input, 'ucs2');
var ucs2be = swapBytes(ucs2le);
return ucs2be.toString('hex');
}
console.log(encodeSmsText('Hi'));
Inspired by these SO answers:
- Node.JS Big-Endian UCS-2
- How to do Base64 encoding in node.js?
Thanks,
Finally I got the answer :)
This characters([,],|) are encode as two characters like
[
is encode as 1B1E
(Combination of escape character and < sign)
]
is encode as 1B20
(Combination of escap character and > sign)
So whenever I fond such characters I replaced it with corresponding value then I use 7 bit encoding. It's Work good...
So my encoding string for [ is
> AT+CMGS=15
> 0001000C911989890878800000021B1E
And for "[hello]"
> AT+CMGS=21
> 0001000C911989890878800000091B1EBACC66BF373E
Thanks once again..
I am writing application in nodejs for sending and recieving sms in PDU mode.I use wave GSM modem(7-bit encoding) to send sms. It also support 8 bit(AT+CSMP=1,167,0,8) encoding scheme.
I can send alpha numeric character properly.But I can't send some character like ([,],| etc).
Here string :
AT+CMGS=14
0001030C911989890878800004015B
Text String : [
But I recieve some junk character. Any Idea?
And how to send multipart sms. I have refer this, and this but I does not get desired output. can anyone suggest 8-bit(7-bit encoding scheme) text encoding scheme? Please Help me...
I am writing application in nodejs for sending and recieving sms in PDU mode.I use wave GSM modem(7-bit encoding) to send sms. It also support 8 bit(AT+CSMP=1,167,0,8) encoding scheme.
I can send alpha numeric character properly.But I can't send some character like ([,],| etc).
Here string :
AT+CMGS=14
0001030C911989890878800004015B
Text String : [
But I recieve some junk character. Any Idea?
And how to send multipart sms. I have refer this, and this but I does not get desired output. can anyone suggest 8-bit(7-bit encoding scheme) text encoding scheme? Please Help me...
Share Improve this question asked May 1, 2012 at 13:46 Paresh ThummarParesh Thummar 9287 silver badges20 bronze badges 1- have you tried escaping the characters yet? – Gonçalo Vieira Commented May 11, 2012 at 8:21
2 Answers
Reset to default 4 +50According to this page (see section Sending an Unicode SMS message), the 8bit encoding is in fact UCS-2.
I don't know enough about nodejs to give you the full implementation, but here is a .NET sample:
string EncodeSmsText(string text)
{
// Convert input string to a sequence of bytes in BigEndian UCS-2 encoding
// 'Hi' -> [0, 72, 0, 105]
var bytes = Encoding.BigEndianUnicode.GetBytes(text);
// Encode bytes to hex representation
// [0, 72, 0, 105] -> '00480069'
return BitConverter.ToString(bytes).Replace("-", "");
}
Please note that according to this post my code will not work for characters encoded as surrogate pairs, because Encoding.BigEndianEncoding
is UTF-16 (not UCS-2).
Edit
Here is NodeJS version that uses the built-in UCS2 converter in Buffer class:
function swapBytes(buffer) {
var l = buffer.length;
if (l & 0x01) {
throw new Error('Buffer length must be even');
}
for (var i = 0; i < l; i += 2) {
var a = buffer[i];
buffer[i] = buffer[i+1];
buffer[i+1] = a;
}
return buffer;
}
function encodeSmsText(input) {
var ucs2le = new Buffer(input, 'ucs2');
var ucs2be = swapBytes(ucs2le);
return ucs2be.toString('hex');
}
console.log(encodeSmsText('Hi'));
Inspired by these SO answers:
- Node.JS Big-Endian UCS-2
- How to do Base64 encoding in node.js?
Thanks,
Finally I got the answer :)
This characters([,],|) are encode as two characters like
[
is encode as 1B1E
(Combination of escape character and < sign)
]
is encode as 1B20
(Combination of escap character and > sign)
So whenever I fond such characters I replaced it with corresponding value then I use 7 bit encoding. It's Work good...
So my encoding string for [ is
> AT+CMGS=15
> 0001000C911989890878800000021B1E
And for "[hello]"
> AT+CMGS=21
> 0001000C911989890878800000091B1EBACC66BF373E
Thanks once again..
本文标签: javascriptSupportandcharacters in PDU modeStack Overflow
版权声明:本文标题:javascript - Support [ and ] characters in PDU mode - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745613855a2159167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论