Call the Huawei SMS development kit to send long messages (C # cmpp3.0)

Source: Internet
Author: User

Description: a stable text message processing program must be developed within a short period of time to meet special requirements. The mobile text message development kit is used, and no relevant documentation is found for long text message sending, as a code farmer, I can only find some non-mainstream methods to solve the problem.

API Declaration

       [DllImport("SMEIDLL.DLL",CharSet = CharSet.Unicode)]       public static extern int CMPP3Submit(        [MarshalAs(UnmanagedType.U1)] byte byPKTotal,        [MarshalAs(UnmanagedType.U1)] byte byPKNumber,        [MarshalAs(UnmanagedType.U1)] byte SRR,        [MarshalAs(UnmanagedType.U1)] byte byMsglevel,        [MarshalAs(UnmanagedType.LPStr)]  StringBuilder ServiceSubType,        [MarshalAs(UnmanagedType.U1)] byte byFeeUserType,        [MarshalAs(UnmanagedType.LPStr)]  StringBuilder sFeeAddr,        [MarshalAs(UnmanagedType.U1)] byte byFeeTerminalType,        [MarshalAs(UnmanagedType.U1)] byte PID,        UInt32 Default_ID,        [MarshalAs(UnmanagedType.U1)] byte UDHI,        [MarshalAs(UnmanagedType.U1)] byte DCS,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder sSPID,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder sFeeType,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder sFeeCode,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder Schedule,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder Expire,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder OrgAddr,       [MarshalAs(UnmanagedType.U1)] byte byUserNum,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder sDestAddrs,       [MarshalAs(UnmanagedType.U1)] byte byDestTerminalType,       UInt32 UDLen,       String UserData,       [MarshalAs(UnmanagedType.LPStr)]  StringBuilder sLinkID,     [MarshalAs(UnmanagedType.LPStr)] StringBuilder byMsgID);

 

Send and call long messages. analyze them carefully.

Udhi = 1; int headlenght = 7; // header length string mtmsg = _ message. strsmscontent; byte [] messageucs2 = encoding. bigendianunicode. getbytes (mtmsg); int messageucs2len = messageucs2.length; int maxmessagelen = 139; If (latency> maxmessagelen) {int messageucs2count = Bytes/(maxmessagelen-headlenght) + 1; // The number of messages sent with long SMS messages: bypktotal = (byte) messageucs2count; byte [] tp_udhihead = new byte [Head Lenght]; tp_udhihead [0] = 0x06; tp_udhihead [1] = 0x08; tp_udhihead [2] = 0x04; tp_udhihead [3] = 0x00; tp_udhihead [4] = 0x00; tp_udhihead [5] = (byte) messageucs2count; tp_udhihead [6] = 0x01; // The first for (INT I = 0 by default; I <messageucs2count; I ++) {bypknumber = (byte) (I + 1); // THE NUMBER OF THE SAME TEXT MESSAGE tp_udhihead [6] = (byte) (I + 1); byte [] msgcontent; if (I! = Messageucs2count-1) {// not the last msgcontent = biconvert. byteadd (tp_udhihead, messageucs2, I * (maxmessagelen-headlenght), (I + 1) * (maxmessagelen-headlenght); udlen = (uint) msgcontent. length;} else {msgcontent = biconvert. byteadd (tp_udhihead, messageucs2, I * (maxmessagelen-headlenght), messageucs2len); msgcontent = biconvert. byteadd (msgcontent, new byte [] {0}, 0, 1); udlen = (uint) msgcontent. length-1;} string str_msgcontent = encoding. unicode. getstring (msgcontent); int issub = SMEI. partition (bypktotal, bypknumber, SRR, bymsglevel, servicesubtype, struct, struct, sequence, PID, default_id, udhi, DCs, sspid, sfeetype, struct, schedule, expire, orgaddr, byusernum, sdestaddrs, bydestterminaltype, udlen, str_msgcontent, slinkid, bymsgid );}}

 

It is not the best method, but there is no pressure on ultra-long text messages to solve the problem.

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.