登录应答协议包定义
|
字段名 |
字节数 |
属性 |
描述 |
|
Status |
1 |
Unsigned Integer |
状态 0:正确 1:消息结构错 2:非法源地址 3:认证错 4:版本太高 5~ :其他错误 |
|
AuthenticatorISMG |
16 |
Octet String |
ISMG认证码,用于鉴别ISMG。 其值通过单向MD5 hash计算得出,表示如下: AuthenticatorISMG =MD5(Status+AuthenticatorSource+shared secret),Shared secret 由中国移动与源地址实体事先商定,AuthenticatorSource为源地址实体发送给ISMG的对应消息CMPP_Connect中的值。 认证出错时,此项为空。 |
|
Version |
1 |
Unsigned Integer |
服务器支持的最高版本号 |
消息体长度:1+16+1=18
登录协议包发送后,获取登录应答协议包内容,并解析。
MobileConnectResp.cs
public MobileConnectResp(byte[] sb)
{
FromBytes(sb);
}
public void FromBytes(byte[] sb)
{
MobileMessageTitle header = new MobileMessageTitle(sb);
int index = 0;
index += (int)header.MessageTitleLength;
this.Status = sb[index];//Tools.UintArrayToUint(Tools.IntChangeNetByte(Tools.SubByte(sb, index, 1)));
index += 1;
this.AuthenticatorISMG = Tools.ByteToString(Tools.SubByte(sb, index, 16), "ASCII");
index += 16;
this.Version = sb[index];
}
uint status;
/// <summary>
/// 登录状态0:正确 1:消息结构错2:非法源地址 3:认证错4:版本太高 5:其他错误
/// </summary>
public uint Status
{
get
{
return this.status;
}
set
{
this.status = value;
}
}
uint version;
/// <summary>
/// 服务器支持的最高版本号,对于3.0的版本,高4bit为3,低4位为0
/// </summary>
public uint Version
{
get
{
return this.version;
}
set
{
this.version = value;
}
}
string authenticatorISMG;
/// <summary>
/// ISMG认证码,用于鉴别ISMG。
/// </summary>
public string AuthenticatorISMG
{
get
{
return this.authenticatorISMG;
}
set
{
this.authenticatorISMG = value;
}
}
获取到应答消息后,首先拆分消息头,然后拆分消息体。
byte[] retxt = new byte[10240];
int index = 0;
index = clientSocket.Receive(retxt);
MobileMessageTitle header = new MobileMessageTitle(retxt);
header.CommandID;//消息类型
MobileConnectResp conr = new MobileConnectResp(retxt);
conr.Status;//登录状态
本文介绍了使用C#进行CMPP2.0协议网关开发,详细解析了登录应答协议包的内容,包括消息体长度计算、消息头拆分和消息体解析,展示了如何获取和处理登录状态。
4817

被折叠的 条评论
为什么被折叠?



