|
|
|
|
|
package com.rehome.dywoa;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
|
|
|
|
|
|
|
|
import com.rehome.dywoa.ui.activity.BiShowActivity;
|
|
|
|
|
|
import com.rehome.dywoa.utils.SPUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
|
|
|
import cn.hutool.core.util.HexUtil;
|
|
|
|
|
|
import cn.hutool.crypto.SmUtil;
|
|
|
|
|
|
import cn.hutool.crypto.symmetric.SM4;
|
|
|
|
|
|
|
|
|
|
|
|
public class MyObject {
|
|
|
|
|
|
private Context context;
|
|
|
|
|
|
private String data;
|
|
|
|
|
|
private String time;
|
|
|
|
|
|
private String nfc;
|
|
|
|
|
|
|
|
|
|
|
|
public void setNfc(String nfc) {
|
|
|
|
|
|
this.nfc = nfc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取Base64人脸图片数据
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getBase64StringImg() {
|
|
|
|
|
|
return base64StringImg;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setBase64StringImg(String base64StringImg) {
|
|
|
|
|
|
this.base64StringImg = base64StringImg;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取二维码数据
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getQRCodeStr() {
|
|
|
|
|
|
return qrCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取nfc数据
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getNfcStr() {
|
|
|
|
|
|
return nfc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setQRCodeStr(String qrCode) {
|
|
|
|
|
|
this.qrCode = qrCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//人脸识别图片
|
|
|
|
|
|
private String base64StringImg;
|
|
|
|
|
|
//二维码
|
|
|
|
|
|
private String qrCode;
|
|
|
|
|
|
public MyObject(Context c,String data,String time){
|
|
|
|
|
|
this.data = data;
|
|
|
|
|
|
this.time = time;
|
|
|
|
|
|
this.context = c;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取心电数据
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getData(){
|
|
|
|
|
|
String[] dd = new String[0];
|
|
|
|
|
|
try {
|
|
|
|
|
|
dd = data.substring(data.indexOf("Ъ")+2, data.length()-1).split(",");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
return Arrays.toString(dd).toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void showLog(String logText) {
|
|
|
|
|
|
if (isApkInDebug(context)) {
|
|
|
|
|
|
if(TextUtils.isEmpty(logText)){
|
|
|
|
|
|
Log.i("app", "logText is null");
|
|
|
|
|
|
}else{
|
|
|
|
|
|
Log.i("app", logText);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 判断当前应用是否是debug状态
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean isApkInDebug(Context context) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
ApplicationInfo info = context.getApplicationInfo();
|
|
|
|
|
|
return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取测量时间
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getTime(){
|
|
|
|
|
|
return time;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String commandOperation(String command){
|
|
|
|
|
|
// Log.i("app",command);
|
|
|
|
|
|
//writeNfc
|
|
|
|
|
|
//刷新计划下载界面
|
|
|
|
|
|
Intent intent = new Intent(Contans.ACTION_RECEIVENFC);
|
|
|
|
|
|
intent.putExtra("nfc",command);
|
|
|
|
|
|
//发送本地广播写入nfc
|
|
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
|
|
|
|
|
|
|
|
|
|
|
return "success";
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 人脸识别
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String startFaceRecognition(){
|
|
|
|
|
|
showLog("startFaceRecognition");
|
|
|
|
|
|
//发送本地广播,调起人脸识别
|
|
|
|
|
|
Intent intent = new Intent(Contans.STARTFACERECOGNITION);
|
|
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
|
|
|
|
|
return "success";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存数据到APP内部存储
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String saveDataToSharedPreferences(String key,String value){
|
|
|
|
|
|
showLog("saveDataToSharedPreferences");
|
|
|
|
|
|
SPUtils.put(context, key, value);
|
|
|
|
|
|
return "success";
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 从APP内部获取保存的任何数据
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public Object getDataFromSharedPreferences(String key,Object defaultObject){
|
|
|
|
|
|
showLog("getDataFromSharedPreferences");
|
|
|
|
|
|
if(key==null){
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
return SPUtils.get(context, key, defaultObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 从APP内部获取保存的字符串数据
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getStringDataFromSharedPreferences(String key){
|
|
|
|
|
|
showLog("getStringDataFromSharedPreferences");
|
|
|
|
|
|
if(key==null){
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
String result = (String) SPUtils.get(context, key, "");
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 关闭两票当前页面,返回上一级入口
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String closeCurrentActivity(){
|
|
|
|
|
|
showLog("closeCurrentActivity");
|
|
|
|
|
|
//发送本地广播,调起人脸识别
|
|
|
|
|
|
Intent intent = new Intent(Contans.CLOSECURRENTACTIVITY);
|
|
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
|
|
|
|
|
return "success";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 国密四加密,传入要加密的字符串
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getGuoMi4EncryptStr(String valueStr){
|
|
|
|
|
|
showLog("getGuoMi4EncryptStr");
|
|
|
|
|
|
if(TextUtils.isEmpty(valueStr)){
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
String key = "63727578e5a4a9e4b88be697a0e6958c";
|
|
|
|
|
|
SM4 sm4 = SmUtil.sm4(HexUtil.decodeHex(key));
|
|
|
|
|
|
//加密
|
|
|
|
|
|
String encryptStr = sm4.encryptHex(valueStr, CharsetUtil.CHARSET_UTF_8);
|
|
|
|
|
|
return encryptStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 国密四解密,传入要解密的字符串
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getGuoMi4DecryptStr(String encryptStr){
|
|
|
|
|
|
showLog("closeCurrentActivity");
|
|
|
|
|
|
if(TextUtils.isEmpty(encryptStr)){
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
String key = "63727578e5a4a9e4b88be697a0e6958c";
|
|
|
|
|
|
SM4 sm4 = SmUtil.sm4(HexUtil.decodeHex(key));
|
|
|
|
|
|
//解密
|
|
|
|
|
|
String decryptStr = sm4.decryptStr(encryptStr, CharsetUtil.CHARSET_UTF_8);
|
|
|
|
|
|
return decryptStr;
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
return "解密失败";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取国密四加密后的APP登录帐号
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getGuoMi4EncryptAccountStr(){
|
|
|
|
|
|
showLog("getGuoMi4EncryptAccountStr");
|
|
|
|
|
|
|
|
|
|
|
|
String key = "63727578e5a4a9e4b88be697a0e6958c";
|
|
|
|
|
|
SM4 sm4 = SmUtil.sm4(HexUtil.decodeHex(key));
|
|
|
|
|
|
|
|
|
|
|
|
//加密
|
|
|
|
|
|
String encryptStr = sm4.encryptHex(App.getInstance().getUserInfo().getManid(), CharsetUtil.CHARSET_UTF_8);
|
|
|
|
|
|
return encryptStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取国密四加密后的APP登录帐号+时间戳
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getGuoMi4EncryptAccountTimeStr(){
|
|
|
|
|
|
showLog("getGuoMi4EncryptAccountStr");
|
|
|
|
|
|
|
|
|
|
|
|
String key = "63727578e5a4a9e4b88be697a0e6958c";
|
|
|
|
|
|
SM4 sm4 = SmUtil.sm4(HexUtil.decodeHex(key));
|
|
|
|
|
|
|
|
|
|
|
|
String account = App.getInstance().getUserInfo().getManid() + "|" + System.currentTimeMillis();
|
|
|
|
|
|
//加密
|
|
|
|
|
|
String encryptStr = sm4.encryptHex(account, CharsetUtil.CHARSET_UTF_8);
|
|
|
|
|
|
return encryptStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取未加密的APP登录帐号
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String getBaseAccountStr(){
|
|
|
|
|
|
showLog("getBaseAccountStr");
|
|
|
|
|
|
return App.getInstance().getUserInfo().getManid();
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* URL编码
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String urlEncoding(String encodiString){
|
|
|
|
|
|
showLog("urlEncoding");
|
|
|
|
|
|
try {
|
|
|
|
|
|
//URLEncoder的编码
|
|
|
|
|
|
String encode = URLEncoder.encode(encodiString, "UTF-8");//第二个参数一定要是服务器段支持的格式
|
|
|
|
|
|
showLog(encode);
|
|
|
|
|
|
return encode;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* URL解码
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String urlDecoder(String decoderString){
|
|
|
|
|
|
showLog("urlDecoder");
|
|
|
|
|
|
try {
|
|
|
|
|
|
//URLDecoder的解码:
|
|
|
|
|
|
String baseString = URLDecoder.decode(decoderString,"UTF-8");
|
|
|
|
|
|
showLog(baseString);
|
|
|
|
|
|
return baseString;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 触发二给码扫描
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public String openQrScanActivity(){
|
|
|
|
|
|
showLog("openQrScanActivity");
|
|
|
|
|
|
//发送本地广播,调起二给码扫描
|
|
|
|
|
|
Intent intent = new Intent(Contans.OPENQRCODESCAN);
|
|
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
|
|
|
|
|
return "success";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|