調用華為簡訊開發包髮長簡訊(C#版 CMPP3.0)

來源:互聯網
上載者:User

描述:應特殊需要,必須在很短時間內開發穩定的簡訊處理常式,採用了移動給的簡訊開發包,長簡訊發送一直沒有找到相關文檔解決,作為一個碼農只能找些非主流的方法解決問題了

api聲明

       [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);

 

長簡訊發送調用 ,仔細分析下吧

                                       UDHI = 1;                   int HeadLenght = 7;  //包頭長度                      string MtMsg = _message.StrSMSContent;                   byte[] messageUCS2 = Encoding.BigEndianUnicode.GetBytes(MtMsg);                                    int messageUCS2Len = messageUCS2.Length;                   int maxMessageLen = 139;                   if (messageUCS2Len > maxMessageLen)                   {                     int messageUCS2Count = messageUCS2Len / (maxMessageLen - HeadLenght) + 1;                       //長簡訊分為多少條發送                       byPKTotal = (byte)messageUCS2Count;                       byte[] tp_udhiHead = new byte[HeadLenght];                       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;                       //預設為第一條                       for (int i = 0; i< messageUCS2Count; i++)                       {                        byPKNumber = (byte)(i + 1);      //同一條簡訊的第幾條                           tp_udhiHead[6]=(byte)(i + 1);                         byte[] msgContent;                           if (i != messageUCS2Count - 1)                           {                             //不為最後一條               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.CMPP3Submit(byPKTotal, byPKNumber, SRR, byMsglevel, ServiceSubType, byFeeUserType, sFeeAddr,           byFeeTerminalType, PID, Default_ID, UDHI, DCS, sSPID, sFeeType, sFeeCode,        Schedule, Expire, OrgAddr, byUserNum, sDestAddrs, byDestTerminalType, UDLen, str_msgContent,        sLinkID, byMsgID);}}

 

不是最好的方法,但是解決問題,超長簡訊也無壓力。

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.