wzp
2021-07-28 1cd1fbd9b88e3a4c0a9f6b76947c7523c1fa2979
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
namespace AsiaINFO.SMS.CMPP2
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Text;
 
    public class CMPP_SUBMIT
    {
        private string _At_Time;
        private int _BodyLength;
        private string[] _Dest_terminal_Id;
        private uint _DestUsr_tl;
        private string _Fee_terminal_Id;
        private uint _Fee_UserType;
        private string _FeeCode;
        private string _FeeType;
        private MessageHeader _Header;
        private string _Msg_Content;
        private byte[] _Msg_Content_Bytes;
        private uint _Msg_Fmt;
        private ulong _Msg_Id;
        private uint _Msg_Length;
        private uint _Msg_level;
        private string _Msg_src;
        private uint _Pk_number;
        private uint _Pk_total;
        private uint _Registered_Delivery;
        private string _Reserve;
        private uint _Sequence_Id;
        private string _Service_Id;
        private string _Src_Id;
        private uint _TP_pId;
        private uint _TP_udhi;
        private string _ValId_Time;
        public const int FixedBodyLength = 0x7e;
 
        public CMPP_SUBMIT(uint Sequence_Id)
        {
            this._Sequence_Id = Sequence_Id;
        }
 
        private void SetHeader()
        {
            if (!string.IsNullOrEmpty(this.WapURL))
            {
                this._Msg_Content_Bytes = WapPush.GetInstance().toBytes(this._Msg_Content, this.WapURL);
                this._Msg_Fmt = 4;
                this.TP_pId = 1;
                this.TP_udhi = 1;
            }
            else
            {
                switch (this._Msg_Fmt)
                {
                    case 8:
                        this._Msg_Content_Bytes = Encoding.BigEndianUnicode.GetBytes(this._Msg_Content);
                        break;
 
                    case 15:
                        this._Msg_Content_Bytes = Encoding.GetEncoding("gb2312").GetBytes(this._Msg_Content);
                        break;
 
                    default:
                        this._Msg_Content_Bytes = Encoding.ASCII.GetBytes(this._Msg_Content);
                        break;
                }
                if (this.Pk_total > 1)
                {
                    this.TP_udhi = 1;
                    byte[] buffer = new byte[] { 5, 0, 3, 10, (byte) this.Pk_total, (byte) this.Pk_number };
                    byte[] array = new byte[this._Msg_Content_Bytes.Length + 6];
                    int index = 0;
                    buffer.CopyTo(array, index);
                    index += buffer.Length;
                    this._Msg_Content_Bytes.CopyTo(array, index);
                    this._Msg_Content_Bytes = array;
                }
            }
            this._Msg_Length = (uint) this._Msg_Content_Bytes.Length;
            this._BodyLength = (0x7e + (0x15 * this._Dest_terminal_Id.Length)) + ((int) this._Msg_Length);
            this._Header = new MessageHeader((uint) (12 + this._BodyLength), CMPP_Command_Id.CMPP_SUBMIT, this._Sequence_Id);
        }
 
        public byte[] ToBytes()
        {
            int dstOffset = 0;
            byte[] dst = new byte[12 + this._BodyLength];
            byte[] src = this._Header.ToBytes();
            Buffer.BlockCopy(src, 0, dst, 0, src.Length);
            dstOffset += 12;
            src = new byte[8];
            src = BitConverter.GetBytes(this._Msg_Id);
            Array.Reverse(src);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 8;
            dst[dstOffset++] = (byte) this._Pk_total;
            dst[dstOffset++] = (byte) this._Pk_number;
            dst[dstOffset++] = (byte) this._Registered_Delivery;
            dst[dstOffset++] = (byte) this._Msg_level;
            src = Encoding.ASCII.GetBytes(this._Service_Id);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 10;
            dst[dstOffset++] = (byte) this._Fee_UserType;
            src = Encoding.ASCII.GetBytes(this._Fee_terminal_Id);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 0x15;
            dst[dstOffset++] = (byte) this._TP_pId;
            dst[dstOffset++] = (byte) this._TP_udhi;
            dst[dstOffset++] = (byte) this._Msg_Fmt;
            src = Encoding.ASCII.GetBytes(this._Msg_src);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 6;
            src = Encoding.ASCII.GetBytes(this._FeeType);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 2;
            src = Encoding.ASCII.GetBytes(this._FeeCode);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 6;
            src = Encoding.ASCII.GetBytes(this._ValId_Time);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 0x11;
            src = Encoding.ASCII.GetBytes(this._At_Time);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 0x11;
            src = Encoding.ASCII.GetBytes(this._Src_Id);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 0x15;
            this._DestUsr_tl = (uint) this._Dest_terminal_Id.Length;
            dst[dstOffset++] = (byte) this._DestUsr_tl;
            foreach (string str in this._Dest_terminal_Id)
            {
                src = Encoding.ASCII.GetBytes(str);
                Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
                dstOffset += 0x15;
            }
            dst[dstOffset++] = (byte) this._Msg_Length;
            Buffer.BlockCopy(this._Msg_Content_Bytes, 0, dst, dstOffset, this._Msg_Content_Bytes.Length);
            dstOffset += (int) this._Msg_Length;
            src = Encoding.ASCII.GetBytes(this._Reserve);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            return dst;
        }
 
        public override string ToString()
        {
            return ("[\r\n" + this._Header.ToString() + "\r\n" + string.Format("\tMessageBody:\r\n\t\tAt_Time: {0}\r\n\t\tBodyLength: {1}\r\n\t\tDest_terminal_Id: {2}\r\n\t\tDestUsr_tl: {3}\r\n\t\tFee_terminal_Id: {4}\r\n\t\tFee_UserType: {5}\r\n\t\tFeeCode: {6}\r\n\t\tFeeType: {7}\r\n\t\tReserve: {8}\r\n\t\tMsg_Content: {9}\r\n\t\tMsg_Fmt: {10}\r\n\t\tMsg_Id: {11}\r\n\t\tMsg_Length: {12}\r\n\t\tMsg_level: {13}\r\n\t\tMsg_src: {14}\r\n\t\tPk_number: {15}\r\n\t\tPk_total: {16}\r\n\t\tRegistered_Delivery: {17}\r\n\t\tSequence_Id: {18}\r\n\t\tService_Id: {19}\r\n\t\tSrc_Id: {20}\r\n\t\tTP_pId: {21}\r\n\t\tTP_udhi: {22}\r\n\t\tValId_Time: {23}", new object[] { 
                this._At_Time, this._BodyLength, string.Join(",", this._Dest_terminal_Id), this._DestUsr_tl, this._Fee_terminal_Id, this._Fee_UserType, this._FeeCode, this._FeeType, this._Reserve, this._Msg_Content, this._Msg_Fmt, this._Msg_Id, this._Msg_Length, this._Msg_level, this._Msg_src, this._Pk_number, 
                this._Pk_total, this._Registered_Delivery, this._Sequence_Id, this._Service_Id, this._Src_Id, this._TP_pId, this._TP_udhi, this._ValId_Time
             }) + "\r\n]");
        }
 
        public string At_Time
        {
            get
            {
                return this._At_Time;
            }
            set
            {
                this._At_Time = value;
            }
        }
 
        public string[] Dest_terminal_Id
        {
            get
            {
                return this._Dest_terminal_Id;
            }
            set
            {
                this._Dest_terminal_Id = value;
            }
        }
 
        public uint DestUsr_tl
        {
            get
            {
                return this._DestUsr_tl;
            }
            set
            {
                this._DestUsr_tl = value;
            }
        }
 
        public string Fee_terminal_Id
        {
            get
            {
                return this._Fee_terminal_Id;
            }
            set
            {
                this._Fee_terminal_Id = value;
            }
        }
 
        public uint Fee_UserType
        {
            get
            {
                return this._Fee_UserType;
            }
            set
            {
                this._Fee_UserType = value;
            }
        }
 
        public string FeeCode
        {
            get
            {
                return this._FeeCode;
            }
            set
            {
                this._FeeCode = value;
            }
        }
 
        public string FeeType
        {
            get
            {
                return this._FeeType;
            }
            set
            {
                this._FeeType = value;
            }
        }
 
        public MessageHeader Header
        {
            get
            {
                return this._Header;
            }
            set
            {
                this._Header = value;
            }
        }
 
        public string Msg_Content
        {
            get
            {
                return this._Msg_Content;
            }
            set
            {
                this._Msg_Content = value;
                this.SetHeader();
            }
        }
 
        public uint Msg_Fmt
        {
            get
            {
                return this._Msg_Fmt;
            }
            set
            {
                this._Msg_Fmt = value;
            }
        }
 
        public ulong Msg_Id
        {
            get
            {
                return this._Msg_Id;
            }
            set
            {
                this._Msg_Id = value;
            }
        }
 
        public uint Msg_Length
        {
            get
            {
                return this._Msg_Length;
            }
            set
            {
                this._Msg_Length = value;
            }
        }
 
        public uint Msg_level
        {
            get
            {
                return this._Msg_level;
            }
            set
            {
                this._Msg_level = value;
            }
        }
 
        public string Msg_src
        {
            get
            {
                return this._Msg_src;
            }
            set
            {
                this._Msg_src = value;
            }
        }
 
        public uint Pk_number
        {
            get
            {
                return this._Pk_number;
            }
            set
            {
                this._Pk_number = value;
            }
        }
 
        public uint Pk_total
        {
            get
            {
                return this._Pk_total;
            }
            set
            {
                this._Pk_total = value;
            }
        }
 
        public uint Registered_Delivery
        {
            get
            {
                return this._Registered_Delivery;
            }
            set
            {
                this._Registered_Delivery = value;
            }
        }
 
        public string Reserve
        {
            get
            {
                return this._Reserve;
            }
            set
            {
                this._Reserve = value;
            }
        }
 
        public string Service_Id
        {
            get
            {
                return this._Service_Id;
            }
            set
            {
                this._Service_Id = value;
            }
        }
 
        public string Src_Id
        {
            get
            {
                return this._Src_Id;
            }
            set
            {
                this._Src_Id = value;
            }
        }
 
        public uint TP_pId
        {
            get
            {
                return this._TP_pId;
            }
            set
            {
                this._TP_pId = value;
            }
        }
 
        public uint TP_udhi
        {
            get
            {
                return this._TP_udhi;
            }
            set
            {
                this._TP_udhi = value;
            }
        }
 
        public string ValId_Time
        {
            get
            {
                return this._ValId_Time;
            }
            set
            {
                this._ValId_Time = value;
            }
        }
 
        public string WapURL { get; set; }
    }
}