📄 send.java
字号:
/*
* Created on 2004-7-19
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import spApi.Bind;
import spApi.BindResp;
import spApi.Deliver;
import spApi.SGIP_Command;
import spApi.SGIP_Exception;
import spApi.Submit;
import spApi.SubmitResp;
import spApi.Unbind;
import spApi.UnbindResp;
import java.net.*;
import java.io.*;
public class send {
long noteid; //nite_id
String strIp;
int nPort;
String UserName; //登录用户名
String Password; //用户密码
String SPNumber; //sp代码
String CorpId; //企业接入号
public send() {
this.noteid = 3000082300L;
this.strIp = "222.248.9.63";
this.nPort = 8801;
this.UserName = "1xjzhwg";
this.Password = "1xjzhwg";
this.SPNumber = "8714";
this.CorpId = "82300";
}
public int sendSms(int fee_type,int report_type,int mt_flag,int fee,String service_type,String msisdn,String paynumber,String content ) {
Socket so = null;
OutputStream out = null;
InputStream input = null;
Bind command = null;
Bind com = null;
SGIP_Command sgip = null;
SGIP_Command tmp = null;
int usercount = 1;
int i = 0;
try {
sgip = new SGIP_Command();
command = new Bind(noteid, //nodeID 3+CP_ID
1, //login type
UserName, //login name
Password);//login password
int err;
byte[] byte_content = new byte[140];
Deliver deliver = null;
Submit submit = null;
SubmitResp submitresp = null;
Bind active = null;
Unbind term = null;
BindResp resp = null;
UnbindResp Unresp = null;
so = new Socket(strIp, nPort);
out = new DataOutputStream(so.getOutputStream());
input = new DataInputStream(so.getInputStream());
err = command.write(out);//发送bind
if (err != 0) {
System.out.println("bind err" + err);
out.close();
so.close();
return -1;
}
tmp = sgip.read(input);//接收sgip消息
if (sgip.getCommandID() == SGIP_Command.ID_SGIP_BIND_RESP) {
resp = (BindResp) tmp;//强制转换为bindresp
resp.readbody();//对消息进行解包
if( resp.GetResult() != 0 ){
System.out.println("bind err,result:"+resp.GetResult());
out.close();
so.close();
return -1;
}
}
for (i = 0; i < 140; i++) {
byte_content[i] = 51;
i++;
byte_content[i] = 51;
i++;
byte_content[i] = 52;
i++;
byte_content[i] = 53;
i++;
byte_content[i] = 54;
i++;
byte_content[i] = 55;
i++;
byte_content[i] = 56;
i++;
byte_content[i] = 57;
i++;
byte_content[i] = 58;
i++;
byte_content[i] = 59;
}
String cp_phone = SPNumber;
String cp_id = CorpId;
System.out.println(noteid+" "+cp_phone+" "+paynumber+" "+usercount+" "+msisdn+" "+cp_id);
System.out.println(content);
submit = new Submit(noteid, //node id同上
cp_phone, //cp_phone
paynumber,//"000000000000000000000", //付费号码
usercount, //接收短消息的手机数
msisdn, //手机号码前面加86
cp_id, //cp_id
service_type, //业务代码
fee_type,//2, //计费类型
String.valueOf(fee),//"10", //短消息收费值
"0", //赠送话费,
1, //代收标志
mt_flag,//2, //引起MT的原因
9, //优先级
"", //短消息终止时间
"", //011125120000032+短消息定时发送时间
report_type,//1, //状态报告标志
0, //GSM协议类型
0, //GSM协议类型
15, //短消息编码格式
0, //信息类型
content.length(), //短消息长度
content,
0,
0
);//短消息内容
submit.write(out);//发送submit
// System.out.println("seq3:"+submit.getSeqno_3());
tmp = sgip.read(input);
if (tmp.getCommandID() == SGIP_Command.ID_SGIP_SUBMIT_RESP) {
submitresp = (SubmitResp) tmp;//强制转换
submitresp.readbody();//解包
System.out.println("seq1:"+tmp.getSeqno_1());
System.out.println("seq2:"+tmp.getSeqno_2());
System.out.println("seq3:"+tmp.getSeqno_3());
System.out.println("result:"+submitresp.getResult());
if( submitresp.getResult() != 0 ){
System.out.println("bind err,result:"+ submitresp.getResult());
out.close();
so.close();
return -1;
}
}
//com.write(out);
term = new Unbind(399000);
term.write(out);//发送unbind
tmp = sgip.read(input);
if (sgip.getCommandID() == SGIP_Command.ID_SGIP_UNBIND_RESP) {
Unresp = (UnbindResp) tmp;
}
out.close();
so.close();
return 0;
} catch (SGIP_Exception e) {
System.out.println(e.toString());
return -1;
} catch (Exception e) {
System.out.println(e.toString());
return -1;
}
}
public static void main(String[] args) {
try
{
send sms = new send();
//sms.sendSms(2,1,1,10,"100","8613005449774","000000000000000000000","test1");
sms.sendSms(2,1,1,10,"100","8613150332167","abc","短信发送程序测试基本通过");
}
catch(Exception e){System.out.println(e.toString());}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -