一些网上收集的MMS相关代码
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
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
1
BYTE ChangeAsciiToHexByte(
char
src_char)
2 {
3 BYTE src_byte = ( BYTE ) src_char;
4
5 BYTE result_byte = src_byte;
6
7 if( src_byte >= 0x30
8 && src_byte <= 0x39 )
9 {
10 result_byte = src_byte - 0x30;
11 return result_byte;
12 }
13
14 if( src_byte >= 0x41
15 && src_byte <= 0x46 )
16 {
17 result_byte = src_byte - 0x41 + 0x0a;
18 }
19
20 if( src_byte >= 0x61
21 && src_byte >= 0x66 )
22 {
23 result_byte = src_byte - 0x61 + 0x0a;
24 }
25
26 return result_byte;
27}
28
29 char * ChangeStringToHexBuf( char * pSrc, int len, char * pResultBuf)
30 {
31
32 int nLength = len/2 ;
33 BYTE first_byte;
34 BYTE second_byte;
35 BYTE result_byte;
36 for( int nIndex = 0; nIndex < nLength; nIndex ++ )
37 {
38 first_byte = ChangeAsciiToHexByte(pSrc[ nIndex * 2 ] );
39 second_byte = ChangeAsciiToHexByte(pSrc[ nIndex * 2 + 1]);
40 result_byte = ( BYTE ) ( first_byte * 16 + second_byte );
41 pResultBuf[ nIndex ] = result_byte;
42 }
43 pResultBuf[ nIndex ] = '\0';
44 return pResultBuf;
45}
46
47 static char HexCode[] =
48 {
49 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
50 'A', 'B', 'C', 'D', 'E', 'F',
51} ;
52 char * ByteToHexString(BYTE src_byte, char * pHexCode)
53 {
54 int n = src_byte;
55 if (n < 0)
56 n = 256 + n;
57 pHexCode[0] = HexCode[n / 16];
58 pHexCode[1] = HexCode[n % 16];
59 return pHexCode;
60}
61 char * ByteArrayToHexString( char * pSrc, int nLen , char * pDesc)
62 {
63 for (int nIndex = 0 ; nIndex <nLen; nIndex ++ )
64 {
65 ByteToHexString( (BYTE) pSrc[nIndex] , pDesc );
66 pDesc = pDesc + 2;
67 }
68 return pDesc;
69}
70
71 char * UTF_8ToUnicode( char * pText,WCHAR * pOut )
72 {
73 unsigned char* uchar = (unsigned char *)pOut;
74 uchar[1] = ((pText[0] & 0x0F) << 4) + ((pText[1] >> 2) & 0x0F);
75 uchar[0] = ((pText[1] & 0x03) << 6) + (pText[2] & 0x3F);
76 return (char* )uchar ;
77}
78
79 char * UnicodeToUTF_8( WCHAR * pText, char * pOut)
80 {
81 // 注意 WCHAR高低字的顺序,低字节在前,高字节在后
82 unsigned char * pchar = (unsigned char *)pText;
83 unsigned char * pdest = (unsigned char *)pOut;
84 pdest[0] = (0xE0 | ((pchar[1] & 0xF0) >> 4));
85 pdest[1] = (0x80 | ((pchar[1] & 0x0F) << 2)) + ((pchar[0] & 0xC0) >> 6);
86 pdest[2] = (0x80 | (pchar[0] & 0x3F));
87 return (char * )pdest;
88}
89
90 char * Gb2312ToUnicode( char * pBuffer,WCHAR * pOut)
91 {
92 ::MultiByteToWideChar(936,MB_PRECOMPOSED,pBuffer,2,pOut,1);
93 return (char *)pOut;
94}
95 char * UnicodeToGB2312(WCHAR * pBuffer, char * pOut)
96 {
97 WideCharToMultiByte(936,NULL,pBuffer,1,pOut,sizeof(WCHAR),NULL,NULL);
98 return (char *)pOut;
99}
100 char * GB2312ToUTF_8( char * pText, int pLen, char * pOut)
101 {
102 //UTF_8 must be three bytes
103 char buf[4]={0};
104 char* rst = pOut; //new char[pLen * 3 + 2];//char* rst = new char[pLen + (pLen >> 2) + 2];
105 int i = 0;
106 int j = 0;
107 WCHAR pbuffer;
108 while(i < pLen)
109 {
110 //如果是英文直接复制就可以
111 if( *(pText + i) >= 0)
112 {
113 rst[j++] = pText[i++];
114 }
115 else
116 {
117 Gb2312ToUnicode(pText+i,&pbuffer);
118 UnicodeToUTF_8(&pbuffer,buf);
119 rst[j] = buf[0];
120 rst[j+1] = buf[1];
121 rst[j+2] = buf[2];
122 j += 3;
123 i += 2;
124 }
125 }
126 rst[j] = '\0';
127 return pOut ;
128}
129
130 char * UTF_8ToGB2312( char * pText, int pLen, char * pOut)
131 {
132 char * newBuf = pOut ;
133 char Ctemp[4]={0};
134 int i = 0;
135 int j = 0;
136 WCHAR Wtemp;
137 while(i < pLen)
138 {
139 if(pText > 0)
140 {
141 newBuf[j++] = pText[i++];
142 }
143 else
144 {
145 UTF_8ToUnicode(pText + i,&Wtemp);
146 UnicodeToGB2312(&Wtemp,Ctemp);
147 newBuf[j] = Ctemp[0];
148 newBuf[j + 1] = Ctemp[1];
149 i += 3;
150 j += 2;
151 }
152 }
153 newBuf[j] = '\0';
154 return pOut;
155}
2 {
3 BYTE src_byte = ( BYTE ) src_char;
4
5 BYTE result_byte = src_byte;
6
7 if( src_byte >= 0x30
8 && src_byte <= 0x39 )
9 {
10 result_byte = src_byte - 0x30;
11 return result_byte;
12 }
13
14 if( src_byte >= 0x41
15 && src_byte <= 0x46 )
16 {
17 result_byte = src_byte - 0x41 + 0x0a;
18 }
19
20 if( src_byte >= 0x61
21 && src_byte >= 0x66 )
22 {
23 result_byte = src_byte - 0x61 + 0x0a;
24 }
25
26 return result_byte;
27}
28
29 char * ChangeStringToHexBuf( char * pSrc, int len, char * pResultBuf)
30 {
31
32 int nLength = len/2 ;
33 BYTE first_byte;
34 BYTE second_byte;
35 BYTE result_byte;
36 for( int nIndex = 0; nIndex < nLength; nIndex ++ )
37 {
38 first_byte = ChangeAsciiToHexByte(pSrc[ nIndex * 2 ] );
39 second_byte = ChangeAsciiToHexByte(pSrc[ nIndex * 2 + 1]);
40 result_byte = ( BYTE ) ( first_byte * 16 + second_byte );
41 pResultBuf[ nIndex ] = result_byte;
42 }
43 pResultBuf[ nIndex ] = '\0';
44 return pResultBuf;
45}
46
47 static char HexCode[] =
48 {
49 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
50 'A', 'B', 'C', 'D', 'E', 'F',
51} ;
52 char * ByteToHexString(BYTE src_byte, char * pHexCode)
53 {
54 int n = src_byte;
55 if (n < 0)
56 n = 256 + n;
57 pHexCode[0] = HexCode[n / 16];
58 pHexCode[1] = HexCode[n % 16];
59 return pHexCode;
60}
61 char * ByteArrayToHexString( char * pSrc, int nLen , char * pDesc)
62 {
63 for (int nIndex = 0 ; nIndex <nLen; nIndex ++ )
64 {
65 ByteToHexString( (BYTE) pSrc[nIndex] , pDesc );
66 pDesc = pDesc + 2;
67 }
68 return pDesc;
69}
70
71 char * UTF_8ToUnicode( char * pText,WCHAR * pOut )
72 {
73 unsigned char* uchar = (unsigned char *)pOut;
74 uchar[1] = ((pText[0] & 0x0F) << 4) + ((pText[1] >> 2) & 0x0F);
75 uchar[0] = ((pText[1] & 0x03) << 6) + (pText[2] & 0x3F);
76 return (char* )uchar ;
77}
78
79 char * UnicodeToUTF_8( WCHAR * pText, char * pOut)
80 {
81 // 注意 WCHAR高低字的顺序,低字节在前,高字节在后
82 unsigned char * pchar = (unsigned char *)pText;
83 unsigned char * pdest = (unsigned char *)pOut;
84 pdest[0] = (0xE0 | ((pchar[1] & 0xF0) >> 4));
85 pdest[1] = (0x80 | ((pchar[1] & 0x0F) << 2)) + ((pchar[0] & 0xC0) >> 6);
86 pdest[2] = (0x80 | (pchar[0] & 0x3F));
87 return (char * )pdest;
88}
89
90 char * Gb2312ToUnicode( char * pBuffer,WCHAR * pOut)
91 {
92 ::MultiByteToWideChar(936,MB_PRECOMPOSED,pBuffer,2,pOut,1);
93 return (char *)pOut;
94}
95 char * UnicodeToGB2312(WCHAR * pBuffer, char * pOut)
96 {
97 WideCharToMultiByte(936,NULL,pBuffer,1,pOut,sizeof(WCHAR),NULL,NULL);
98 return (char *)pOut;
99}
100 char * GB2312ToUTF_8( char * pText, int pLen, char * pOut)
101 {
102 //UTF_8 must be three bytes
103 char buf[4]={0};
104 char* rst = pOut; //new char[pLen * 3 + 2];//char* rst = new char[pLen + (pLen >> 2) + 2];
105 int i = 0;
106 int j = 0;
107 WCHAR pbuffer;
108 while(i < pLen)
109 {
110 //如果是英文直接复制就可以
111 if( *(pText + i) >= 0)
112 {
113 rst[j++] = pText[i++];
114 }
115 else
116 {
117 Gb2312ToUnicode(pText+i,&pbuffer);
118 UnicodeToUTF_8(&pbuffer,buf);
119 rst[j] = buf[0];
120 rst[j+1] = buf[1];
121 rst[j+2] = buf[2];
122 j += 3;
123 i += 2;
124 }
125 }
126 rst[j] = '\0';
127 return pOut ;
128}
129
130 char * UTF_8ToGB2312( char * pText, int pLen, char * pOut)
131 {
132 char * newBuf = pOut ;
133 char Ctemp[4]={0};
134 int i = 0;
135 int j = 0;
136 WCHAR Wtemp;
137 while(i < pLen)
138 {
139 if(pText > 0)
140 {
141 newBuf[j++] = pText[i++];
142 }
143 else
144 {
145 UTF_8ToUnicode(pText + i,&Wtemp);
146 UnicodeToGB2312(&Wtemp,Ctemp);
147 newBuf[j] = Ctemp[0];
148 newBuf[j + 1] = Ctemp[1];
149 i += 3;
150 j += 2;
151 }
152 }
153 newBuf[j] = '\0';
154 return pOut;
155}
1
char
*
CMMSEncoder::encodeUintvar(
int
data,
char
*
pUintVar ,
int
*
iUintVarLen)
2 {
3 char reversed[8]={0};
4 int i = 0;
5 reversed = data & 0x7f; // The lowest
6 data = data >> 7;
7 i++;
8 while ( data > 0 )
9 {
10 reversed = 0x80 | (data & 0x7f);
11 i++;
12 data = data >> 7;
13 }
14 // Reverse it because it is in reverse order
15 for ( int j = 0; j < i; j++ )
16 {
17 pUintVar[j] = reversed[i - j - 1];
18 }
19 *iUintVarLen=i;
20 return pUintVar;
21}
22 int CMMSEncoder::decodeUintvar( char * pUintVar , int iUintVarLen)
23 {
24 int uintvar = 0 , i = 0;
25 while ( pUintVar & 0x80 )
26 {
27 uintvar = uintvar << 7;
28 uintvar |=pUintVar & 0x7f;
29 i++;
30 }
31 uintvar = uintvar << 7;
32 uintvar |= pUintVar & 0x7f;
33 return uintvar;
34}
35 int CMMSEncoder::encodeContentType( char * pContentType)
36 {
37 if(stricmp(pContentType,"*/*"==0)
38 return 0;
39 if(stricmp(pContentType,"text/*"==0)
40 return 1;
41 if(stricmp(pContentType,"text/html"==0)
42 return 2;
43 if(stricmp(pContentType,"text/plain"==0)
44 return 3;
45 if(stricmp(pContentType,"text/x-hdml"==0)
46 return 4;
47 if(stricmp(pContentType,"text/x-ttml"==0)
48 return 5;
49 if(stricmp(pContentType,"text/x-vCalendar"==0)
50 return 6;
51 if(stricmp(pContentType,"text/x-vCard"==0)
52 return 7;
53 if(stricmp(pContentType,"text/vnd.wap.wml"==0)
54 return 8;
55 if(stricmp(pContentType,"text/vnd.wap.wmlscript"==0)
56 return 9;
57 if(stricmp(pContentType,"text/vnd.wap.channel"==0)
58 return 10;
59 if(stricmp(pContentType,"multipart/*"==0)
60 return 11;
61 if(stricmp(pContentType,"multipart/mixed"==0)
62 return 12;
63 if(stricmp(pContentType,"multipart/form-data"==0)
64 return 13;
65 if(stricmp(pContentType,"multipart/byteranges"==0)
66 return 14;
67 if(stricmp(pContentType,"multipart/alternative"==0)
68 return 15;
69 if(stricmp(pContentType,"application/*"==0)
70 return 16;
71 if(stricmp(pContentType,"application/java-vm"==0)
72 return 17;
73 if(stricmp(pContentType,"application/x-www-form-urlencoded"==0)
74 return 18;
75 if(stricmp(pContentType,"application/x-hdmlc"==0)
76 return 19;
77 if(stricmp(pContentType,"application/vnd.wap.wmlc"==0)
78 return 20;
79 if(stricmp(pContentType,"application/vnd.wap.wmlscriptc"==0)
80 return 21;
81 if(stricmp(pContentType,"application/vnd.wap.channelc"==0)
82 return 22;
83 if(stricmp(pContentType,"application/vnd.wap.uaprof"==0)
84 return 23;
85 if(stricmp(pContentType,"application/vnd.wap.wtls-ca-certificate"==0)
86 return 24;
87 if(stricmp(pContentType,"application/vnd.wap.wtls-user-certificate"==0)
88 return 25;
89 if(stricmp(pContentType,"application/x-x509-ca-cert"==0)
90 return 26;
91 if(stricmp(pContentType,"application/x-x509-user-cert"==0)
92 return 27;
93 if(stricmp(pContentType,"image/*"==0)
94 return 28;
95 if(stricmp(pContentType,"image/gif"==0)
96 return 29;
97 if(stricmp(pContentType,"image/jpeg"==0)
98 return 30;
99 if(stricmp(pContentType,"image/tiff"==0)
100 return 31;
101 if(stricmp(pContentType,"image/png"==0)
102 return 32;
103 if(stricmp(pContentType,"image/vnd.wap.wbmp"==0)
104 return 33;
105 if(stricmp(pContentType,"application/vnd.wap.multipart.*"==0)
106 return 34;
107 if(stricmp(pContentType,"application/vnd.wap.multipart.mixed"==0)
108 return 35;
109 if(stricmp(pContentType,"application/vnd.wap.multipart.form-data"==0)
110 return 36;
111 if(stricmp(pContentType,"application/vnd.wap.multipart.byteranges"==0)
112 return 37;
113 if(stricmp(pContentType,"application/vnd.wap.multipart.alternative"==0)
114 return 38;
115 if(stricmp(pContentType,"application/xml"==0)
116 return 39;
117 if(stricmp(pContentType,"text/xml"==0)
118 return 40;
119 if(stricmp(pContentType,"application/vnd.wap.wbxml"==0)
120 return 41;
121 if(stricmp(pContentType,"application/x-x968-cross-cert"==0)
122 return 42;
123 if(stricmp(pContentType,"application/x-x968-ca-cert"==0)
124 return 43;
125 if(stricmp(pContentType,"application/x-x968-user-cert"==0)
126 return 44;
127 if(stricmp(pContentType,"text/vnd.wap.si"==0)
128 return 45;
129 if(stricmp(pContentType,"application/vnd.wap.sic"==0)
130 return 46;
131 if(stricmp(pContentType,"text/vnd.wap.sl"==0)
132 return 47;
133 if(stricmp(pContentType,"application/vnd.wap.slc"==0)
134 return 48;
135 if(stricmp(pContentType,"text/vnd.wap.co"==0)
136 return 49;
137 if(stricmp(pContentType,"application/vnd.wap.coc"==0)
138 return 50;
139 if(stricmp(pContentType,"application/vnd.wap.multipart.related"==0)
140 return 51;
141 if(stricmp(pContentType,"application/vnd.wap.sia"==0)
142 return 52;
143 if(stricmp(pContentType,"text/vnd.wap.connectivity-xml"==0)
144 return 53;
145 if(stricmp(pContentType,"application/vnd.wap.connectivity-wbxml"==0)
146 return 54;
147 else
148 return -1;
149}
2 {
3 char reversed[8]={0};
4 int i = 0;
5 reversed = data & 0x7f; // The lowest
6 data = data >> 7;
7 i++;
8 while ( data > 0 )
9 {
10 reversed = 0x80 | (data & 0x7f);
11 i++;
12 data = data >> 7;
13 }
14 // Reverse it because it is in reverse order
15 for ( int j = 0; j < i; j++ )
16 {
17 pUintVar[j] = reversed[i - j - 1];
18 }
19 *iUintVarLen=i;
20 return pUintVar;
21}
22 int CMMSEncoder::decodeUintvar( char * pUintVar , int iUintVarLen)
23 {
24 int uintvar = 0 , i = 0;
25 while ( pUintVar & 0x80 )
26 {
27 uintvar = uintvar << 7;
28 uintvar |=pUintVar & 0x7f;
29 i++;
30 }
31 uintvar = uintvar << 7;
32 uintvar |= pUintVar & 0x7f;
33 return uintvar;
34}
35 int CMMSEncoder::encodeContentType( char * pContentType)
36 {
37 if(stricmp(pContentType,"*/*"==0)
38 return 0;
39 if(stricmp(pContentType,"text/*"==0)
40 return 1;
41 if(stricmp(pContentType,"text/html"==0)
42 return 2;
43 if(stricmp(pContentType,"text/plain"==0)
44 return 3;
45 if(stricmp(pContentType,"text/x-hdml"==0)
46 return 4;
47 if(stricmp(pContentType,"text/x-ttml"==0)
48 return 5;
49 if(stricmp(pContentType,"text/x-vCalendar"==0)
50 return 6;
51 if(stricmp(pContentType,"text/x-vCard"==0)
52 return 7;
53 if(stricmp(pContentType,"text/vnd.wap.wml"==0)
54 return 8;
55 if(stricmp(pContentType,"text/vnd.wap.wmlscript"==0)
56 return 9;
57 if(stricmp(pContentType,"text/vnd.wap.channel"==0)
58 return 10;
59 if(stricmp(pContentType,"multipart/*"==0)
60 return 11;
61 if(stricmp(pContentType,"multipart/mixed"==0)
62 return 12;
63 if(stricmp(pContentType,"multipart/form-data"==0)
64 return 13;
65 if(stricmp(pContentType,"multipart/byteranges"==0)
66 return 14;
67 if(stricmp(pContentType,"multipart/alternative"==0)
68 return 15;
69 if(stricmp(pContentType,"application/*"==0)
70 return 16;
71 if(stricmp(pContentType,"application/java-vm"==0)
72 return 17;
73 if(stricmp(pContentType,"application/x-www-form-urlencoded"==0)
74 return 18;
75 if(stricmp(pContentType,"application/x-hdmlc"==0)
76 return 19;
77 if(stricmp(pContentType,"application/vnd.wap.wmlc"==0)
78 return 20;
79 if(stricmp(pContentType,"application/vnd.wap.wmlscriptc"==0)
80 return 21;
81 if(stricmp(pContentType,"application/vnd.wap.channelc"==0)
82 return 22;
83 if(stricmp(pContentType,"application/vnd.wap.uaprof"==0)
84 return 23;
85 if(stricmp(pContentType,"application/vnd.wap.wtls-ca-certificate"==0)
86 return 24;
87 if(stricmp(pContentType,"application/vnd.wap.wtls-user-certificate"==0)
88 return 25;
89 if(stricmp(pContentType,"application/x-x509-ca-cert"==0)
90 return 26;
91 if(stricmp(pContentType,"application/x-x509-user-cert"==0)
92 return 27;
93 if(stricmp(pContentType,"image/*"==0)
94 return 28;
95 if(stricmp(pContentType,"image/gif"==0)
96 return 29;
97 if(stricmp(pContentType,"image/jpeg"==0)
98 return 30;
99 if(stricmp(pContentType,"image/tiff"==0)
100 return 31;
101 if(stricmp(pContentType,"image/png"==0)
102 return 32;
103 if(stricmp(pContentType,"image/vnd.wap.wbmp"==0)
104 return 33;
105 if(stricmp(pContentType,"application/vnd.wap.multipart.*"==0)
106 return 34;
107 if(stricmp(pContentType,"application/vnd.wap.multipart.mixed"==0)
108 return 35;
109 if(stricmp(pContentType,"application/vnd.wap.multipart.form-data"==0)
110 return 36;
111 if(stricmp(pContentType,"application/vnd.wap.multipart.byteranges"==0)
112 return 37;
113 if(stricmp(pContentType,"application/vnd.wap.multipart.alternative"==0)
114 return 38;
115 if(stricmp(pContentType,"application/xml"==0)
116 return 39;
117 if(stricmp(pContentType,"text/xml"==0)
118 return 40;
119 if(stricmp(pContentType,"application/vnd.wap.wbxml"==0)
120 return 41;
121 if(stricmp(pContentType,"application/x-x968-cross-cert"==0)
122 return 42;
123 if(stricmp(pContentType,"application/x-x968-ca-cert"==0)
124 return 43;
125 if(stricmp(pContentType,"application/x-x968-user-cert"==0)
126 return 44;
127 if(stricmp(pContentType,"text/vnd.wap.si"==0)
128 return 45;
129 if(stricmp(pContentType,"application/vnd.wap.sic"==0)
130 return 46;
131 if(stricmp(pContentType,"text/vnd.wap.sl"==0)
132 return 47;
133 if(stricmp(pContentType,"application/vnd.wap.slc"==0)
134 return 48;
135 if(stricmp(pContentType,"text/vnd.wap.co"==0)
136 return 49;
137 if(stricmp(pContentType,"application/vnd.wap.coc"==0)
138 return 50;
139 if(stricmp(pContentType,"application/vnd.wap.multipart.related"==0)
140 return 51;
141 if(stricmp(pContentType,"application/vnd.wap.sia"==0)
142 return 52;
143 if(stricmp(pContentType,"text/vnd.wap.connectivity-xml"==0)
144 return 53;
145 if(stricmp(pContentType,"application/vnd.wap.connectivity-wbxml"==0)
146 return 54;
147 else
148 return -1;
149}
void
CMMSEncoder::setMMSHead(
char
*
pFrom,
char
*
pTo,
char
*
pSubject,
int
nMultipartRelated,
int
nChoiceType)
{
memset(m_szFrom,0,sizeof(m_szFrom));
if(pFrom)
{
strcpy(m_szFrom,pFrom);
}
memset(m_szTo,0,sizeof(m_szTo));
if(pTo)
{
strcpy(m_szTo,pTo);
}
memset(m_szSubject,0,sizeof(m_szSubject));
if(pSubject)
{
strcpy(m_szSubject,pSubject);
}
m_nIsMultipartRelated=nMultipartRelated;
m_nChoiceType=nChoiceType;
}
int CMMSEncoder::encodeHead( char * pHeader, char * pFrom, char * pTo, char * pSubject)
{
int nIndex=0;
pHeader[nIndex++]=0x8C; // X-Mms-Message-Type
if(m_nChoiceType) //m-send-req
{
pHeader[nIndex++]=0x80; //m-send-req
}
else
{
pHeader[nIndex++]=0x84; // m-retrieve-conf
}
pHeader[nIndex++]=0x98; // transaction-id mms header
char szMessageId[12]={0};
m_MessageTransactionId=time(NULL);
nIndex=nIndex+sprintf(&pHeader[nIndex],"%08X",m_MessageTransactionId);
pHeader[nIndex++]=0x00;
pHeader[nIndex++]=0x8D; // X-Mms-Version
pHeader[nIndex++]=0x90; // 1.0
if(pFrom)
{
if(pFrom[0])
{
int iFromLen=strlen(pFrom);
pHeader[nIndex++]=0x89; // From mms header
pHeader[nIndex++]=iFromLen+2; // address-length
pHeader[nIndex++]=0x80; // address-present-token
memcpy(&pHeader[nIndex],pFrom,iFromLen);
nIndex=nIndex+iFromLen;
pHeader[nIndex++]=0x00; // string terminator
}
}
{
memset(m_szFrom,0,sizeof(m_szFrom));
if(pFrom)
{
strcpy(m_szFrom,pFrom);
}
memset(m_szTo,0,sizeof(m_szTo));
if(pTo)
{
strcpy(m_szTo,pTo);
}
memset(m_szSubject,0,sizeof(m_szSubject));
if(pSubject)
{
strcpy(m_szSubject,pSubject);
}
m_nIsMultipartRelated=nMultipartRelated;
m_nChoiceType=nChoiceType;
}
int CMMSEncoder::encodeHead( char * pHeader, char * pFrom, char * pTo, char * pSubject)
{
int nIndex=0;
pHeader[nIndex++]=0x8C; // X-Mms-Message-Type
if(m_nChoiceType) //m-send-req
{
pHeader[nIndex++]=0x80; //m-send-req
}
else
{
pHeader[nIndex++]=0x84; // m-retrieve-conf
}
pHeader[nIndex++]=0x98; // transaction-id mms header
char szMessageId[12]={0};
m_MessageTransactionId=time(NULL);
nIndex=nIndex+sprintf(&pHeader[nIndex],"%08X",m_MessageTransactionId);
pHeader[nIndex++]=0x00;
pHeader[nIndex++]=0x8D; // X-Mms-Version
pHeader[nIndex++]=0x90; // 1.0
if(pFrom)
{
if(pFrom[0])
{
int iFromLen=strlen(pFrom);
pHeader[nIndex++]=0x89; // From mms header
pHeader[nIndex++]=iFromLen+2; // address-length
pHeader[nIndex++]=0x80; // address-present-token
memcpy(&pHeader[nIndex],pFrom,iFromLen);
nIndex=nIndex+iFromLen;
pHeader[nIndex++]=0x00; // string terminator
}
}
if
(pTo
&&
(
*
pTo) )
{
int iToLen=strlen(pTo);
pHeader[nIndex++]=0x97; // To mms header
memcpy(&pHeader[nIndex],pTo,iToLen);
nIndex=nIndex+iToLen;
pHeader[nIndex++]=0x00; // string terminator
}
/**/ /*if (1)//CC =0x82
{
int iToLen=strlen("13820412022";
pHeader[nIndex++]=0x82; // To mms header
memcpy(&pHeader[nIndex],"13820412022",iToLen);
nIndex=nIndex+iToLen;
pHeader[nIndex++]=0x00; // string terminator
}*/
if (pSubject)
{
if(pSubject[0])
{
int iSubjectLen=strlen(pSubject);
int nSubject_UTF_8_Len; //标题***UTF-8的长度
char *pSubject_UTF_8 =(char *) alloca (iSubjectLen* 3 + 1 ); //new char[nSubjectLen* 3 + 1 ]={0};
GB2312ToUTF_8(pSubject, iSubjectLen,pSubject_UTF_8 ); //标题***UTF-8
nSubject_UTF_8_Len=strlen(pSubject_UTF_8);
pHeader[nIndex++]=0x96; // Subject
pHeader[nIndex++]=nSubject_UTF_8_Len + 1 + 1 ;
pHeader[nIndex++]=0xEA;
memcpy(&pHeader[nIndex],pSubject_UTF_8,nSubject_UTF_8_Len);
nIndex=nIndex+nSubject_UTF_8_Len;
pHeader[nIndex++]=0x00; // string terminator
}
}
{
int iToLen=strlen(pTo);
pHeader[nIndex++]=0x97; // To mms header
memcpy(&pHeader[nIndex],pTo,iToLen);
nIndex=nIndex+iToLen;
pHeader[nIndex++]=0x00; // string terminator
}
/**/ /*if (1)//CC =0x82
{
int iToLen=strlen("13820412022";
pHeader[nIndex++]=0x82; // To mms header
memcpy(&pHeader[nIndex],"13820412022",iToLen);
nIndex=nIndex+iToLen;
pHeader[nIndex++]=0x00; // string terminator
}*/
if (pSubject)
{
if(pSubject[0])
{
int iSubjectLen=strlen(pSubject);
int nSubject_UTF_8_Len; //标题***UTF-8的长度
char *pSubject_UTF_8 =(char *) alloca (iSubjectLen* 3 + 1 ); //new char[nSubjectLen* 3 + 1 ]={0};
GB2312ToUTF_8(pSubject, iSubjectLen,pSubject_UTF_8 ); //标题***UTF-8
nSubject_UTF_8_Len=strlen(pSubject_UTF_8);
pHeader[nIndex++]=0x96; // Subject
pHeader[nIndex++]=nSubject_UTF_8_Len + 1 + 1 ;
pHeader[nIndex++]=0xEA;
memcpy(&pHeader[nIndex],pSubject_UTF_8,nSubject_UTF_8_Len);
nIndex=nIndex+nSubject_UTF_8_Len;
pHeader[nIndex++]=0x00; // string terminator
}
}
pHeader[nIndex
++
]
=
0x8A
;
//
mes. class
pHeader[nIndex ++ ] = 0x80 ; // personal
pHeader[nIndex ++ ] = 0x8F ; // priority
pHeader[nIndex ++ ] = 0x81 ; // normal
pHeader[nIndex ++ ] = 0x94 ; // sender visibility
pHeader[nIndex ++ ] = 0x81 ; // no
pHeader[nIndex ++ ] = 0x86 ; // delivery report
pHeader[nIndex ++ ] = 0x81 ; // no
pHeader[nIndex ++ ] = 0x90 ; // read reply
pHeader[nIndex ++ ] = 0x81 ; // no
pHeader[nIndex ++ ] = 0x84 ; // Content-type
if (m_nMessageParts == 0 )
{
return nIndex;
}
if (m_nIsMultipartRelated) // related
{
char szSIMLId[64]={0}; //SIML文件ID
int iSIMLIdlen=0 ;
CMMSMessage *pPre,*pNext;
pNext=pPre=m_pMMSMessage;
while(pNext)
{
if(stricmp(pNext->m_szContentType,"application/smil"==0)
{
strcpy(szSIMLId,pNext->m_szContentId);
iSIMLIdlen=strlen(szSIMLId);
break;
}
pNext=pNext->m_next;
}
pHeader[nIndex ++ ] = 0x80 ; // personal
pHeader[nIndex ++ ] = 0x8F ; // priority
pHeader[nIndex ++ ] = 0x81 ; // normal
pHeader[nIndex ++ ] = 0x94 ; // sender visibility
pHeader[nIndex ++ ] = 0x81 ; // no
pHeader[nIndex ++ ] = 0x86 ; // delivery report
pHeader[nIndex ++ ] = 0x81 ; // no
pHeader[nIndex ++ ] = 0x90 ; // read reply
pHeader[nIndex ++ ] = 0x81 ; // no
pHeader[nIndex ++ ] = 0x84 ; // Content-type
if (m_nMessageParts == 0 )
{
return nIndex;
}
if (m_nIsMultipartRelated) // related
{
char szSIMLId[64]={0}; //SIML文件ID
int iSIMLIdlen=0 ;
CMMSMessage *pPre,*pNext;
pNext=pPre=m_pMMSMessage;
while(pNext)
{
if(stricmp(pNext->m_szContentType,"application/smil"==0)
{
strcpy(szSIMLId,pNext->m_szContentId);
iSIMLIdlen=strlen(szSIMLId);
break;
}
pNext=pNext->m_next;
}
int
index
=
0
;
int iContentIdLen = 0 ;
int iContentLocationLen = 0 ;
int iId_Location_len = 0 ;
if (pContentId)
{
iContentIdLen=strlen(pContentId) + 1 ;//"\0"
/**//*
if(m_nIsMultipartRelated)
{
iId_Location_len=strlen("Content-ID"+1;
}
else
{
iId_Location_len=2 ;
}*/
iId_Location_len=2 ;
}
if (pContentLocation)
{
iContentLocationLen=strlen(pContentLocation)+1;//"\0"
iId_Location_len= iId_Location_len + 1 ;
}
int iContentType = encodeContentType(pContentType) + 128 ; // 补高字节
if (iContentType > 128 )
{
if(iContentType==131)//text/plain
{
int headlen= 4 + iContentIdLen + iContentLocationLen +iId_Location_len ;//HEAD LENGTH
//int headlen= 6 + iContentIdLen + iContentLocationLen +iId_Location_len ;//HEAD LENGTH
int iUintVarLen=0;
//7-bit 编码
int iContentIdLen = 0 ;
int iContentLocationLen = 0 ;
int iId_Location_len = 0 ;
if (pContentId)
{
iContentIdLen=strlen(pContentId) + 1 ;//"\0"
/**//*
if(m_nIsMultipartRelated)
{
iId_Location_len=strlen("Content-ID"+1;
}
else
{
iId_Location_len=2 ;
}*/
iId_Location_len=2 ;
}
if (pContentLocation)
{
iContentLocationLen=strlen(pContentLocation)+1;//"\0"
iId_Location_len= iId_Location_len + 1 ;
}
int iContentType = encodeContentType(pContentType) + 128 ; // 补高字节
if (iContentType > 128 )
{
if(iContentType==131)//text/plain
{
int headlen= 4 + iContentIdLen + iContentLocationLen +iId_Location_len ;//HEAD LENGTH
//int headlen= 6 + iContentIdLen + iContentLocationLen +iId_Location_len ;//HEAD LENGTH
int iUintVarLen=0;
//7-bit 编码