📄 mms_send.java
字号:
package robinyummspush;
import java.net.*;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class SendMMS {
public SendMMS() {
}
static byte wdphead[] = {//wdp header
(byte)0x0B,//header total Length
(byte)0x05,//UDH IE identifier:Port Numbers(5) ID element
(byte)0x04,//UDH port number IE length(4) length of params
(byte)0x0B,//Destination Port (High)
(byte)0x84,//(Low)
(byte)0x23,//Originator Port (High)
(byte)0xF0,//(Low)
(byte)0x00,//UDH IE identifier:SAR(0) concatenation identifier element
(byte)0x03,//UDH SAR IE length(3) length of params
(byte)0x9D,//Datagram Reference number concat reference
(byte)0x01,//Total number of segments in datagram total parts
(byte)0x01 //sequence number
};
static byte wsphead[] = {//wsp header
(byte)0x3C,//Transaction ID
(byte)0x06,//PDU type (push)
(byte)0x22,//header length 34bytes
(byte)0x61, (byte)0x70, (byte)0x70, (byte)0x6C, (byte)0x69, (byte)0x63,
(byte)0x61, (byte)0x74, (byte)0x69, (byte)0x6F, (byte)0x6E, (byte)0x2F,
(byte)0x76, (byte)0x6E, (byte)0x64, (byte)0x2E, (byte)0x77, (byte)0x61,
(byte)0x70, (byte)0x2E, (byte)0x6D, (byte)0x6D, (byte)0x73, (byte)0x2D,
(byte)0x6D, (byte)0x65, (byte)0x73, (byte)0x73, (byte)0x61, (byte)0x67,
(byte)0x65,//application/vnd.wap.mms-message
(byte)0x00,
(byte)0xAF, (byte)0x84//x-wap-application.ua 哪里定义的??
};
static byte mmsbody1[] = {
(byte)0x8C, (byte)0x82, //message type:0x0c p28MMSEncapsulation , m-notification.ind 0x82 p25MMSEncapsulation
(byte)0x98 //MMS transaction ID
};
//textual transaction id
static byte mmsbody2[] = {
(byte)0x00, //end of textual transaction id
(byte)0x8d,(byte)0x90,
(byte)0x83 //content location 0x03 p28MMSEncapsulation
};
//textual conent location
static byte mmsbody3[] = {
(byte)0x00, //textual content location end
(byte)0x88, //expire 0x08 p28MMSEncapsulation
/* (byte)0x05,
(byte)0x81,
(byte)0x03,(byte)0x02,(byte)0xA2,(byte)0xFF,
*/
(byte)0x05, //expiry length
(byte)0x81, //relative format
(byte)0x03, //3 octets
(byte)0x00,(byte)0x00,(byte)0x3c, //1day (60 secs)//0302A2FF
(byte)0x89, //from
(byte)0x09, //len
(byte)0x80, //address present
(byte)0x31,(byte)0x30,(byte)0x31,(byte)0x30,(byte)0x31,(byte)0x30,(byte)0x30,//1010100
(byte)0x00, //textual from end
(byte)0x8A, (byte)0x80, //message class:0x0A p28MMSEncapsulation,personal 0x80 p24MMSEncapsulation
(byte)0x8E, //msg size 0x0E p28MMSEncapsulation
(byte)0x02, //2 octets
(byte)0x94, (byte)0xe2, //419 bytes 长度!!!应该填写我的MMS消息的长度
};
static byte mmsbody4[]={
(byte)0x96, //subject:0x16 p28MMSEncapsulation
(byte)0x01, //subject len
(byte)0xEA, //utf8
(byte)0x7F //Quote
};
//subject
static byte mmsbody5[]={
(byte)0x00 //subject end
};
public static byte[] genMMSPush(String title, String url) {
try{
int title_len; //标题长度
int url_len; //url长度
int total_len; //结果长度
byte[] id_bytes;
byte[] title_bytes; //标题byte流
byte[] url_bytes; //url byte流
long transactionid = (long)(Math.random() * 100000);
String s_transactionid = Long.toString(transactionid);//"0140000430392050516174317002";//"0130000061339050513153940002";//
System.out.println("Transaction_id:"+s_transactionid);
id_bytes = s_transactionid.getBytes("ISO-8859-1");
title_bytes = title.getBytes("UTF8");
url_bytes = url.getBytes("ISO-8859-1");
System.out.print("\ntitle:");
for(int i=0;i<title_bytes.length;i++){
System.out.print("["+Integer.toHexString((byte)title_bytes[i])+"]");
}
title_len = title_bytes.length;
url_len = url_bytes.length;
mmsbody4[1] = (byte)(title_bytes.length+3);//设置标题长度
total_len = id_bytes.length + title_len + url_len +
wsphead.length + mmsbody1.length + mmsbody2.length +
mmsbody3.length + mmsbody4.length + mmsbody5.length;//计算总长度
byte[] result_bytes = new byte[total_len];//根据总长度构造结果流
int i = 0;
for (i = 0; i < wsphead.length; i++) {
result_bytes[i] = wsphead[i];
}
i = wsphead.length;
for (int j = 0; j < mmsbody1.length; j++) {
result_bytes[i + j] = mmsbody1[j];
}
i += mmsbody1.length;
for (int j = 0; j < id_bytes.length; j++) {
result_bytes[i + j] = id_bytes[j];
}
i += id_bytes.length;
for (int j = 0; j < mmsbody2.length; j++) {
result_bytes[i + j] = mmsbody2[j];
}
i += mmsbody2.length;
for (int j = 0; j < url_len; j++) {
result_bytes[i + j] = url_bytes[j];
}
i += url_len;
for (int j = 0; j < mmsbody3.length; j++) {
result_bytes[i + j] = mmsbody3[j];
}
i += mmsbody3.length;
for (int j = 0; j < mmsbody4.length; j++) {
result_bytes[i + j] = mmsbody4[j];
}
i += mmsbody4.length;
for (int j = 0; j < title_len; j++) {
result_bytes[i + j] = title_bytes[j];
}
i += title_len;
for (int j = 0; j < mmsbody5.length; j++) {
result_bytes[i + j] = mmsbody5[j];
}
i += mmsbody5.length;
return result_bytes;
} catch (Exception e){
return null;
}
}
public static int sendSMS(String phonenumber, String content) {
try {
System.out.print("\nbody:");
byte toshow[] = content.getBytes("ISO-8859-1");
for(int i=0;i<toshow.length;i++){
System.out.print("["+Integer.toHexString((byte)toshow[i])+"]");
}
System.out.print("\n");
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String base64str = encoder.encode(content.getBytes("ISO-8859-1"));
base64str = base64str.replaceAll("\r\n","");
base64str = base64str.replaceAll("\n","");
base64str = java.net.URLEncoder.encode(base64str,"ISO-8859-1");
System.out.println("PUSH: BASE64:"+base64str);
}catch (Exception e) {
System.out.println("PUSH: Send SMS error:" + e);
}
return -1;
}
public static int sendOnePush(String hint, String urlstr, String PhoneNum) throws Exception {
byte[] rst = genMMSPush(hint, urlstr);
if (rst.length + 12 <= 140) { //单条是否足够
//单条OK
wdphead[9] = (byte) (Math.random() * 1000 % 255);
System.out.println("PUSH: msg_id:" + (byte) wdphead[9]);
byte[] tempbytes = rst;
tempbytes[0] = wdphead[9];
rst = new byte[rst.length + 12];
for (int i = 0; i < wdphead.length; i++) {
rst[i] = wdphead[i];
}
for (int i = 0; i < tempbytes.length; i++) {
rst[i + 12] = tempbytes[i];
}
int result = sendSMS(PhoneNum,new String(rst,"ISO-8859-1"));
System.out.println("PUSH: single content length:"+rst.length +" phone:"+PhoneNum+" result:"+result);
return result;
}
else {//多条
wdphead[9] = (byte) (Math.random() * 1000 % 255);
System.out.println("PUSH: msg_id:" + (byte) wdphead[9]);
byte[] tempbytes = rst;
tempbytes[0] = wdphead[9];
rst = new byte[140]; //构造长度=140的数组
for (int i = 0; i < wdphead.length; i++) {
rst[i] = wdphead[i];
}
rst[10] = 2;//共两条
rst[11] = 1;//第一条
for (int i = 0; i < 128; i++) {//头之外的128个byte
rst[i + 12] = tempbytes[i];
}
int result1 = sendSMS(PhoneNum,new String(rst,"ISO-8859-1"));
System.out.println("PUSH: first content length:"+rst.length +" phone:"+PhoneNum+" result:"+result1);
try{//睡眠2秒再发送下一条
Thread.sleep(1000);
}catch(Exception e){}
rst = new byte[tempbytes.length - 128 + 12];
for (int i = 0; i < wdphead.length; i++) {
rst[i] = wdphead[i];
}
rst[10] = 2;//共两条
rst[11] = 2;//第二条
for (int i = 0; i < tempbytes.length - 128; i++) {
rst[i + 12] = tempbytes[i + 128];
}
int result2 = sendSMS(PhoneNum,new String(rst,"ISO-8859-1"));
System.out.println("PUSH second content length:"+rst.length +" phone:"+PhoneNum+" result:"+result2);
return result1&result2;
}
}
public static void main(String args[]){
try{
SendMMS.sendOnePush("清纯美女033","http://210.77.150.119"
//"http://210.77.150.119/0140000430392050516174317002.mms"
,"13651379441");//"13910820337");//"13701058457");//
}catch (Exception e){
System.out.println("Send One MMS Push Error:"+e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -