package safeluck.drive.evaluation.im;
|
|
import android.util.Log;
|
|
import com.anyun.exam.lib.MyLog;
|
import com.anyun.im_lib.util.ByteUtil;
|
|
import safeluck.drive.evaluation.platformMessage.PlatFormConstant;
|
import safeluck.drive.evaluation.platformMessage.RegisterResp;
|
import safeluck.drive.evaluation.platformMessage.ServerCommonRsp;
|
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
|
import safeluck.drive.evaluation.util.Utils;
|
|
/**
|
* MyApplication2
|
* Created by lzw on 2019/12/12. 16:14:33
|
* 邮箱:632393724@qq.com
|
* All Rights Saved! Chongqing AnYun Tech co. LTD
|
*/
|
public class MessageProcessor implements IMessageProcessor {
|
|
private static final String TAG = MessageProcessor.class.getSimpleName();
|
|
private MessageProcessor(){
|
|
}
|
|
private static class MessageProcessorInstance{
|
private static final IMessageProcessor INSTANCE = new MessageProcessor();
|
}
|
|
public static IMessageProcessor getInstance(){
|
return MessageProcessorInstance.INSTANCE;
|
}
|
|
@Override
|
public void receiveMsg(byte[] message) {
|
byte[] datas = Utils.parseMsg(message);
|
Log.i(TAG, "receiveMsg: "+ ByteUtil.byte2HexStr(datas));
|
byte checkcolde=Utils.calCheckCode(ByteUtil.subArray(datas,0,datas.length-1));
|
if (checkcolde == datas[datas.length-1]){
|
Log.i(TAG, "receiveMsg: 消息正确");
|
parseMessage(datas);
|
}
|
}
|
|
private void parseMessage(byte[] datas) {
|
byte[] msgidBytes = ByteUtil.subArray(datas,1,2);
|
short msgid = ByteUtil.getShort(msgidBytes);
|
|
switch (msgid){
|
case (short) 0x8100:
|
RegisterResp registerResp = new RegisterResp(datas);
|
break;
|
case (short) 0x8001://服务器端 通用应答
|
ServerCommonRsp serverCommonRsp = new ServerCommonRsp(datas);
|
if (serverCommonRsp.getResult() == PlatFormConstant.SUCCESS){
|
MyLog.i(PlatFormConstant.TAG,"确认"+serverCommonRsp.getMsgId()+"消息成功");
|
}
|
break;
|
|
}
|
}
|
|
@Override
|
public void sendMessage(final byte[] msg) {
|
CThreadPoolExecutor.runInBackground(new Runnable() {
|
@Override
|
public void run() {
|
if (IMSClientBootstrap.getInstance().isActive()){
|
|
IMSClientBootstrap.getInstance().sendMessage(msg);
|
}else{
|
Log.e(TAG, "run: 发送消息失败,未初始化连接NettyTcp");
|
}
|
}
|
});
|
}
|
}
|