📄 loginmessage.java
字号:
package com.gctech.sms.sp.cms.msg2;
import java.util.Date;
import com.gctech.sms.sp.cms.util.*;
public class LoginMessage extends Message{
private String spId ;
private String secret;
private int now;
public LoginMessage(String spId,String secret)
{
this.totalLength = 56;
this.commandId = Message.LOGIN_REQ;
this.sequenceId = Message.nextSeqId() ;
this.spId = spId;
this.secret = secret;
now = TypesTools.date2int(new Date());
}
public byte[] toBytes()
{
ProtocolBuffer pb = ProtocolBuffer.create(56);
pb.appendInt(this.totalLength);
pb.appendInt(this.commandId);
pb.appendInt(0);
pb.appendInt(sequenceId);
pb.appendString(spId,20);
// String authClient = getMD5();
// pb.appendString(authClient,authClient.length());
pb.appendBytes(getMD5());
pb.appendInt(now);
return pb.toBytes();
}
public byte[] getMD5()
{
ProtocolBuffer pb = ProtocolBuffer.create(20+7+secret.length()+10);
pb.appendString(spId,20);
pb.appendBynary0(7);
pb.appendString(secret,secret.length());
String time = ""+now;
if(time.length()<10)
{
time = "0"+time;
}
pb.appendString(time,time.length());
MD5 md5 = new MD5();
byte[] bs = pb.toBytes();
// String authClient = md5.getMD5ofStr(bs,bs.length);
byte[] auth = md5.getMD5ofBytes(bs,bs.length);
return auth;
}
public static LoginMessage create(byte[] bs)
{
throw new UnsupportedOperationException("cp side can not support this method ");
}
// public byte[] toBytes()
// {
// return null;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -