62,614
社区成员
发帖
与我相关
我的任务
分享
public class cmppdemo {
private static Logger log = LogManager.getLogger(cmppdemo.class);
private static int seq = 0;
private static int timestamp = (int) (System.currentTimeMillis() / 1000);
private static Socket socket = null;
/**
* @param args
*/
public static void main(String[] args) {
try {
socket = new Socket("127.0.0.1", 7890);
socket.setSoTimeout(120000);
DataOutputStream out = new DataOutputStream(socket
.getOutputStream());
// 发送消息头
out.writeInt(12 + 6 + 16 + 1 + 4);
out.writeInt(1);
out.writeInt(getSeq());
String icp_id = "901234";
String icp_auth = "123456";
//发送消息体
//Source_Addr
out.writeBytes(icp_id);
SimpleDateFormat sdf = new SimpleDateFormat("MMddHHmmss");
String date = sdf.format(Calendar.getInstance().getTime());
timestamp = Integer.parseInt(date);
byte[] b_icpID = icp_id.getBytes("GB2312");
byte[] b_icpPWD = icp_auth.getBytes("GB2312");
byte beforeMD5[] = new byte[b_icpPWD.length + 25];
System.arraycopy(b_icpID, 0, beforeMD5, 0, 6);
System.arraycopy(b_icpPWD, 0, beforeMD5, 15, b_icpPWD.length);
System.arraycopy(date.getBytes(), 0, beforeMD5,
15 + b_icpPWD.length, date.length());
// 3. ����AuthenticatorSource
MD5 md5 = new MD5();
byte[] md5ed = md5.getMD5ofStr(beforeMD5, beforeMD5.length);
out.write(md5ed);
//
int version = 0x30;
out.writeByte((byte) version);
// 5. ����ʱ���
out.writeInt(timestamp);
DataInputStream in = new DataInputStream(socket.getInputStream());
int pk_len = in.readInt();
int pk_cmd = in.readInt();
int pk_seq = in.readInt();
int status = in.readInt();
int CMPPE_LOGIN_RESP = 0x80000001;
System.out.println(" CMPPE_LOGIN_RESP = " + CMPPE_LOGIN_RESP);
// 读取 登陆消息体
System.out.println(pk_len);
System.out.println(pk_cmd);
System.out.println(pk_seq);
System.out.println(status);
System.out.println(in.readInt());
System.out.println(in.readInt());
System.out.println(in.readInt());
System.out.println("here");
//////////////////////////////////////////////////////////////////////////////////////////////
// 发送短信
out.flush();
out.writeInt(210);
out.writeInt(0x00000004);
out.writeInt(getSeq());
out.writeLong(66); // Msg_Id
out.writeByte(1); //Pk_total
out.writeByte(1); //Pk_numbers
out.writeByte(0); // Registered_Delivery
out.writeByte(1); // Msg_level
byte serviceId = 0;
out.write(serviceId); //Service_Id
out.writeByte(0); //Fee_UserType
out.write(serviceId); //Fee_terminal_Id
out.writeByte(0); //Fee_terminal_type
out.writeByte(0); //TP_pId
out.writeByte(0); //TP_udhi
byte msg_Fmt = 15;
out.writeByte(msg_Fmt); //Msg_Fmt
out.writeBytes("901234"); //Msg_src
out.writeBytes("01"); //FeeType
out.writeBytes("000000"); //FeeCode
out.writeBytes("55555"); // valId_Time
out.writeBytes("0000"); // atTime
out.writeBytes("901234"); //Src_Id
out.writeByte(1); //DestUsr_tl
out.writeBytes("13806666666"); //Dest_terminal_Id
out.writeByte(0); //Dest_terminal_type
out.writeByte(15); //Msg_Length
out.writeBytes("aaa aaaaaaaaaaa"); //Msg_Content
out.writeBytes(""); // LinkID
out.flush();
if (socket.isClosed()) {
socket = new Socket("127.0.0.1", 7890);
socket.setSoTimeout(120000);
}
/* 读取 提交回馈信息 */
System.out.println(Integer.toHexString(in.readInt())); //Msg_Id
System.out.println(in.readInt()); //Result
System.out.println(in.readInt()); //Result
System.out.println(in.readInt()); //Result
System.out.println(in.readInt()); //Result
System.out.println(in.readInt()); //Result
////////////////////////////////////////////////////////////////////////////////////////////
// 推出连接
out.writeInt(2);
out.writeInt(getSeq());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static int getSeq() {
seq++;
if (seq == 0x7fffffff)
seq = 1;
return seq;
}
}