init扫码安卓项目,初始化,删除人脸识别内容
This commit is contained in:
@@ -79,7 +79,7 @@ dependencies {
|
|||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||||
implementation 'com.google.code.gson:gson:2.8.4'
|
implementation 'com.google.code.gson:gson:2.8.4'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:3.3.1'
|
implementation 'com.squareup.okhttp3:okhttp:3.3.1'
|
||||||
implementation 'io.netty:netty-all:4.1.17.Final'
|
implementation 'io.netty:netty-all:4.1.10.Final'
|
||||||
implementation 'org.greenrobot:eventbus:3.1.1'
|
implementation 'org.greenrobot:eventbus:3.1.1'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package com.ydd.sportfaceid;
|
package com.ydd.sportfaceid;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
@@ -19,19 +17,13 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.tencent.bugly.Bugly;
|
|
||||||
import com.tencent.bugly.crashreport.CrashReport;
|
import com.tencent.bugly.crashreport.CrashReport;
|
||||||
import com.ydd.sportfaceid.config.SDAppConfig;
|
import com.ydd.sportfaceid.config.SDAppConfig;
|
||||||
import com.ydd.sportfaceid.event.FaceidEvent;
|
import com.ydd.sportfaceid.event.QRCodeEvent;
|
||||||
import com.ydd.sportfaceid.event.MessageEvent;
|
|
||||||
import com.ydd.sportfaceid.main.SDBaseActivity;
|
import com.ydd.sportfaceid.main.SDBaseActivity;
|
||||||
import com.ydd.sportfaceid.net.ClientThread;
|
|
||||||
import com.ydd.sportfaceid.net.dto.MemberDto;
|
|
||||||
import com.ydd.sportfaceid.service.ClientService;
|
import com.ydd.sportfaceid.service.ClientService;
|
||||||
import com.ydd.sportfaceid.setting.SDSettingActivity;
|
import com.ydd.sportfaceid.setting.SDSettingActivity;
|
||||||
import com.ydd.sportfaceid.utils.EggClickUtil;
|
import com.ydd.sportfaceid.utils.EggClickUtil;
|
||||||
import com.ydd.sportfaceid.websocket.FaceWsClient;
|
|
||||||
import com.ydd.sportfaceid.websocket.FaceWsClientService;
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
@@ -297,70 +289,49 @@ public class MainActivity extends SDBaseActivity implements IVLCVout.OnNewVideoL
|
|||||||
* 加载人脸识别信息
|
* 加载人脸识别信息
|
||||||
*/
|
*/
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void loadFaceidInfo(FaceidEvent faceidEvent) {
|
public void loadFaceidInfo(QRCodeEvent qrCodeEvent) {
|
||||||
if (faceidEvent.isDebug){
|
if (qrCodeEvent.msg.equals("不是会员")){
|
||||||
// 这里检测到 debug模式下,显示toast
|
// 这个是非会员进入现场
|
||||||
showToast(faceidEvent.msg);
|
this.showStrangerDialog();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
CrashReport.postCatchedException(new Throwable("接受到命令 " + qrCodeEvent.msg));
|
||||||
MemberDto memberDto = faceidEvent.getMember();
|
|
||||||
if (memberDto != null){
|
|
||||||
// 这个是会员进入现场
|
|
||||||
if (errorDialog != null){
|
|
||||||
if (errorDialog.isShow){
|
|
||||||
errorDialog.dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CrashReport.postCatchedException(new Throwable("接受到命令 " + memberDto.getCode()));
|
|
||||||
|
|
||||||
|
|
||||||
// 监听到头像
|
// 监听到头像
|
||||||
Glide.with(this).load(memberDto.getAvatar()).into(this.avator_imageview);
|
Glide.with(this).load("https://www.baidu.com").into(this.avator_imageview);
|
||||||
String message = memberDto.getMessage();
|
user_name_label.setText("张三");
|
||||||
user_name_label.setText(memberDto.getName());
|
user_phone_label.setText("1234567");
|
||||||
user_phone_label.setText(memberDto.getMobile());
|
user_amount_label.setText("amount");
|
||||||
if (memberDto.getAmount()!= null){
|
unit_price_label.setText("price");
|
||||||
user_amount_label.setText(memberDto.getAmount().toString());
|
welcome_label.setText(String.format("欢迎%s进场", "张三"));
|
||||||
}
|
if (TextUtils.isEmpty(qrCodeEvent.msg)) {
|
||||||
if (memberDto.getPlacePrice() != null){
|
|
||||||
unit_price_label.setText(memberDto.getPlacePrice().toString());
|
|
||||||
}
|
|
||||||
// welcome_label.setText(String.format("欢迎%s进场", memberDto.getName()));
|
|
||||||
welcome_label.setText(message);
|
|
||||||
if (TextUtils.isEmpty(memberDto.getCardName())) {
|
|
||||||
memberInfoLineView.setVisibility(View.GONE);
|
memberInfoLineView.setVisibility(View.GONE);
|
||||||
memberInfopackLayout.setVisibility(View.GONE); // 场地的信息
|
memberInfopackLayout.setVisibility(View.GONE); // 场地的信息
|
||||||
} else {
|
} else {
|
||||||
memberInfoLineView.setVisibility(View.VISIBLE);
|
memberInfoLineView.setVisibility(View.VISIBLE);
|
||||||
memberInfopackLayout.setVisibility(View.VISIBLE);
|
memberInfopackLayout.setVisibility(View.VISIBLE);
|
||||||
this.user_place_label.setText(memberDto.getCardName());
|
this.user_place_label.setText(qrCodeEvent.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memberDto.getCode() == 2){
|
int code = 1; // TODO 这个是获取事件的参数
|
||||||
|
if (code == 2){
|
||||||
// 出场成功
|
// 出场成功
|
||||||
startCountDownTime(user_info_out_ok);
|
startCountDownTime(user_info_out_ok);
|
||||||
}else if (memberDto.getCode() == 1){
|
}else if (code == 1){
|
||||||
// 入场成功
|
// 入场成功
|
||||||
if (memberDto.isFirst()){
|
if ("firstTime".equals(code)){
|
||||||
// 每天的第一次
|
// 每天的第一次
|
||||||
firstEnterHome();
|
firstEnterHome();
|
||||||
}else{
|
}else{
|
||||||
startCountDownTime(user_info_ok);
|
startCountDownTime(user_info_ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
}else if (memberDto.getCode() == 0 ){
|
}else if (code == 0 ){
|
||||||
// 入场失败
|
// 入场失败
|
||||||
startCountDownTime(user_info_fail);
|
startCountDownTime(user_info_fail);
|
||||||
}else if (memberDto.getCode() == -1){
|
}else if (code == -1){
|
||||||
// 余额不足
|
// 余额不足
|
||||||
startCountDownTime(user_info_recahrge);
|
startCountDownTime(user_info_recahrge);
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
// 这个是非会员进入现场
|
|
||||||
this.showStrangerDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,13 +10,9 @@ package com.ydd.sportfaceid.config;
|
|||||||
|
|
||||||
public class GlobalConfig {
|
public class GlobalConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 与服务器通讯状态
|
||||||
|
*/
|
||||||
public static boolean isConnected = false;
|
public static boolean isConnected = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* face++的websocket连接状态
|
|
||||||
*/
|
|
||||||
public static boolean FACE_WS_CONNECTED = false;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.event;
|
|
||||||
|
|
||||||
import com.ydd.sportfaceid.net.dto.MemberDto;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息事件
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 08/12/2017 11:16 PM
|
|
||||||
*/
|
|
||||||
public class FaceidEvent {
|
|
||||||
|
|
||||||
private MemberDto member;
|
|
||||||
|
|
||||||
public FaceidEvent(MemberDto member) {
|
|
||||||
this.member = member;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemberDto getMember() {
|
|
||||||
return member;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMember(MemberDto member) {
|
|
||||||
this.member = member;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDebug;
|
|
||||||
|
|
||||||
public String msg;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.ydd.sportfaceid.event;
|
package com.ydd.sportfaceid.event;
|
||||||
|
|
||||||
import com.ydd.sportfaceid.net.dto.MemberDto;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息事件
|
* 消息事件
|
||||||
*
|
*
|
||||||
|
|||||||
10
app/src/main/java/com/ydd/sportfaceid/event/QRCodeEvent.java
Normal file
10
app/src/main/java/com/ydd/sportfaceid/event/QRCodeEvent.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package com.ydd.sportfaceid.event;
|
||||||
|
/**
|
||||||
|
* 扫码之后通知时间
|
||||||
|
*
|
||||||
|
* @author peakren
|
||||||
|
* @date 08/12/2017 11:16 PM
|
||||||
|
*/
|
||||||
|
public class QRCodeEvent {
|
||||||
|
public String msg;
|
||||||
|
}
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.ydd.sportfaceid.StartApplication;
|
|
||||||
import com.ydd.sportfaceid.config.GlobalConfig;
|
|
||||||
import com.ydd.sportfaceid.session.ClientTcpSession;
|
|
||||||
import com.ydd.sportfaceid.service.MessageService;
|
|
||||||
import com.ydd.sportfaceid.net.dto.HeartBeat;
|
|
||||||
import com.ydd.sportfaceid.net.dto.Message;
|
|
||||||
import com.ydd.sportfaceid.utils.AppUtil;
|
|
||||||
import com.ydd.sportfaceid.utils.DeviceIdUtil;
|
|
||||||
import com.ydd.sportfaceid.utils.JsonMapper;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
||||||
import io.netty.handler.timeout.IdleState;
|
|
||||||
import io.netty.handler.timeout.IdleStateEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通讯服务器请求处理
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 05/12/2017 10:27 PM
|
|
||||||
*/
|
|
||||||
@ChannelHandler.Sharable
|
|
||||||
public class ClientHandler extends ChannelInboundHandlerAdapter {
|
|
||||||
|
|
||||||
private final static String TAG = "ClientHandler";
|
|
||||||
|
|
||||||
private boolean hasRead = false;
|
|
||||||
|
|
||||||
private Activity mContext;
|
|
||||||
|
|
||||||
public ClientHandler(Activity context) {
|
|
||||||
mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
|
||||||
super.channelRegistered(ctx);
|
|
||||||
ClientTcpSession.getInstance().setContext(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
||||||
super.channelActive(ctx);
|
|
||||||
//服务器连上以后立即模拟心跳返回
|
|
||||||
ctx.writeAndFlush(getHbMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
|
||||||
super.channelInactive(ctx);
|
|
||||||
Log.e(TAG, "----close----");
|
|
||||||
GlobalConfig.isConnected =false;
|
|
||||||
ClientThread.getInstance().clearFuture();
|
|
||||||
ClientThread.getInstance().restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
|
||||||
super.channelRead(ctx, msg);
|
|
||||||
Log.i(TAG, "----read data: " + msg.toString() + "----");
|
|
||||||
Message message = JsonMapper.fromJson(msg.toString(), Message.class);
|
|
||||||
MessageService.getInstance().execute(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
|
||||||
super.exceptionCaught(ctx, cause);
|
|
||||||
Log.e(TAG, "----tcp exception----");
|
|
||||||
GlobalConfig.isConnected = false;
|
|
||||||
ctx.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取心跳返回消息
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Message getHbMessage() {
|
|
||||||
HeartBeat hb = new HeartBeat();
|
|
||||||
hb.setVersionCode(AppUtil.getVersionCode(StartApplication.getAppContext()));
|
|
||||||
Message message = new Message();
|
|
||||||
message.setCmdId(Cmd.HB.id);
|
|
||||||
// message.setDeviceId(DeviceIdUtil.generateDeviceId(mContext));
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 心跳处理
|
|
||||||
*
|
|
||||||
* @param ctx
|
|
||||||
* @param evt
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
|
||||||
if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
|
|
||||||
IdleStateEvent event = (IdleStateEvent) evt;
|
|
||||||
if (event.state() == IdleState.ALL_IDLE) {
|
|
||||||
ctx.writeAndFlush(getHbMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息协议指令定义
|
|
||||||
*
|
|
||||||
* @Author peakren
|
|
||||||
* @Date 08/12/2017 11:51 AM
|
|
||||||
*/
|
|
||||||
public enum Cmd {
|
|
||||||
|
|
||||||
|
|
||||||
HB("hb", "心跳"),
|
|
||||||
|
|
||||||
FACEID("faceid", "人脸识别"),
|
|
||||||
|
|
||||||
FACEID_RESPONSE("faceid_response_upload", "识别结果"),
|
|
||||||
|
|
||||||
RECEV_FACE_IMAGE("recev_face_image", "接收人脸照片"),
|
|
||||||
|
|
||||||
RECEV_FACE_IMAGE_R("recev_face_image_r", "返回上传图片结果"),
|
|
||||||
|
|
||||||
OPEN_DOOR("open_door", "开门禁");
|
|
||||||
|
|
||||||
|
|
||||||
public String id;
|
|
||||||
|
|
||||||
public String text;
|
|
||||||
|
|
||||||
Cmd(String id, String text) {
|
|
||||||
this.id = id;
|
|
||||||
this.text = text;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Cmd getCmd(String id) {
|
|
||||||
for (Cmd cmd : Cmd.values()) {
|
|
||||||
if (cmd.id.equalsIgnoreCase(id)) {
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Cmd.HB;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
|
||||||
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义解码器,解决粘包和分包问题
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 07/12/2017 10:03 PM
|
|
||||||
*/
|
|
||||||
public class CustomDecoder extends LengthFieldBasedFrameDecoder {
|
|
||||||
|
|
||||||
public CustomDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength) {
|
|
||||||
super(maxFrameLength, lengthFieldOffset, lengthFieldLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip) {
|
|
||||||
super(maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) {
|
|
||||||
super(maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip, failFast);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomDecoder(ByteOrder byteOrder, int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) {
|
|
||||||
super(byteOrder, maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip, failFast);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
|
||||||
return super.decode(ctx, in);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hehelt on 16/2/26.
|
|
||||||
*/
|
|
||||||
public class DataConfig {
|
|
||||||
|
|
||||||
public static final int MAGIC_WORD = 0x9DDD;
|
|
||||||
public static final int MAGIC_WORD_INDEX = 0;
|
|
||||||
public static final int LENGTH_INDEX = 4;
|
|
||||||
public static final int DATA_INDEX = 8;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 门禁处理
|
|
||||||
* DoorHandler.java
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 2019/4/17 12:44 PM
|
|
||||||
*/
|
|
||||||
public class DoorHandler {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hehelt on 16/2/26.
|
|
||||||
* <p/>
|
|
||||||
* 解码器
|
|
||||||
*/
|
|
||||||
public class MessageDecoder extends ByteToMessageDecoder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
|
||||||
if (in.capacity() >= DataConfig.LENGTH_INDEX) {
|
|
||||||
int magicWord = in.readInt();
|
|
||||||
if (magicWord == DataConfig.MAGIC_WORD) {
|
|
||||||
int length = in.readInt();
|
|
||||||
byte[] msg = new byte[length];
|
|
||||||
in.readBytes(msg);
|
|
||||||
String message = new String(msg, "utf-8");
|
|
||||||
out.add(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析从服务器接受的消息
|
|
||||||
*
|
|
||||||
* @param buf
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getMessage(ByteBuf buf) {
|
|
||||||
|
|
||||||
byte[] con = new byte[buf.readableBytes()];
|
|
||||||
buf.readBytes(con);
|
|
||||||
try {
|
|
||||||
return new String(con, "utf-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.ydd.sportfaceid.net.dto.Message;
|
|
||||||
import com.ydd.sportfaceid.utils.JsonMapper;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义编码器, 1个字节固定头+4个字节长度+内容
|
|
||||||
*/
|
|
||||||
public class MessageEncoder extends MessageToByteEncoder<Message> {
|
|
||||||
|
|
||||||
private String charset = "utf-8";
|
|
||||||
private final static String TAG = "MessageEncoder";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void encode(ChannelHandlerContext ctx, Message message, ByteBuf out) throws Exception {
|
|
||||||
out.writeInt(DataConfig.MAGIC_WORD);
|
|
||||||
String msg = JsonMapper.toJson(message);
|
|
||||||
Log.i(TAG, "send data:" + msg);
|
|
||||||
out.writeInt(msg.getBytes(charset).length);
|
|
||||||
out.writeBytes(msg.getBytes(charset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net.dto;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
|
|
||||||
public class AddFaceResponse {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* code : 0
|
|
||||||
* data : {"company_id":1,"id":4,"origin_url":"/static/upload/origin/2018-08-09/v2_1ea4b7847d1ea56b773aec99441af52dcbf9ca7d.jpg","quality":0.992649,"subject_id":null,"url":"/static/upload/photo/2018-08-09/v2_fa9dcfd045ff5232aa446f5645cbb031eef7ac74.jpg","version":7}
|
|
||||||
* page : {}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private int code;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private DataBean data;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private PageBean page;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private String desc;
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataBean getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(DataBean data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PageBean getPage() {
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPage(PageBean page) {
|
|
||||||
this.page = page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc() {
|
|
||||||
return desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDesc(String desc) {
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DataBean {
|
|
||||||
/**
|
|
||||||
* company_id : 1
|
|
||||||
* id : 4
|
|
||||||
* origin_url : /static/upload/origin/2018-08-09/v2_1ea4b7847d1ea56b773aec99441af52dcbf9ca7d.jpg
|
|
||||||
* quality : 0.992649
|
|
||||||
* subject_id : null
|
|
||||||
* url : /static/upload/photo/2018-08-09/v2_fa9dcfd045ff5232aa446f5645cbb031eef7ac74.jpg
|
|
||||||
* version : 7
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private int company_id;
|
|
||||||
@Expose
|
|
||||||
private int id;
|
|
||||||
@Expose
|
|
||||||
private String origin_url;
|
|
||||||
@Expose
|
|
||||||
private double quality;
|
|
||||||
@Expose
|
|
||||||
private Object subject_id;
|
|
||||||
@Expose
|
|
||||||
private String url;
|
|
||||||
@Expose
|
|
||||||
private int version;
|
|
||||||
|
|
||||||
public int getCompany_id() {
|
|
||||||
return company_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCompany_id(int company_id) {
|
|
||||||
this.company_id = company_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOrigin_url() {
|
|
||||||
return origin_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrigin_url(String origin_url) {
|
|
||||||
this.origin_url = origin_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getQuality() {
|
|
||||||
return quality;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuality(double quality) {
|
|
||||||
this.quality = quality;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSubject_id() {
|
|
||||||
return subject_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubject_id(Object subject_id) {
|
|
||||||
this.subject_id = subject_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(int version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PageBean {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net.dto;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by peakren on 19/01/2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class BaseDto implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3139438146199448677L;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private String cmdId; //指令
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private String deviceId; //设备ID
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端IP
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String clientIp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态码 0正常 1错误
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private int errorCode = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 错误返回信息
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String errorMsg;
|
|
||||||
|
|
||||||
|
|
||||||
public String getCmdId() {
|
|
||||||
return cmdId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCmdId(String cmdId) {
|
|
||||||
this.cmdId = cmdId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(String deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端IP,获取的内网IP
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getClientIp() {
|
|
||||||
return clientIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClientIp(String clientIp) {
|
|
||||||
this.clientIp = clientIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getErrorCode() {
|
|
||||||
return errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorCode(int errorCode) {
|
|
||||||
this.errorCode = errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorMsg() {
|
|
||||||
return errorMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMsg(String errorMsg) {
|
|
||||||
this.errorMsg = errorMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net.dto;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员基本信息
|
|
||||||
* MemberDto.java
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 2018/12/20 8:39 PM
|
|
||||||
*/
|
|
||||||
public class FaceImageDto implements Serializable {
|
|
||||||
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private Integer faceId;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private Integer memberId;
|
|
||||||
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private String faceImage;
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getFaceId() {
|
|
||||||
return faceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFaceId(Integer faceId) {
|
|
||||||
this.faceId = faceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getMemberId() {
|
|
||||||
return memberId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMemberId(Integer memberId) {
|
|
||||||
this.memberId = memberId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFaceImage() {
|
|
||||||
return faceImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFaceImage(String faceImage) {
|
|
||||||
this.faceImage = faceImage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,44 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net.dto;
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端心跳数据包
|
|
||||||
* HeartBeat.java
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 07/12/2017 10:23 PM
|
|
||||||
*/
|
|
||||||
public class HeartBeat implements Serializable {
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private String versionCode; //客户端版本号
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private String apkUrl; //升级的软件下载地址
|
|
||||||
|
|
||||||
|
|
||||||
public String getVersionCode() {
|
|
||||||
return versionCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端版本号
|
|
||||||
*
|
|
||||||
* @param versionCode
|
|
||||||
*/
|
|
||||||
public void setVersionCode(String versionCode) {
|
|
||||||
this.versionCode = versionCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getApkUrl() {
|
|
||||||
return apkUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApkUrl(String apkUrl) {
|
|
||||||
this.apkUrl = apkUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net.dto;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员基本信息
|
|
||||||
* MemberDto.java
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 2018/12/20 8:39 PM
|
|
||||||
*/
|
|
||||||
public class MemberDto implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 头像
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String avatar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 姓名
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手机号码
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String mobile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 余额
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private BigDecimal amount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 场地名称
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String placeName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员卡名称
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String cardName;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1成功进场 0不允许进场
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private int code;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private BigDecimal placePrice;
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private boolean first;
|
|
||||||
|
|
||||||
public BigDecimal getPlacePrice() {
|
|
||||||
return placePrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlacePrice(BigDecimal placePrice) {
|
|
||||||
this.placePrice = placePrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFirst() {
|
|
||||||
return first;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirst(boolean first) {
|
|
||||||
this.first = first;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAvatar() {
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvatar(String avatar) {
|
|
||||||
this.avatar = avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMobile() {
|
|
||||||
return mobile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMobile(String mobile) {
|
|
||||||
this.mobile = mobile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getAmount() {
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAmount(BigDecimal amount) {
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlaceName() {
|
|
||||||
return placeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlaceName(String placeName) {
|
|
||||||
this.placeName = placeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCardName() {
|
|
||||||
return cardName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCardName(String cardName) {
|
|
||||||
this.cardName = cardName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.net.dto;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <pre>上位机与通讯服务器的数据协议格式</pre>
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 07/12/2017 9:57 PM
|
|
||||||
*/
|
|
||||||
public class Message extends BaseDto {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7944124768291562453L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息内容
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private MemberDto result;
|
|
||||||
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private FaceImageDto faceImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 机器识别返回字符串
|
|
||||||
*/
|
|
||||||
@Expose
|
|
||||||
private String content;
|
|
||||||
|
|
||||||
|
|
||||||
public int getDoor() {
|
|
||||||
return door;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDoor(int door) {
|
|
||||||
this.door = door;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Expose
|
|
||||||
private int door;
|
|
||||||
|
|
||||||
|
|
||||||
public MemberDto getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResult(MemberDto result) {
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(String content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FaceImageDto getFaceImage() {
|
|
||||||
return faceImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFaceImage(FaceImageDto faceImage) {
|
|
||||||
this.faceImage = faceImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
120
app/src/main/java/com/ydd/sportfaceid/netty/ClientHandler.java
Normal file
120
app/src/main/java/com/ydd/sportfaceid/netty/ClientHandler.java
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
package com.ydd.sportfaceid.netty;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.ydd.sportfaceid.netty.message.DeviceType;
|
||||||
|
import com.ydd.sportfaceid.netty.message.HeartBeat;
|
||||||
|
import com.ydd.sportfaceid.netty.message.MessageDTO;
|
||||||
|
import com.ydd.sportfaceid.service.MessageService;
|
||||||
|
import com.ydd.sportfaceid.utils.DeviceIdUtil;
|
||||||
|
import com.ydd.sportfaceid.utils.JsonMapper;
|
||||||
|
import io.netty.channel.*;
|
||||||
|
import io.netty.handler.timeout.IdleState;
|
||||||
|
import io.netty.handler.timeout.IdleStateEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通讯服务器请求处理
|
||||||
|
*
|
||||||
|
* @author peakren
|
||||||
|
* @date 05/12/2017 10:27 PM
|
||||||
|
*/
|
||||||
|
@ChannelHandler.Sharable
|
||||||
|
public class ClientHandler extends SimpleChannelInboundHandler<String> {
|
||||||
|
|
||||||
|
private final static String TAG = "ClientHandler";
|
||||||
|
private Activity mContext;
|
||||||
|
|
||||||
|
public ClientHandler(Activity context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当通道就绪就会触发
|
||||||
|
* @param ctx
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
super.channelActive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当通道失效就会触发
|
||||||
|
* @param ctx
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
super.channelInactive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当通道有读取事件时触发
|
||||||
|
* @param ctx
|
||||||
|
* @param msg
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||||
|
Log.d(TAG,"接收服务器响应msg:[" + msg + "]");
|
||||||
|
// 安卓写,非netty 后台实现
|
||||||
|
// TODO 安卓获取心跳内容(有二维码的唯一识别)显示请求小程序的venueId的二维码,无需拼接url
|
||||||
|
// TODO 安卓获取通知加载页面
|
||||||
|
// TODO 安卓获取通知开门失败消息 (进入一个页面,然后显示倒计时,回到主页(二维码页面))
|
||||||
|
// TODO 安卓获取通知开门的消息 (无需校验,直接操作开门)
|
||||||
|
MessageDTO message = JsonMapper.fromJson(msg, MessageDTO.class);
|
||||||
|
switch (message.getMessageType()){
|
||||||
|
case LOAD:
|
||||||
|
System.out.println("LOADING" + message.getMessage());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("default");
|
||||||
|
}
|
||||||
|
MessageService.getInstance().execute(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 心跳
|
||||||
|
* @param ctx
|
||||||
|
* @param evt
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||||
|
if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
|
||||||
|
IdleStateEvent event = (IdleStateEvent) evt;
|
||||||
|
if (event.state() == IdleState.ALL_IDLE) {
|
||||||
|
ctx.writeAndFlush(getHbMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装心跳请求包
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private HeartBeat getHbMessage() {
|
||||||
|
HeartBeat hb = new HeartBeat();
|
||||||
|
hb.setDeviceName(DeviceIdUtil.generateDeviceId(mContext));
|
||||||
|
hb.setVenueId(mContext.getTaskId()); // TODO 从上下文选择场馆
|
||||||
|
hb.setEnterOrOut(DeviceType.ENTER); // TODO 上下文获取场馆进场或者出场
|
||||||
|
return hb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理异常
|
||||||
|
* @param ctx
|
||||||
|
* @param cause
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||||
|
Log.d(TAG,"ClientHandler exceptionCaught",cause);
|
||||||
|
Channel channel = ctx.channel();
|
||||||
|
if(channel.isActive()) {
|
||||||
|
ctx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,27 +1,22 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
package com.ydd.sportfaceid.netty;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
|
import com.ydd.sportfaceid.netty.config.Constant;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
|
||||||
|
import io.netty.handler.codec.string.StringDecoder;
|
||||||
import io.netty.handler.timeout.IdleStateHandler;
|
import io.netty.handler.timeout.IdleStateHandler;
|
||||||
|
|
||||||
|
|
||||||
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
|
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
private final static int TIME_HEART_BEAT = 20;
|
private final static int TIME_HEART_BEAT = 20;
|
||||||
|
|
||||||
public ClientThread.ReConnectHandler reConnectHandler;
|
public ClientThread.ReConnectHandler reConnectHandler;
|
||||||
public ClientHandler dmClientHandler;
|
public ClientHandler dmClientHandler;
|
||||||
|
|
||||||
public ClientInitializer(ClientThread.ReConnectHandler handler) {
|
|
||||||
reConnectHandler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClientInitializer(ClientThread.ReConnectHandler handler, ClientHandler dmClientHandler) {
|
public ClientInitializer(ClientThread.ReConnectHandler handler, ClientHandler dmClientHandler) {
|
||||||
reConnectHandler = handler;
|
reConnectHandler = handler;
|
||||||
this.dmClientHandler = dmClientHandler;
|
this.dmClientHandler = dmClientHandler;
|
||||||
@@ -32,10 +27,11 @@ public class ClientInitializer extends ChannelInitializer<SocketChannel> {
|
|||||||
protected void initChannel(SocketChannel ch) throws Exception {
|
protected void initChannel(SocketChannel ch) throws Exception {
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
ChannelPipeline pipeline = ch.pipeline();
|
||||||
pipeline.addLast("reconnect", reConnectHandler);
|
pipeline.addLast("reconnect", reConnectHandler);
|
||||||
pipeline.addLast("idleStateHandler", new IdleStateHandler(TIME_HEART_BEAT, TIME_HEART_BEAT, TIME_HEART_BEAT));
|
pipeline.addLast(new DelimiterBasedFrameDecoder(2048,
|
||||||
|
Unpooled.wrappedBuffer(Constant.DELIMITER_WORD.getBytes())));
|
||||||
|
pipeline.addLast(new StringDecoder());
|
||||||
pipeline.addLast(new MessageEncoder());
|
pipeline.addLast(new MessageEncoder());
|
||||||
pipeline.addFirst(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 4, 4, 0, 0));
|
pipeline.addLast(new IdleStateHandler(TIME_HEART_BEAT, TIME_HEART_BEAT,TIME_HEART_BEAT));
|
||||||
pipeline.addLast(new MessageDecoder());
|
|
||||||
pipeline.addLast(dmClientHandler);
|
pipeline.addLast(dmClientHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.ydd.sportfaceid.net;
|
package com.ydd.sportfaceid.netty;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Handler;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.ydd.sportfaceid.BuildConfig;
|
import com.ydd.sportfaceid.BuildConfig;
|
||||||
@@ -94,22 +93,12 @@ public class ClientThread {
|
|||||||
}
|
}
|
||||||
remoteHost = SharedPreferencesUtil.getServerIp();
|
remoteHost = SharedPreferencesUtil.getServerIp();
|
||||||
remotePort = SharedPreferencesUtil.getServerPort();
|
remotePort = SharedPreferencesUtil.getServerPort();
|
||||||
|
|
||||||
// if (future != null){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// future = null;
|
|
||||||
if (GlobalConfig.isConnected){
|
if (GlobalConfig.isConnected){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("sander", "连接 = " + remoteHost + " " + remotePort);
|
Log.d("sander", "连接 = " + remoteHost + " " + remotePort);
|
||||||
future = bootstrap.connect(new InetSocketAddress(remoteHost, remotePort));
|
future = bootstrap.connect(new InetSocketAddress(remoteHost, remotePort));
|
||||||
future.addListener(new ChannelFutureListener() {
|
future.addListener((ChannelFutureListener) f -> f.channel().eventLoop().schedule(() -> {
|
||||||
public void operationComplete(ChannelFuture f) throws Exception {
|
|
||||||
f.channel().eventLoop().schedule(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!f.isSuccess()) {
|
if (!f.isSuccess()) {
|
||||||
if (GlobalConfig.isConnected) {
|
if (GlobalConfig.isConnected) {
|
||||||
GlobalConfig.isConnected = false;
|
GlobalConfig.isConnected = false;
|
||||||
@@ -122,12 +111,7 @@ public class ClientThread {
|
|||||||
Log.i(TAG, "连接成功!");
|
Log.i(TAG, "连接成功!");
|
||||||
GlobalConfig.isConnected = true;
|
GlobalConfig.isConnected = true;
|
||||||
}
|
}
|
||||||
}
|
}, 2, TimeUnit.SECONDS));
|
||||||
}, 2, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,18 +135,11 @@ public class ClientThread {
|
|||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class ReConnectHandler extends ChannelInboundHandlerAdapter {
|
public class ReConnectHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
super.channelInactive(ctx);
|
super.channelInactive(ctx);
|
||||||
System.out.println("inactive");
|
System.out.println("inactive");
|
||||||
ctx.channel().eventLoop().schedule(new Runnable() {
|
ctx.channel().eventLoop().schedule(() -> doConnect(), 1, TimeUnit.SECONDS);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
doConnect();
|
|
||||||
}
|
|
||||||
}, 1, TimeUnit.SECONDS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ydd.sportfaceid.netty;
|
||||||
|
|
||||||
|
import com.ydd.sportfaceid.netty.config.Constant;
|
||||||
|
import com.ydd.sportfaceid.utils.JsonMapper;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义编码器, 1个字节固定头+4个字节长度+内容
|
||||||
|
*/
|
||||||
|
public class MessageEncoder extends MessageToByteEncoder {
|
||||||
|
|
||||||
|
Charset charset = Charset.forName("UTF-8");
|
||||||
|
/**
|
||||||
|
* 安卓打印日志,本地不需要
|
||||||
|
*/
|
||||||
|
private final static String TAG = "MessageEncoder";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
|
||||||
|
String message = JsonMapper.toJson(msg);
|
||||||
|
message = message + Constant.DELIMITER_WORD;
|
||||||
|
byte[] content = message.getBytes(charset.name());
|
||||||
|
out.writeBytes(content); //发送消息内容
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ydd.sportfaceid.netty.config;
|
||||||
|
|
||||||
|
public class Constant {
|
||||||
|
|
||||||
|
public final static String DELIMITER_WORD = "$_$";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.ydd.sportfaceid.netty.message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备属性,控制入场还是控制出场
|
||||||
|
*/
|
||||||
|
public enum DeviceType {
|
||||||
|
|
||||||
|
ENTER(0,"进场"),
|
||||||
|
OUT(1,"出场");
|
||||||
|
private int code;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
DeviceType(int code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.ydd.sportfaceid.netty.message;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端心跳数据包
|
||||||
|
* HeartBeat.java
|
||||||
|
*
|
||||||
|
* @author peakren
|
||||||
|
* @date 07/12/2017 10:23 PM
|
||||||
|
*/
|
||||||
|
public class HeartBeat implements Serializable {
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private Integer venueId; //场馆号
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private String deviceName; //设备号
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private DeviceType EnterOrOut; //出入标志
|
||||||
|
|
||||||
|
public Integer getVenueId() {
|
||||||
|
return venueId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVenueId(Integer venueId) {
|
||||||
|
this.venueId = venueId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceName() {
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceName(String deviceName) {
|
||||||
|
this.deviceName = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceType getEnterOrOut() {
|
||||||
|
return EnterOrOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnterOrOut(DeviceType enterOrOut) {
|
||||||
|
EnterOrOut = enterOrOut;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ydd.sportfaceid.netty.message;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class MessageDTO implements Serializable {
|
||||||
|
|
||||||
|
private MessageType messageType;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public MessageDTO(MessageType messageType, String message) {
|
||||||
|
this.messageType = messageType;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageType getMessageType() {
|
||||||
|
return messageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageType(MessageType messageType) {
|
||||||
|
this.messageType = messageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.ydd.sportfaceid.netty.message;
|
||||||
|
|
||||||
|
public enum MessageType {
|
||||||
|
LOAD("加载"),
|
||||||
|
OPENDOOR("开门"),
|
||||||
|
FAILED("开门校验失败");
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
MessageType(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,11 @@
|
|||||||
package com.ydd.sportfaceid.service;
|
package com.ydd.sportfaceid.service;
|
||||||
|
|
||||||
import android.app.IntentService;
|
import android.app.IntentService;
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.ydd.sportfaceid.StartApplication;
|
import com.ydd.sportfaceid.StartApplication;
|
||||||
import com.ydd.sportfaceid.net.ClientThread;
|
import com.ydd.sportfaceid.netty.ClientThread;
|
||||||
import com.ydd.sportfaceid.websocket.FaceWsClient;
|
|
||||||
import com.ydd.sportfaceid.websocket.FaceWsClientService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动socker和websocket服务
|
* 启动socker和websocket服务
|
||||||
@@ -21,46 +16,19 @@ import com.ydd.sportfaceid.websocket.FaceWsClientService;
|
|||||||
public class ClientService extends IntentService {
|
public class ClientService extends IntentService {
|
||||||
|
|
||||||
public ClientService() {
|
public ClientService() {
|
||||||
super("new cocket");
|
super("new socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
//启动服务器socket连接
|
|
||||||
|
|
||||||
Log.d("sander", "clientThread run");
|
Log.d("sander", "clientThread run");
|
||||||
StartApplication.executor.execute(new Runnable() {
|
StartApplication.executor.execute(() -> ClientThread.getInstance().run());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ClientThread.getInstance().run();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public int onStartCommand(Intent intent, int flags, int startId) {
|
|
||||||
// return super.onStartCommand(intent, flags, startId);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onDestroy() {
|
|
||||||
// super.onDestroy();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public IBinder onBind(Intent intent) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
/**
|
|
||||||
* 启动face++ websocket连接
|
|
||||||
*/
|
|
||||||
FaceWsClientService.getInstance().start();
|
|
||||||
|
|
||||||
Log.d("sander","这里在重复启动hanglde intent service");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,28 +2,12 @@ package com.ydd.sportfaceid.service;
|
|||||||
|
|
||||||
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.ydd.sportfaceid.BuildConfig;
|
import com.ydd.sportfaceid.BuildConfig;
|
||||||
import com.ydd.sportfaceid.StartApplication;
|
import com.ydd.sportfaceid.netty.message.MessageDTO;
|
||||||
import com.ydd.sportfaceid.event.FaceidEvent;
|
|
||||||
import com.ydd.sportfaceid.net.Cmd;
|
|
||||||
import com.ydd.sportfaceid.net.dto.AddFaceResponse;
|
|
||||||
import com.ydd.sportfaceid.net.dto.FaceImageDto;
|
|
||||||
import com.ydd.sportfaceid.net.dto.Message;
|
|
||||||
import com.ydd.sportfaceid.session.ClientTcpSession;
|
|
||||||
import com.ydd.sportfaceid.utils.AppLogger;
|
import com.ydd.sportfaceid.utils.AppLogger;
|
||||||
import com.ydd.sportfaceid.utils.DeviceIdUtil;
|
|
||||||
import com.ydd.sportfaceid.utils.JsonMapper;
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
|
||||||
|
|
||||||
import java.io.Console;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import Net.PC15.Command.CommandDetial;
|
import Net.PC15.Command.CommandDetial;
|
||||||
import Net.PC15.Connector.ConnectorAllocator;
|
import Net.PC15.Connector.ConnectorAllocator;
|
||||||
import Net.PC15.Connector.E_ControllerType;
|
import Net.PC15.Connector.E_ControllerType;
|
||||||
@@ -55,7 +39,7 @@ public class MessageService {
|
|||||||
|
|
||||||
static public MessageService getInstance() {
|
static public MessageService getInstance() {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
synchronized (ClientTcpSession.class) {
|
synchronized (MessageService.class) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new MessageService();
|
sInstance = new MessageService();
|
||||||
}
|
}
|
||||||
@@ -69,55 +53,55 @@ public class MessageService {
|
|||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
public void execute(Message message) {
|
public void execute(MessageDTO message) {
|
||||||
if (null == message) {
|
// if (null == message) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
Cmd cmd = Cmd.getCmd(message.getCmdId());
|
// Cmd cmd = Cmd.getCmd(message.getCmdId());
|
||||||
switch (cmd) {
|
// switch (cmd) {
|
||||||
case HB:
|
// case HB:
|
||||||
break;
|
// break;
|
||||||
case FACEID:
|
// case FACEID:
|
||||||
EventBus.getDefault().post(new FaceidEvent(message.getResult()));
|
// EventBus.getDefault().post(new FaceidEvent(message.getResult()));
|
||||||
break;
|
// break;
|
||||||
//识别结果返回
|
// //识别结果返回
|
||||||
case OPEN_DOOR:
|
// case OPEN_DOOR:
|
||||||
AppLogger.getInstance().writeLog("----receive open door cmd----");
|
// AppLogger.getInstance().writeLog("----receive open door cmd----");
|
||||||
StartApplication.executor.execute(new Runnable() {
|
// StartApplication.executor.execute(new Runnable() {
|
||||||
@Override
|
// @Override
|
||||||
public void run() {
|
// public void run() {
|
||||||
openDoor(message.getDoor());
|
// openDoor(message.getDoor());
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
break;
|
// break;
|
||||||
|
//
|
||||||
//接收人脸照片
|
// //接收人脸照片
|
||||||
case RECEV_FACE_IMAGE:
|
// case RECEV_FACE_IMAGE:
|
||||||
//获取图片内容
|
// //获取图片内容
|
||||||
String imageBase64 = message.getContent();
|
// String imageBase64 = message.getContent();
|
||||||
StartApplication.executor.execute(new Runnable() {
|
// StartApplication.executor.execute(new Runnable() {
|
||||||
@Override
|
// @Override
|
||||||
public void run() {
|
// public void run() {
|
||||||
try {
|
// try {
|
||||||
Integer faceId = uploadFace(imageBase64);
|
// Integer faceId = uploadFace(imageBase64);
|
||||||
Message sendMsg = new Message();
|
// Message sendMsg = new Message();
|
||||||
sendMsg.setCmdId(Cmd.RECEV_FACE_IMAGE_R.id);
|
// sendMsg.setCmdId(Cmd.RECEV_FACE_IMAGE_R.id);
|
||||||
sendMsg.setDeviceId(DeviceIdUtil.generateDeviceId(StartApplication.getAppContext()));
|
// sendMsg.setDeviceId(DeviceIdUtil.generateDeviceId(StartApplication.getAppContext()));
|
||||||
FaceImageDto faceImage = new FaceImageDto();
|
// FaceImageDto faceImage = new FaceImageDto();
|
||||||
faceImage.setFaceId(faceId);
|
// faceImage.setFaceId(faceId);
|
||||||
if (sendMsg.getFaceImage() != null) {
|
// if (sendMsg.getFaceImage() != null) {
|
||||||
faceImage.setMemberId(sendMsg.getFaceImage().getMemberId());
|
// faceImage.setMemberId(sendMsg.getFaceImage().getMemberId());
|
||||||
}
|
// }
|
||||||
sendMsg.setFaceImage(faceImage);
|
// sendMsg.setFaceImage(faceImage);
|
||||||
//返回上传结果
|
// //返回上传结果
|
||||||
ClientTcpSession.getInstance().send(sendMsg);
|
// ClientTcpSession.getInstance().send(sendMsg);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
Log.e(TAG, "upload face image error...");
|
// Log.e(TAG, "upload face image error...");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,10 +155,10 @@ public class MessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResponseBody responseBody = response.body();
|
ResponseBody responseBody = response.body();
|
||||||
AddFaceResponse faceResponse = JsonMapper.fromJson(responseBody.string(), AddFaceResponse.class);
|
// AddFaceResponse faceResponse = JsonMapper.fromJson(responseBody.string(), AddFaceResponse.class);
|
||||||
if (faceResponse.getCode() == 0) {
|
// if (faceResponse.getCode() == 0) {
|
||||||
return faceResponse.getData().getId();
|
// return faceResponse.getData().getId();
|
||||||
}
|
// }
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.session;
|
|
||||||
|
|
||||||
|
|
||||||
import com.ydd.sportfaceid.net.dto.Message;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通讯服务器session持久化
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 07/12/2017 10:42 PM
|
|
||||||
*/
|
|
||||||
public class ClientTcpSession {
|
|
||||||
|
|
||||||
private static ChannelHandlerContext context;
|
|
||||||
|
|
||||||
static private ClientTcpSession sInstance;
|
|
||||||
|
|
||||||
static public ClientTcpSession getInstance() {
|
|
||||||
if (sInstance == null) {
|
|
||||||
synchronized (ClientTcpSession.class) {
|
|
||||||
if (sInstance == null) {
|
|
||||||
sInstance = new ClientTcpSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChannelHandlerContext getContext() {
|
|
||||||
return this.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContext(ChannelHandlerContext context) {
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void send(Message message) {
|
|
||||||
if (context != null) {
|
|
||||||
context.writeAndFlush(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
if (context != null) {
|
|
||||||
context.close();
|
|
||||||
context = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.websocket;
|
|
||||||
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.tencent.bugly.crashreport.CrashReport;
|
|
||||||
import com.ydd.sportfaceid.StartApplication;
|
|
||||||
import com.ydd.sportfaceid.config.SDAppConfig;
|
|
||||||
import com.ydd.sportfaceid.event.FaceidEvent;
|
|
||||||
import com.ydd.sportfaceid.net.Cmd;
|
|
||||||
import com.ydd.sportfaceid.net.dto.FaceRecognizeResponse;
|
|
||||||
import com.ydd.sportfaceid.net.dto.Message;
|
|
||||||
import com.ydd.sportfaceid.session.ClientTcpSession;
|
|
||||||
import com.ydd.sportfaceid.utils.DeviceIdUtil;
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
|
||||||
import org.java_websocket.client.WebSocketClient;
|
|
||||||
import org.java_websocket.drafts.Draft;
|
|
||||||
import org.java_websocket.handshake.ServerHandshake;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* face++ WS连接客户端
|
|
||||||
* FaceWsClient.java
|
|
||||||
*
|
|
||||||
* @author peakren
|
|
||||||
* @date 2019/4/15 12:51 PM
|
|
||||||
*/
|
|
||||||
public class FaceWsClient extends WebSocketClient {
|
|
||||||
|
|
||||||
private final static String TAG = "FaceWsClient";
|
|
||||||
private Gson gson = new Gson();
|
|
||||||
|
|
||||||
public FaceWsClient(URI serverUri, Draft draft) {
|
|
||||||
super(serverUri, draft);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FaceWsClient(URI serverURI) {
|
|
||||||
super(serverURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FaceWsClient(URI serverUri, Map<String, String> httpHeaders) {
|
|
||||||
super(serverUri, httpHeaders);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOpen(ServerHandshake handshakedata) {
|
|
||||||
Log.i(TAG, "opened connection");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(String message) {
|
|
||||||
Log.i(TAG, "received: " + message);
|
|
||||||
|
|
||||||
FaceRecognizeResponse faceRecognizeResponse = gson.fromJson(message, FaceRecognizeResponse.class);
|
|
||||||
if (faceRecognizeResponse.getType().equals("unrecognized")){
|
|
||||||
Log.d("sander", "这是个陌生人,");
|
|
||||||
FaceidEvent faceidEvent = new FaceidEvent(null);
|
|
||||||
EventBus.getDefault().post(faceidEvent);
|
|
||||||
}else {
|
|
||||||
Message sendMsg = new Message();
|
|
||||||
sendMsg.setContent(message);
|
|
||||||
sendMsg.setCmdId(Cmd.FACEID_RESPONSE.id);
|
|
||||||
// 这里改成1和2,1是1号摄像头,2是2号摄像头
|
|
||||||
int current_camera_index = SDAppConfig.getInstance().getCurrent_selected_camera();
|
|
||||||
String device_ID = current_camera_index == 0 ? "1" : "2";
|
|
||||||
CrashReport.postCatchedException(new Throwable("device_ID = " + device_ID + " message = " + message));
|
|
||||||
sendMsg.setDeviceId(device_ID);
|
|
||||||
ClientTcpSession.getInstance().send(sendMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FaceidEvent debugFace = new FaceidEvent(null);
|
|
||||||
// debugFace.isDebug = true;
|
|
||||||
// debugFace.msg = message;
|
|
||||||
// EventBus.getDefault().post(debugFace);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClose(int code, String reason, boolean remote) {
|
|
||||||
Log.e(TAG, "Connection closed by " + (remote ? "remote peer" : "us") + " Code: " + code + " Reason: " + reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.ydd.sportfaceid.websocket;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.ydd.sportfaceid.BuildConfig;
|
|
||||||
import com.ydd.sportfaceid.StartApplication;
|
|
||||||
import com.ydd.sportfaceid.config.SDAppConfig;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class FaceWsClientService {
|
|
||||||
|
|
||||||
private final static String TAG = "FaceWsClientService";
|
|
||||||
|
|
||||||
private static FaceWsClientService instance;
|
|
||||||
|
|
||||||
private String local_camer_service ;
|
|
||||||
FaceWsClient c = null;
|
|
||||||
public static FaceWsClientService getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
synchronized (FaceWsClientService.class) {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new FaceWsClientService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
String rtspUrl = SDAppConfig.getInstance().getCurrentCameraUrl();
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(local_camer_service)){
|
|
||||||
if (local_camer_service.equals(rtspUrl)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
StartApplication.executor.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
if (c != null){
|
|
||||||
c.closeBlocking();
|
|
||||||
c = null;
|
|
||||||
}
|
|
||||||
local_camer_service = rtspUrl;
|
|
||||||
// String rtspUrl = "rtsp://192.168.1.161/user=admin&password=&channel=1&stream=0.sdp?";
|
|
||||||
c = new FaceWsClient(new URI(BuildConfig.FACEID_WS_URL + URLEncoder.encode(rtspUrl, "UTF-8")));
|
|
||||||
c.connectBlocking(5000, TimeUnit.MILLISECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ buildscript {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
|
maven{ url 'https://maven.aliyun.com/repository/public'}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||||
|
|||||||
Reference in New Issue
Block a user