Skip to content

SMS

Unicode

UTF-8

  1. 对单字节,高位设为0, 后面7 bit为该符号的Unicode
  2. n(n>1)字节的字符,第一个字节的前n位设为1n+1位为0,后面字节的前两位均为10,余下部分为该字符的Unicode
Unicode符号范围(hex) | UTF-8编码方式(binary)
--------------------+---------------------------------------------
0000 0000-0000 007F | 0xxxxxxx
0000 0080-0000 07FF | 110xxxxx 10xxxxxx
0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

举例

字符 Unicode UTF-8
A U+0041 41
0 U+0030 30
U+4f60 E4BDA0
U+9955 E9A595

PDU mode

短信收发分text, PDU两种模式, 本文仅考虑PDU模式。 参考收发短信的PDU格式1,总结主要内容如下。

名词解释

元素 名称 描述
GSM Global System for Mobile Communications 全球移动通信系统
SMS Short Message Service 短信服务
SMSC Short Message Service Center 短信服务中心
PDU Protocol Data Unit 协议数据单元
RP Reply Path 应答路径
UDHI User Data Header Indicator 用户数据头标识
SRR Status Report Request 状态报告请求
SRI Status Report Indication 状态报告指示
RD Reject Duplicate 拒绝副本
MTI Message Type Indicator 信息类型指示
MR Message Reference 所有成功的SMS-SUBMIT参考数目
TON Type of number 号码类型
SCA Service Center Address 服务中心地址
OA Original Address 发送方地址(手机号码)
DA Destination Address 接收方地址(手机号码)
PID Protocol Identify 协议类型
DCS Data coding scheme 数据编码策略
VP Validity Period 消息在SMSC的有效期
VPF Validity Period Format 有效期格式
SCTS Service Center Timestamp 时间戳
UD User Data 用户数据
UDL User Data Length 用户数据长度

短信收发格式

发送短信

发送短信的PDU格式

接收短信

接收短信的PDU格式

SCA

SCA长度 SCA类型 SCA地址
1 Octet 0-1 Octet 0-10 Octet
08 91 683108200115F1
  • SCA 长度:SCA类型与SCA地址的总长度
  • SCA 类型:TON/NPI, 0x91最常用
  • SCA 地址:依照ISDN编号方式(+8613800210511, 13800210511, 123456)

TON(type of number)

  1. International: 91
  2. National: A1
  3. Unkown: 81

PDU Type

第一个8位位组,发送和接收的格式略有不同。

  • 发送格式:SMS-SUBMIT
7 6 5 4 3 2 1 0
RP UDHI SRR VPF RD MTI
0 0 1 10 0 01
  • 接收格式:SMS-DELIVER
7 6 5 4 3 2 1 0
RP UDHI SRI MMS MTI
0 0 0 00 1 00

这里比较关键的参数是UDHI,用户数据头部标识,为1代表该短信是长短信,被分为多条短信发送,用户数据部分包含头部信息。

DCS

DCS(Data coding scheme)

  1. 7-bit: 00
  2. 8-bit: F4
  3. UCS2: 08

接收短信

使用手机向带有SIM卡的LBR1020发送一条长短信:

生僻字

(滟灪爩鱻麤龖龗齾齉靐龘)拼音如下: 【汉语拼音】滟(yàn) 灪(yù) 爩(yù) 鱻(xiǎn) 麤(cū) 龖(dá) 龗(línɡ) 齾(yà) 齉(nànɡ) 靐(bìnɡ) 龘(dá)

通过mbctrl.sh --show-message获取SIM卡的短信列表

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
root@LBR1020:/# mbctrl.sh --show-message
---#Sent Command:AT+CMGL=4---
#Got response:
AT+CMGL=4
+CMGL: 0,1,,157
0891683108200115F36008A0018016000008026011319352238C05000384030130105F15988600355343514630118D2D7269629862634F1860E0591AFF0C00500052004F4F1A54580033002E003951436BCF670853EF4EAB5929732B30014EAC4E1C8D2D726952384F1860E04EF7FF0C8FD86709003551438BDD8D395238300100330030004700425A314E506D4191CF003151438D2D3001997F4E864E487EA2530530016EF4
+CMGL: 1,1,,73
0891683108200115F36008A00180160000080260113193622338050003840303590D201C548C4F60201D767B5F554E0A6D7779FB52A8548C4F6000410050005083B753D666F4591A4F1860E04FE1606FFF01
+CMGL: 2,1,,157
0891683108200115F36408A0018016000008026011319362238C0500038403026EF462538F667EA253057B498D85003100304E2A54C17C7B4F1860E0FF0C53055E7453E653EF514D8D39988653D60032003053EA533B752853E37F69FF018BE660C570B951FB002000680074007400700073003A002F002F00640078002E00310030003000380036002E0063006E002F0072006300570045004300670020621677ED4FE156DE
+CMGL: 3,1,,157
0891683108200115F36008A0018016000008026021413310238C0500034E0301301000350047770B79FB52A8301189C698914F1A5458662565E55927793C53056B6357286D3E9001FF0C72315947827A30014F189177300154D454E954D454E94F1A54584E0990094E00002B00310035004700424E135C5E6D4191CF72794EAB4EF700310035002E00395143002F670830028BE660C570B951FB002000680074007400700073
+CMGL: 4,1,,157
0891683108200115F36008A0018016000008026021413310238C0500034E0302003A002F002F00640078002E00310030003000380036002E0063006E002F004F00380039005F004100670020621677ED4FE156DE590D201C548C4F60201D767B5F554E0A6D7779FB52A8548C4F6000410050005083B753D666F4591A4F1860E04FE1606FFF01FF086CE8FF1A524D671F5DF253C24E0E4F1860E072794EAB4EF76D3B52A87684
+CMGL: 5,1,,53
0891683108200115F36408A001801600000802602141331023240500034E030375286237FF0C65E06CD591CD590D53C24E0E672C4F1860E06D3B52A8FF09
+CMGL: 6,0,,159
0891683108200115F1640BA17105611983F40008026021514111238C0500035A0201FF086EDF706A72299C7B9EA49F969F979F7E9F4997509F98FF0962FC97F359824E0BFF1A000A30106C498BED62FC97F330116EDF0028007900E0006E00290020706A0028007900F90029002072290028007900F9002900209C7B00280078006901CE006E002900209EA400280063016B002900209F960028006400E1002900209F970028006C
+CMGL: 7,0,,89
0891683108200115F1640BA17105611983F4000802602151415123460500035A020200ED006E0261002900209F7E0028007900E0002900209F490028006E00E0006E02610029002097500028006200EC006E0261002900209F980028006400E10029

OK

#Return Val:0

soap 测试

使用 SOAP Sender 发送WAN3GinterfaceConfig:1#GetSMSInfo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:GetSMSInfoResponse xmlns:m="urn:NETGEAR-ROUTER:service:WAN3GinterfaceConfig:1"> <NewSMS>
 <UnreadMsgs>0</UnreadMsgs>
 <MsgCounts>8</MsgCounts>
    <Msg>
    <Index>0</Index>
    <Time>2020/06/11 13:39:25 +32</Time>
    <Text>30105F15988600355343514630118D2D7269629862634F1860E0591AFF0C00500052004F4F1A54580033002E003951436BCF670853EF4EAB5929732B30014EAC4E1C8D2D726952384F1860E04EF7FF0C8FD86709003551438BDD8D395238300100330030004700425A314E506D4191CF003151438D2D3001997F4E864E487EA2530530016EF4</Text>
    <Type>SMS</Type>
    <Sender>10086100</Sender>
    <Read>true</Read>
    </Msg>
    <Msg>
    <Index>2</Index>
    <Time>2020/06/11 13:39:26 +32</Time>
    <Text>6EF462538F667EA253057B498D85003100304E2A54C17C7B4F1860E0FF0C53055E7453E653EF514D8D39988653D60032003053EA533B752853E37F69FF018BE660C570B951FB002000680074007400700073003A002F002F00640078002E00310030003000380036002E0063006E002F0072006300570045004300670020621677ED4FE156DE</Text>
    <Type>SMS</Type>
    <Sender>10086100</Sender>
    <Read>true</Read>
    </Msg>
    <Msg>
    <Index>1</Index>
    <Time>2020/06/11 13:39:26 +32</Time>
    <Text>590D201C548C4F60201D767B5F554E0A6D7779FB52A8548C4F6000410050005083B753D666F4591A4F1860E04FE1606FFF01</Text>
    <Type>SMS</Type>
    <Sender>10086100</Sender>
    <Read>true</Read>
    </Msg>
    <Msg>
    <Index>3</Index>
    <Time>2020/06/12 14:33:01 +32</Time>
    <Text>301000350047770B79FB52A8301189C698914F1A5458662565E55927793C53056B6357286D3E9001FF0C72315947827A30014F189177300154D454E954D454E94F1A54584E0990094E00002B00310035004700424E135C5E6D4191CF72794EAB4EF700310035002E00395143002F670830028BE660C570B951FB002000680074007400700073</Text>
    <Type>SMS</Type>
    <Sender>10086100</Sender>
    <Read>true</Read>
    </Msg>
    <Msg>
    <Index>4</Index>
    <Time>2020/06/12 14:33:01 +32</Time>
    <Text>003A002F002F00640078002E00310030003000380036002E0063006E002F004F00380039005F004100670020621677ED4FE156DE590D201C548C4F60201D767B5F554E0A6D7779FB52A8548C4F6000410050005083B753D666F4591A4F1860E04FE1606FFF01FF086CE8FF1A524D671F5DF253C24E0E4F1860E072794EAB4EF76D3B52A87684</Text>
    <Type>SMS</Type>
    <Sender>10086100</Sender>
    <Read>true</Read>
    </Msg>
    <Msg>
    <Index>5</Index>
    <Time>2020/06/12 14:33:01 +32</Time>
    <Text>75286237FF0C65E06CD591CD590D53C24E0E672C4F1860E06D3B52A8FF09</Text>
    <Type>SMS</Type>
    <Sender>10086100</Sender>
    <Read>true</Read>
    </Msg>
    <Msg>
    <Index>6</Index>
    <Time>2020/06/12 15:14:11 +32</Time>
    <Text>FF086EDF706A72299C7B9EA49F969F979F7E9F4997509F98FF0962FC97F359824E0BFF1A000A30106C498BED62FC97F330116EDF0028007900E0006E00290020706A0028007900F90029002072290028007900F9002900209C7B00280078006901CE006E002900209EA400280063016B002900209F960028006400E1002900209F970028006C</Text>
    <Type>SMS</Type>
    <Sender>17501691384</Sender>
    <Read>true</Read>
    </Msg>
    <Msg>
    <Index>7</Index>
    <Time>2020/06/12 15:14:15 +32</Time>
    <Text>00ED006E0261002900209F7E0028007900E0002900209F490028006E00E0006E02610029002097500028006200EC006E0261002900209F980028006400E10029</Text>
    <Type>SMS</Type>
    <Sender>17501691384</Sender>
    <Read>true</Read>
    </Msg>
 </NewSMS>
