1
#define nWAP_SIN_EX 25 //单包WAP PUSH额外字节长度
2
#define nMMS_SIN_EX 77 //单包彩信额外字节长度
3
4
int CWapPush::GetMMSEncode(
5
char * pSrcNum, //源发送号码
6
char * pUrl, //下载连接
7
char * pSubject, //标题
8
int nMMSSize, //字节大小
9
char * pOut1, //输出短信二进制
10
int * nOut1Len,
11
char * pOut2, //输出短信二进制
12
int * nOut2Len,
13
int * nCount) //几条短信
14
{
15
* nCount=1;
16
int nLeftByte;
17
char szEncode1[350*2]=
{0}; //加码编码1
18
char szEncode2[350]=
{0}; //加码编码2
19
int nSrcNumLen = strlen(pSrcNum) ;
20
int nUrlLen = strlen(pUrl);
21
int nTransactionID= GetTransactionID();
22
int nSubjectLen=strlen(pSubject); //标题长度
23
int nSubject_UTF_8_Len; //标题***UTF-8的长度
24
char *pSubject_UTF_8 =(char *) alloca (nSubjectLen* 3 + 1 + 3 ); //new char[nSubjectLen* 3 + 1 ]={0};
25
GB2312ToUTF_8(pSubject, nSubjectLen,pSubject_UTF_8+2); //标题***UTF-8
26
nSubject_UTF_8_Len=strlen(pSubject_UTF_8 + 2 );
27
pSubject_UTF_8[0]=nSubject_UTF_8_Len + 1 + 1 ; //charset value-length
28
pSubject_UTF_8[1]=0xEA;
29
nSubject_UTF_8_Len=nSubject_UTF_8_Len + 2 ;
30
31
if( ( nMMS_SIN_EX + nSrcNumLen + nUrlLen + nSubject_UTF_8_Len ) > 140 )
32
{
33
//第一条短信息
34
// udh
35
szEncode1[0]='0';szEncode1[1] ='B'; // "0B" User Data Header Length (11 bytes)
36
szEncode1[2]='0';szEncode1[3] ='5'; // "05" UDH Item Element id (Port Numbers)
37
szEncode1[4]='0';szEncode1[5] ='4'; // "04 UDH IE length (4 bytes)
38
szEncode1[6]='0';szEncode1[7] ='B'; // "0B"
39
szEncode1[8]='8';szEncode1[9] ='4'; // "84" destination port number
40
szEncode1[10]='2';szEncode1[11] ='3';// "23"
41
szEncode1[12]='F';szEncode1[13] ='0';// "F0"origin port number
42
szEncode1[14]='0';szEncode1[15] ='0';// "00"concatenation identifier element
43
szEncode1[16]='0';szEncode1[17] ='3';// "03"length of params
44
szEncode1[18]='3';szEncode1[19] ='A';// "3A"concat reference
45
szEncode1[20]='0';szEncode1[21] ='2';// "02"total parts
46
szEncode1[22]='0';szEncode1[23] ='1';// "01"sequence number
47
48
//pud += "400601AE";
49
ByteToHexString(nTransactionID,&szEncode1[24]); //transaction id (connectionless WSP)
50
szEncode1[26]='0';szEncode1[27] ='6';// pdu type (06=push)
51
szEncode1[28]='2';szEncode1[29] ='2';// Headers len
52
//application/vnd.wap.mms-message+'0'
53
memcpy(&szEncode1[30],"6170706C69636174696F6E2F766E642E7761702E6D6D732D6D65737361676500",0x20 * 2 );
54
// AF84 x-wap-application.ua
55
szEncode1[94]='A';szEncode1[95] ='F';
56
szEncode1[96]='8';szEncode1[97] ='4';
57
// MMS Specific stuff
58
szEncode1[98]='8';szEncode1[99] ='C';
59
szEncode1[100]='8';szEncode1[101] ='2'; //8C 82 message type (m-notification.ind)
60
szEncode1[102]='9';szEncode1[103] ='8'; //98 MMS transaction ID
61
62
szEncode1[104]='3';szEncode1[105] ='3';
63
szEncode1[106]='4';szEncode1[107] ='6';
64
szEncode1[108]='3';szEncode1[109] ='6';
65
szEncode1[110]='3';szEncode1[111] ='6';
66
szEncode1[112]='3';szEncode1[113] ='8';
67
szEncode1[114]='3';szEncode1[115] ='8';
68
szEncode1[116]='3';szEncode1[117] ='2';
69
ByteToHexString(nTransactionID,&szEncode1[118]);// transaction id (connectionless WSP)
70
szEncode1[120]='0';szEncode1[121] ='0';
71
72
szEncode1[122]='8';szEncode1[123] ='D';
73
szEncode1[124]='9';szEncode1[125] ='0';// 8D90 MMS version 1.0
74
szEncode1[126]='8';szEncode1[127] ='9';// FROM
75
ByteToHexString(nSrcNumLen + 1 + 1,&szEncode1[128]); // length of from
76
szEncode1[130]='8';szEncode1[131] ='0'; // 80 address present
77
78
ByteArrayToHexString(pSrcNum,nSrcNumLen,&szEncode1[132]); //发送号码
79
szEncode1[132+ nSrcNumLen *2 ]='0';szEncode1[133+ nSrcNumLen *2 ]='0';//00
80
81
szEncode1[134+ nSrcNumLen *2 ]='9';szEncode1[135+ nSrcNumLen *2 ]='6';//96 subject
82
83
ByteArrayToHexString(pSubject_UTF_8,nSubject_UTF_8_Len,&szEncode1[136+ nSrcNumLen *2 ]);//显示标题
84
szEncode1[136+ (nSubject_UTF_8_Len + nSrcNumLen)*2 ]='0';szEncode1[137+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='0';//00
85
86
szEncode1[138+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='8';szEncode1[139+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='A';
87
szEncode1[140+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='8';szEncode1[141+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='0';//Personal message class
88
szEncode1[142+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='8';szEncode1[143+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='E';//msg size
89
int msgByte=0;
90
if(nMMSSize&0xFF000000)
91
{
92
sprintf(&szEncode1[146+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%08X",nMMSSize);
93
msgByte=4;
94
}
95
else if(nMMSSize&0xFF0000)
96
{
97
sprintf(&szEncode1[146+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%06X",nMMSSize);
98
msgByte=3;
99
}
100
else if(nMMSSize&0xFF00)
101
{
102
sprintf(&szEncode1[146+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%04X",nMMSSize);
103
msgByte=2;
104
}
105
else if(nMMSSize&0xFF)
106
{
107
sprintf(&szEncode1[146+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%02X",nMMSSize);
108
msgByte=1;
109
}
110
ByteToHexString(msgByte,&szEncode1[144+ (nSubject_UTF_8_Len + nSrcNumLen) *2]); // 2 octets
111
112
szEncode1[146+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[147+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='8';//88 expiry
113
szEncode1[148+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='0';szEncode1[149+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='5';//05 expiry length
114
szEncode1[150+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[151+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='1';//81 relative format
115
116
szEncode1[152+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='0';szEncode1[153+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='3';// 3 octets
117
szEncode1[154+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='0';szEncode1[155+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='9';
118
szEncode1[156+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='3';szEncode1[157+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='A';
119
szEncode1[158+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[159+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='0';//01 51 80: 24hrs (86400 secs)
120
szEncode1[160+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[161+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='3';//83 content location
121
122
ByteArrayToHexString(pUrl, nUrlLen ,&szEncode1[162+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2]);
123
szEncode1[162+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte + nUrlLen) *2]='0';
124
szEncode1[163+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte + nUrlLen) *2]='0';
125
126
*nOut1Len=140;
127
ChangeStringToHexBuf(szEncode1, (*nOut1Len) *2 ,pOut1);
128
nLeftByte = 164 + (nUrlLen + nSubject_UTF_8_Len+nSrcNumLen +msgByte )*2 - 280;
129
130
//第二条短信息
131
szEncode2[0]='0';szEncode2[1] ='B'; // "0B" User Data Header Length (11 bytes)
132
szEncode2[2]='0';szEncode2[3] ='5'; // "05" UDH Item Element id (Port Numbers)
133
szEncode2[4]='0';szEncode2[5] ='4'; // "04 UDH IE length (4 bytes)
134
szEncode2[6]='0';szEncode2[7] ='B'; // "0B"
135
szEncode2[8]='8';szEncode2[9] ='4'; // "84" destination port number
136
szEncode2[10]='2';szEncode2[11] ='3';// "23"
137
szEncode2[12]='F';szEncode2[13] ='0';// "F0"origin port number
138
szEncode2[14]='0';szEncode2[15] ='0';// "00"concatenation identifier element
139
szEncode2[16]='0';szEncode2[17] ='3';// "03"length of params
140
szEncode2[18]='3';szEncode2[19] ='A';// "3A"concat reference
141
szEncode2[20]='0';szEncode2[21] ='2';// "02"total parts
142
szEncode2[22]='0';szEncode2[23] ='2';// "01"sequence number
143
memcpy(&szEncode2[24],&szEncode1[280],nLeftByte);
144
*nOut2Len= 12+ nLeftByte/2 ;
145
ChangeStringToHexBuf(szEncode2, (*nOut2Len )*2 ,pOut2);
146
* nCount = 2 ;
147
}
148
else
149
{
150
// User Data Header: udh
151
szEncode1[0]='0';szEncode1[1] ='6'; // "06" User Data Header Length (6 bytes)
152
szEncode1[2]='0';szEncode1[3] ='5'; // "05" UDH Item Element id (Port Numbers)
153
szEncode1[4]='0';szEncode1[5] ='4'; // "04 UDH IE length (4 bytes)
154
szEncode1[6]='0';szEncode1[7] ='B'; // "0B"
155
szEncode1[8]='8';szEncode1[9] ='4'; // "84" destination port number
156
szEncode1[10]='2';szEncode1[11] ='3';// "23"
157
szEncode1[12]='F';szEncode1[13] ='0';// "F0"origin port number
158
//WSP header:
159
ByteToHexString(nTransactionID,&szEncode1[14]);// transaction id (connectionless WSP)
160
szEncode1[16]='0';szEncode1[17] ='6';// pdu type (06=push)
161
szEncode1[18]='2';szEncode1[19] ='2';// Headers len
162
//application/vnd.wap.mms-message+'0'
163
memcpy(&szEncode1[20],"6170706C69636174696F6E2F766E642E7761702E6D6D732D6D65737361676500",0x20 * 2 );
164
// AF84 x-wap-application.ua
165
szEncode1[84]='A';szEncode1[85] ='F';
166
szEncode1[86]='8';szEncode1[87] ='4';
167
// MMS Specific stuff
168
szEncode1[88]='8';szEncode1[89] ='C';
169
szEncode1[90]='8';szEncode1[91] ='2'; //8C 82 message type (m-notification.ind)
170
szEncode1[92]='9';szEncode1[93] ='8'; //98 MMS transaction ID
171
172
szEncode1[94]='3';szEncode1[95] ='3';
173
szEncode1[96]='4';szEncode1[97] ='6';
174
szEncode1[98]='3';szEncode1[99] ='6';
175
szEncode1[100]='3';szEncode1[101] ='6';
176
szEncode1[102]='3';szEncode1[103] ='8';
177
szEncode1[104]='3';szEncode1[105] ='8';
178
szEncode1[106]='3';szEncode1[107] ='2';
179
ByteToHexString(nTransactionID,&szEncode1[108]);// transaction id (connectionless WSP)
180
szEncode1[110]='0';szEncode1[111] ='0';
181
182
szEncode1[112]='8';szEncode1[113] ='D';
183
szEncode1[114]='9';szEncode1[115] ='0';// 8D90 MMS version 1.0
184
szEncode1[116]='8';szEncode1[117] ='9';// FROM
185
ByteToHexString(nSrcNumLen + 1 + 1,&szEncode1[118]); // length of from
186
szEncode1[120]='8';szEncode1[121] ='0'; // 80 address present
187
188
ByteArrayToHexString(pSrcNum,nSrcNumLen,&szEncode1[122]); //发送号码
189
szEncode1[122+ nSrcNumLen *2 ]='0';szEncode1[123+ nSrcNumLen *2 ]='0';//00
190
191
szEncode1[124+ nSrcNumLen *2 ]='9';szEncode1[125+ nSrcNumLen *2 ]='6';//96 subject
192
193
ByteArrayToHexString(pSubject_UTF_8,nSubject_UTF_8_Len,&szEncode1[126+ nSrcNumLen *2 ]);//显示标题
194
szEncode1[126+ (nSubject_UTF_8_Len + nSrcNumLen)*2 ]='0';szEncode1[127+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='0';//00
195
196
szEncode1[128+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='8';szEncode1[129+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='A';
197
szEncode1[130+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='8';szEncode1[131+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='0';//Personal message class
198
szEncode1[132+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='8';szEncode1[133+ (nSubject_UTF_8_Len + nSrcNumLen) *2 ]='E';//msg size
199
int msgByte=0;
200
if(nMMSSize&0xFF000000)
201
{
202
sprintf(&szEncode1[136+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%08X",nMMSSize);
203
msgByte=4;
204
}
205
else if(nMMSSize&0xFF0000)
206
{
207
sprintf(&szEncode1[136+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%06X",nMMSSize);
208
msgByte=3;
209
}
210
else if(nMMSSize&0xFF00)
211
{
212
sprintf(&szEncode1[136+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%04X",nMMSSize);
213
msgByte=2;
214
}
215
else if(nMMSSize&0xFF)
216
{
217
sprintf(&szEncode1[136+(nSubject_UTF_8_Len + nSrcNumLen )*2],"%02X",nMMSSize);
218
msgByte=1;
219
}
220
ByteToHexString(msgByte,&szEncode1[134+ (nSubject_UTF_8_Len + nSrcNumLen) *2]); // 2 octets
221
szEncode1[136+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[137+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='8';//88 expiry
222
szEncode1[138+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='0';szEncode1[139+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='5';//05 expiry length
223
szEncode1[140+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[141+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='1';//81 relative format
224
szEncode1[142+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='0';szEncode1[143+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='3';// 3 octets
225
szEncode1[144+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='0';szEncode1[145+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='9';
226
szEncode1[146+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='3';szEncode1[147+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='A';
227
szEncode1[148+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[149+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='0';//01 51 80: 24hrs (86400 secs)
228
szEncode1[150+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2 ]='8';szEncode1[151+ (nSubject_UTF_8_Len+nSrcNumLen+msgByte)*2]='3';//83 content location
229
ByteArrayToHexString(pUrl, nUrlLen ,&szEncode1[152+ (nSubject_UTF_8_Len+nSrcNumLen +msgByte) *2]);
230
szEncode1[152+ (nSubject_UTF_8_Len + nSrcNumLen + msgByte + nUrlLen) *2 ]='0';szEncode1[153 + (nSubject_UTF_8_Len+nSrcNumLen+msgByte+nUrlLen) *2]='0';//00结束
231
*nOut1Len= 152/2 + 1 + nSubject_UTF_8_Len + nSrcNumLen + msgByte + nUrlLen;
232
ChangeStringToHexBuf(szEncode1, (*nOut1Len) *2 ,pOut1);
233
//WriteFile("mms.txt" ,szEncode1 ,(*nOut1Len) *2);
234
}
235
return 0;
236
}
237