当前位置: 技术问答>java相关
在对接短信接口中遇到的一堆问题!!!!(在线等待)
来源: 互联网 发布时间:2015-10-28
本文导语: 短信商提供的接口如下: Name: CommandID Type: Integer List: CommandName CommandID ------------------- 0x1 Login 0x80000001 Login Response(login OK...
短信商提供的接口如下:
Name: CommandID
Type: Integer
List:
CommandName CommandID
------------------- 0x1
Login
0x80000001 Login Response(login OK)
0x2 Send
0x80000002 Send Response
0x3 Receive
0x80000003 Receive Response
Data Struct:
-----------------------
SP login的数据格式
CommandName:Login
Data: CommandLength + CommandID + SPName + SPPassword + SPType
CommandLength Integer
CommandID Integer
SPName Varchar
SPPassword Varchar
SPType Varchar
SP login回应的数据格式
CommandName:Login Response
Data: CommandLength + CommandID + Response
CommandLength Integer
CommandID Integer
Response Integer
SP发送短信的数据格式
CommandName:Send
Data:CommandLength + CommandID + FeeType + FeeValue + SourceNO + DestNO + ShortMessage
(注 FeeType 计费类别 FeeValue 费率 SourceNO 发送号码 SestNO 接收号码)
CommandLength Integer
CommandID Integer
FeeType Integer
FeeValue Integer
SourceNO Varchar
DestNO Varchar
ShortMessage Varchar
SP发送短信的回应数据格式
CommandName:Send Response
Data:CommandLength +_CommandID + Response
CommandLength Integer
CommandID Integer
Response Integer
SP接收短信的数据格式
CommandName:Receive
Data:CommandLength + CommandID + SourceNO + DestNO + ShortMessage
CommandLength Integer
CommandID Integer
SourceNO Varchar
DestNO Varchar
ShortMessage Varchar
SP接收回应的数据格式
CommandName:Receive Response
Data:CommandLength + CommandID + Response
CommandLength Integer
CommandID Integer
Response Integer
============以上是提供的接口==============
为了在 jsp 中调用,我用 socket 来对接此接口,问题一个接一个
1. 所以数据都是用 byte[] 来传送, 我不得不把 int , string 转换,再重组到 byte 中,程序如下
int iCommandID = 0x1;
byte command[] = new byte[4];
command[0] = (byte)( (iCommandID & 0xff000000) >>> 24);
command[1] = (byte)( (iCommandID & 0x00ff0000) >>> 16);
command[2] = (byte)( (iCommandID & 0x0000ff00) >>> 8);
command[3] = (byte)( (iCommandID & 0x000000ff) );
byte source[] = strSource.getBytes(); //? 得到 byte[] 后 结尾 是否有 '' ,是不是转换成了 0??
如果 得到长度 source.length 行吗??(后面必须得加上0,字符串的分割符)
2.接收数据时候,这段代码可行吗?
private class ReadThread extends Thread {
public void run() {
byte[] buf = new byte[1024];
while(true) {
int iLength = 0;
byte len[]; //这组数据的长度
int avail = in.available();
if(avail>0){ // 如果可读(有数据)
if ( in.read( len, 0,4 ) != -1 ){
iLength = ((int)len[0]) & (((int)len[1])