Cmpp send long letter, I can achieve the CMPP2 long letter implementation (Java version)

Source: Internet
Author: User
cmpp Send long letter, I can achieve the CMPP2 long letter implementation (Java version)

I resigned after the Yidong engaged in text messaging and mass work, from Beijing experts where learned to send text messages, the beginning can only send a short letter, is not more than 140 characters, if more than I will split and then divided into short send. has not been able to send more than 140 characters. Later after I read a lot of people post to achieve, mainly read the following content, and then modify the code to achieve. Hope to help the same confused friends as me.

Http://blog.csdn.net/pwlazy/archive/2010/03/05/5349625.aspx everybody has what not to understand can look here, writes very good.

Let me say my realization:

1. The cmppsubmitmessage of the time when we could send a short letter. We're still going to use this. I developed the use of a SMS development package made by Huawei. This package is moved to. To do a short message gateway can be called mobile delivery. Texting is the Com.huawei.smproxy.CMPPSMProxy.send (cmppsubmitmessage
Msgvo) method is sent. Long and long letters are also sent with this.

Several properties in the Cmppsubmitmessage class explain:

/**
* The total number of information in the same msg_id, starting from 1
*/
int pktotal = 1;
/**
* Pk_number 1
Unsigned Integer the same msg_id information number, starting from 1
*/
int
Pknumber = 1;

/**
* Registered_delivery 1
Whether the Unsigned Integer requires a return status confirmation report:
0: No need
1: Need
2: The production of SMC message list

(This type of SMS only for the gateway billing use, not sent to the destination terminal)
*/
int Registereddelivery
= 1;

/**
* Msg_level 1 Unsigned Integer
Information level
*/
int msglevel = 3;

/**
* service_id octet String business type, a combination of numbers, letters, and symbols.

*/
String Serviceid = "XXXXX";

/**
* Fee_usertype
* Billing User Type field

0: For the purpose terminal MSISDN billing;
1: The source terminal msisdn billing;
2: the SP billing;

3: This field is invalid, and who is billed to see the fee_terminal_id field.
*/
int
Feeusertype = 2;

/**
*
The number of the billed user (such as this byte fill in the blanks, which means that this field is invalid, who is billed to see the Fee_usertype field, this field is mutually exclusive with the Fee_usertype field)

*/
String feeterminalid = "";

/**
* GSM protocol type. Detailed explanation please refer to the 9.2.3.9 in GSM03.40

*/
int tppid = 0;
/**
*
GSM protocol type. Detailed explanation please refer to 9.2.3.23 in GSM03.40, use only 1 bits, right align
*
Long message: 1. The short message is: 0
*/
//int Tpudhi
= 0;

/**
* Information Format
0:ascii string

3: SMS Writing card operation
4: Binary Information
8:UCS2 Code
15: with GB characters ...

*/
//int msgFMT =
8;

/**
* Information content source (sp_id)

*/
String msgsrc = "XXXX";

/**
* Tariff Category
01: For "Billing user number" free
02: The "Billing user number" in accordance with the provision of information fees

03: The "Billing user number" according to the monthly fee collection information
04: The information fee for "Billing user number" is capped

05: The charge for "Billing user number" is realized by SP
*/
String Feetype =
"A";

/**
* Tariff code (to be divided into units)

*/
String Feecode = "0";
/**

* Survival validity, format follows SMPP3.3 protocol
*/
Date validtime =
null;

/**
* Timed delivery time, format follows SMPP3.3 protocol

*/
Date attime = null;
/**
*
SOURCE number
SP's service code or prefix is a long number of service codes,

The gateway fills the number complete with the corresponding source_addr field of the SMPP protocol SUBMIT_SM message,

The number is eventually displayed on the user's phone as the main name for the short message.
*/
//string Srcterminalid
= "XXXXXX";

/**
* MSISDN number to receive SMS

*/
string[] Destterminalid =
{"XXXXX"};

Many parts of this class can be used without charge, and the length of the letter to be modified are:

1.//int tpudhi = 1; This is to be modified to 1.

2 int msgFMT = 8;
Can only be encoded in UCS2 format

3 The long text into several short letters sent.

1th, 2 good changes.

3rd, I've written an implementation class here:

Import java.util.ArrayList;
Import
Java.util.List;

public class Longmessagebyte {
public static
List<byte[]> getlongbyte (String message) {
list<byte[]> list =
New Arraylist<byte[]> ();
try {
Byte[] messageUCS2;

messageUCS2 = Message.getbytes ("unicodebigunmarked");
int Messageucs2len
= length of long letter messageucs2.length;//
int maxmessagelen = 140;
If
(Messageucs2len > Maxmessagelen) {//short letter Send
int tpudhi = 1;
The long message is 1. The short message is 0.
int MSGFMT = 0x08;//Long message cannot be used GBK
Int
Messageucs2count = Messageucs2len/(maxMessageLen-6) + 1;//
The length of the letter is divided into how many send
byte[] Tp_udhihead = new Byte[6];
Tp_udhihead[0] =
0x05;
TP_UDHIHEAD[1] = 0x00;
TP_UDHIHEAD[2] = 0x03;

TP_UDHIHEAD[3] = 0x0A;
TP_UDHIHEAD[4] = (byte) messageucs2count;

TP_UDHIHEAD[5] = 0x01;//defaults to the first rule
for (int i = 0; i < Messageucs2count;
i++) {
TP_UDHIHEAD[5] = (byte) (i + 1);
Byte[]
Msgcontent;
if (i!= messageucs2count-1) {//not the last one

Msgcontent=byteadd (Tp_udhihead,
MessageUCS2,
i* (maxMessageLen-6),
(i+1) * (maxMessageLen-6));

List.add (msgcontent);
} else {

Msgcontent=byteadd (Tp_udhihead,
MessageUCS2, i* (maxMessageLen-6),
Messageucs2len);
List.add (msgcontent);
}
}

}
catch (Exception e) {
E.printstacktrace ();
}
Return
List
}

private static byte[] Byteadd (byte[] Tpudhihead,
Byte[] messageUCS2, int i,
Int J) {
byte[] MSGB = new
BYTE[J-I+6];
System.arraycopy (tpudhihead,0,msgb,0,6);

System.arraycopy (messageucs2,i,msgb,6,j-i);
Return
MSGB;
}
}
This is the case when a short letter was sent:

message = new Cmppsubmitmessage (Pktotal, Pknumber,

Registereddelivery, Msglevel, Serviceid, Feeusertype,

Feeterminalid, Tppid,0,
MSGSRC,
Feetype, Feecode, Validtime, Attime, Srcterminalid,

Destterminalid, msgcontent.getbytes ("GBK"),
"");

The message is now issued as follows:

list<byte[]> list =
Longmessagebyte.getlongbyte (msgcontent);
for (byte[)
Msg:list) {

Message = new Cmppsubmitmessage (pktotal, Pknumber,

                registereddelivery, Msglevel, Serviceid, Feeusertype,

                Feeterminalid, Tppid, 1,
8, msgsrc,
               Feetype, Feecode, Validtime,
Attime, Srcterminalid,
                destterminalid,msg, "");



SYSTEM.OUT.PRINTLN (message);

System.out.println (Sender.getconnstate ());
Returnmsg =
Sender.send (message);

System.out.println (RETURNMSG);
}

This will do, the specific agreement can go to see http://blog.csdn.net/pwlazy/archive/2010/03/05/5349625.aspx this everyone wrote.

Turn from: http://hi.baidu.com/hhayy7758/item/e7a3c7c7952d4860f6c95d53

Related Article

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.