</m:GetSMSInfoResponse>
<ResponseCode>0</ResponseCode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

收到的PDU信息以及解码后信息如下,长短信会被分批发送,类似IP分片。

unicode:
    part 1: FF086EDF706A72299C7B9EA49F969F979F7E9F4997509F98FF0962FC97F359824E0BFF1A000A30106C498BED62FC97F330116EDF0028007900E0006E00290020706A0028007900F90029002072290028007900F9002900209C7B00280078006901CE006E002900209EA400280063016B002900209F960028006400E1002900209F970028006C
    part 2: 00ED006E0261002900209F7E0028007900E0002900209F490028006E00E0006E02610029002097500028006200EC006E0261002900209F980028006400E10029

utf-16 decode:
    part 1: (滟灪爩鱻麤龖龗齾齉靐龘)拼音如下: 【汉语拼音】滟(yàn) 灪(yù) 爩(yù) 鱻(xiǎn) 麤(cū) 龖(dá) 龗(l
    part 2: ínɡ) 齾(yà) 齉(nànɡ) 靐(bìnɡ) 龘(dá)

PDU 解析

针对测试用例,参考短信实用手册2,下面进行详细解释:

Analysis received PDU

0891683108200115F1640BA17105611983F40008026021514111238C0500035A0201FF086EDF706A72299C7B9EA49F969F979F7E9F4997509F98FF0962FC97F359824E0BFF1A000A30106C498BED62FC97F330116EDF0028007900E0006E00290020706A0028007900F90029002072290028007900F9002900209C7B00280078006901CE006E002900209EA400280063016B002900209F960028006400E1002900209F970028006C  
---
SCA: 08 91 683108200115F1
PDU Header: 64
TP-OA: 0B A1 7105611983F4
TP-PID: 00
TP-DCS: 08
TP-SCTS: 02602151411123
TP-UDL: 8C
Data header: 0500035A 0201
TP-UD: FF086EDF706A72299C7B9EA49F969F979F7E9F4997509F98FF0962FC97F359824E0BFF1A000A30106C498BED62FC97F330116EDF0028007900E0006E00290020706A0028007900F90029002072290028007900F9002900209C7B00280078006901CE006E002900209EA400280063016B002900209F960028006400E1002900209F970028006C
---
SCA
08 91 68 31 08 20 01 15 F1
08: SMSC地址信息的长度,8个字节(含格式信息)
91: SMSC地址格式 国际格式
68 31 08 20 01 15 F1: 接收方SMSC地址 +8613800210511,补`F`凑成整数
PDU Header
- 64: SMS-DELIVER消息的第一个字节
RP UDHI SRI _ _ MMS MTI
0  1    1   0 0 1   00
- RP: 0, 应答路径未设置  
- UDHI: 1, 用户数据包含头信息  
- SRI: 1, 状态报告将返回给短消息实体(SME)  
- MSS: 1, 在SMSC中没有更多信息等待MS  
- MTI: 00, 信息类型指示 SMS-DELIVER(SMS->MS)
TP-OA
- 0B A1 71 05 61 19 83 F4
0B: 发送方地址长度, 11
A1: 发送方地址格式,国内格式
71 05 61 19 83 F4: 发送方地址, 17501691384, 补`F`凑成整数
TP-PID
- 00: 协议标识, GSM类型,点到点方式
TP-DCS
- 08: 用户信息编码方式, UCS2
TP-SCTS
- 02 60 21 51 41 11 23: 时间戳,2020-06-12 15:14:11 +32
TP-UDL
- 8C: 用户数据长度, 当前字节往后(不含8C)的数据长度,如果有分片仅计算本批数据
TP-UD
- 05 00 03 5A 02 01: 短信头部
05: 数据头部剩余5个字节
00: 长短信,8位的参考标识
03: 数据头部剩余3个字节
5A: 这批短信的唯一参考标识
02: 这批短信的数量,该长短信被分为2条
01: 本条短信是长短信中的第1条
- FF08...: TP-UD, 余下都是短信信息

在线工具

reference