master
hwf452 2 years ago
parent 3c52032e62
commit a47272d399

@ -15,8 +15,25 @@ android {
resValue "string", "authorities", applicationId
resourceConfigurations += ['zh', 'en', 'hdpi']
}
buildFeatures {
buildConfig = true
}
signingConfigs {
release {
keyAlias 'key0'
storeFile file('../key/keystore1')
storePassword 'abc123123'
keyPassword 'abc123123'
v1SigningEnabled true //V1
v2SigningEnabled true //V2
}
}
/* keypassword:abc123123 alias key0*/
buildTypes {
debug {
minifyEnabled false
buildConfigField "boolean", "LOG_ERROR", "true"
}
release {
lintOptions {
checkReleaseBuilds false
@ -26,6 +43,8 @@ android {
zipAlignEnabled true // zip
debuggable false // debug
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "LOG_ERROR", "false"
signingConfig signingConfigs.release //
}
}
sourceSets {
@ -34,8 +53,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
namespace 'com.bjzc.yfdxj'
}

@ -187,8 +187,8 @@ public class LoginActivity extends BaseActivity {
}
}
// etUse.setText("161619");
// etPwd.setText("lgy12345");
etUse.setText("161619");
etPwd.setText("lgy12345");
//使用完一定记得关闭电源
mt.RFIDclose();
@ -350,67 +350,76 @@ public class LoginActivity extends BaseActivity {
@Override
public void onSucceed(int what, Response<String> response) throws ParseException {
String json = response.get();
// Log.i("app", "-----login-----");
// Log.i("app", json);
showLog("-----login-----");
showLog(json);
UserInfo userInfo = GsonUtils.GsonToBean(json, UserInfo.class);
//Log.i("app", new Gson().toJson(userInfo));
if (userInfo != null) {
UserInfo.User user = userInfo.getRows().get(0);
String status = user.getStatus();
String username = user.getUsernames();
switch (status) {
case "0":
showToast("用户名或密码错误");
break;
case "1":
SPUtils.put(LoginActivity.this, "save", savePwUser.isChecked());
SPUtils.put(LoginActivity.this, Contans.USERID, RSAUtils.encryptBASE64StrLocal(etUse.getText().toString()));
SPUtils.put(LoginActivity.this, Contans.USERPWD, RSAUtils.encryptBASE64StrLocal(etPwd.getText().toString()));
SPUtils.put(LoginActivity.this, Contans.USERNAME, username);
SPUtils.put(LoginActivity.this, Contans.BZBH, user.getBzbh() == null ? "" : user.getBzbh());
SPUtils.put(LoginActivity.this, Contans.BZMC, user.getBzmc() == null ? "" : user.getBzmc());
SPUtils.put(LoginActivity.this, Contans.PERMISSIONSRESULT, user.getPermissionsResult() == null ? "" : user.getPermissionsResult());
SPUtils.put(LoginActivity.this, Contans.ZY, user.getZY() == null ? "" : user.getZY());
SPUtils.remove(context, Contans.NFCBM);
//格式化日期的对象(转化成习惯的时间格式)
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy年MM月dd日");
//静态方法getInstance()使用默认时区和语言环境获得一个日历。
Calendar calendar = Calendar.getInstance();
//输出当前系统时间;
//System.out.println("当前系统时间: "+sdFormat.format(calendar.getTime()));
//add()增加日期以天为单位Calendar封装了很多静态的操作时间的单位
//增加10天负数则为减少天数
calendar.add(Calendar.DATE, 10);
//输出增加10天后的时间;
//System.out.println("增加10天后的时间: "+sdFormat.format(calendar.getTime()));
//输出时间为2020年的第100天
Date date = sdFormat.parse(sdFormat.format(calendar.getTime()));
Calendar calendarOne = Calendar.getInstance();
calendarOne.setTime(date);
SPUtils.put(LoginActivity.this, Contans.LASTLOGINDATE, sdFormat.format(calendarOne.getTime()));
//System.out.println("加10天后的日期: "+sdFormat.format(calendarOne.getTime()));
//System.out.println("登录已失效: "+String.valueOf(Calendar.getInstance().after(calendarOne)));
needAlarm = false;
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
break;
case "2":
showToast("登录异常...");
break;
case "3":
showToast("未激活或未授权...");
break;
case "4":
showToast("禁止登陆...");
break;
}
} else {
String jsonDecode = RSAUtils.decryptBASE64StrByPublic(json);
if (TextUtils.isEmpty(jsonDecode)) {
showToast(UiUtlis.getString(context, R.string.data_error));
} else {
UserInfo userInfo = GsonUtils.GsonToBean(jsonDecode, UserInfo.class);
showLog(new Gson().toJson(userInfo));
showLog(jsonDecode);
if (userInfo != null) {
UserInfo.User user = userInfo.getRows().get(0);
String status = user.getStatus();
String username = user.getUsernames();
String token = user.getToken();
switch (status) {
case "0":
showToast("用户名或密码错误");
break;
case "1":
SPUtils.put(LoginActivity.this, "save", savePwUser.isChecked());
SPUtils.put(LoginActivity.this, Contans.USERID, RSAUtils.encryptBASE64StrLocal(etUse.getText().toString()));
SPUtils.put(LoginActivity.this, Contans.USERPWD, RSAUtils.encryptBASE64StrLocal(etPwd.getText().toString()));
SPUtils.put(LoginActivity.this, Contans.LOGIN_TOKEN, RSAUtils.encryptBASE64StrLocal(token));
SPUtils.put(LoginActivity.this, Contans.USERNAME, username);
SPUtils.put(LoginActivity.this, Contans.BZBH, user.getBzbh() == null ? "" : user.getBzbh());
SPUtils.put(LoginActivity.this, Contans.BZMC, user.getBzmc() == null ? "" : user.getBzmc());
SPUtils.put(LoginActivity.this, Contans.PERMISSIONSRESULT, user.getPermissionsResult() == null ? "" : user.getPermissionsResult());
SPUtils.put(LoginActivity.this, Contans.ZY, user.getZY() == null ? "" : user.getZY());
SPUtils.remove(context, Contans.NFCBM);
//格式化日期的对象(转化成习惯的时间格式)
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy年MM月dd日");
//静态方法getInstance()使用默认时区和语言环境获得一个日历。
Calendar calendar = Calendar.getInstance();
//输出当前系统时间;
//System.out.println("当前系统时间: "+sdFormat.format(calendar.getTime()));
//add()增加日期以天为单位Calendar封装了很多静态的操作时间的单位
//增加10天负数则为减少天数
calendar.add(Calendar.DATE, 10);
//输出增加10天后的时间;
//System.out.println("增加10天后的时间: "+sdFormat.format(calendar.getTime()));
//输出时间为2020年的第100天
Date date = sdFormat.parse(sdFormat.format(calendar.getTime()));
Calendar calendarOne = Calendar.getInstance();
calendarOne.setTime(date);
SPUtils.put(LoginActivity.this, Contans.LASTLOGINDATE, sdFormat.format(calendarOne.getTime()));
//System.out.println("加10天后的日期: "+sdFormat.format(calendarOne.getTime()));
//System.out.println("登录已失效: "+String.valueOf(Calendar.getInstance().after(calendarOne)));
needAlarm = false;
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
break;
case "2":
showToast("登录异常...");
break;
case "3":
showToast("未激活或未授权...");
break;
case "4":
showToast("禁止登陆...");
break;
}
} else {
showToast(UiUtlis.getString(context, R.string.data_error));
}
}
}
@ -446,8 +455,9 @@ public class LoginActivity extends BaseActivity {
list.add(userInfo);
info.setRows(list);
String json = GsonUtils.GsonString(info);
//Log.i("app", json);
return json;
showLog(json);
showLog(RSAUtils.encryptBASE64Str(json));
return RSAUtils.encryptBASE64Str(json);
}
public String getNfcInfo(String nfcId) {

@ -554,10 +554,9 @@ public class MainActivity extends BaseActivity3 {
return null;
}
public void initMqtt() {
public void initMqtt() {
//开启MQTT一键招回
mqttPublishServer = new MqttSSLPublishServer(this,userID);
//mqttPublishServer.start();
mqttPublishServer = new MqttSSLPublishServer(this);
try {
timer = new Timer();
timer.schedule(new TimerTask() {
@ -577,7 +576,7 @@ public class MainActivity extends BaseActivity3 {
super.onResume();
if(Contans.IP.equals(Contans.network_type_extranet)){
if(mqttPublishServer==null){
mqttPublishServer = new MqttSSLPublishServer(this,userID);
mqttPublishServer = new MqttSSLPublishServer(this);
}
if(timer==null){
try {
@ -618,3 +617,13 @@ public class MainActivity extends BaseActivity3 {
}
}
//XSCB/YX_XJGL.ashx
//XSCB/BA_XJGL.ashx
//XSCB/CURRENT_CHECK_LOCALTION.ashx
//XSCB/CURRENT_CHECK_LOCALTION_TXM.ashx
//XSCB/LAST_UPLOAD_POINT_CHECKED.ashx
//XSCB/LAST_UPLOAD_POINT_CHECKED_TXM.ashx
//XSCB/MY_UPLOAD.ashx
//XSCB/STATISTICS_CHECKED.ashx

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
@ -341,6 +342,17 @@ public class ScxsjhFragment extends BaseFragment {
Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.XSCB, RequestMethod.POST);
// Log.i("app", Contans.IP + Contans.XSCB);
// Log.i("app", json);
String tokenTemp = (String) SPUtils.get(mActivity, Contans.LOGIN_TOKEN, "");
if(!TextUtils.isEmpty(tokenTemp)){
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);;
String credential = "Bearer " + token;
request.addHeader("Authorization", credential);
showLog(request.url());
if(!TextUtils.isEmpty(token)){
showLog(credential);
//showLog(new Gson().toJson(request.headers()));
}
}
request.setDefineRequestBodyForJson(json);
queue.add(1, request, new OnResponseListener<>(){
@ -479,6 +491,17 @@ public class ScxsjhFragment extends BaseFragment {
// Log.i("app", Contans.IP + Contans.XSCB_PLAN_BA_UPLOAD);
// Log.i("app", json);
Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.XSCB_PLAN_BA_UPLOAD, RequestMethod.POST);
String tokenTemp = (String) SPUtils.get(mActivity, Contans.LOGIN_TOKEN, "");
if(!TextUtils.isEmpty(tokenTemp)){
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);;
String credential = "Bearer " + token;
request.addHeader("Authorization", credential);
showLog(request.url());
if(!TextUtils.isEmpty(token)){
showLog(credential);
//showLog(new Gson().toJson(request.headers()));
}
}
request.setDefineRequestBodyForJson(json);
queue.add(2, request, new OnResponseListener<>(){
@Override

@ -7,6 +7,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -303,8 +304,18 @@ public class XzxsjhFragment extends BaseFragment {
//运行,燃料计划下载
private void downData(String zxid, String jhmc) {
selectCount++;
Log.i("app", Contans.IP + Contans.XSCB_PLAN_DOWNLOAD);
Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.XSCB_PLAN_DOWNLOAD, RequestMethod.POST);
String tokenTemp = (String) SPUtils.get(mActivity, Contans.LOGIN_TOKEN, "");
if(!TextUtils.isEmpty(tokenTemp)){
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);;
String credential = "Bearer " + token;
request.addHeader("Authorization", credential);
showLog(request.url());
if(!TextUtils.isEmpty(token)){
showLog(credential);
//showLog(new Gson().toJson(request.headers()));
}
}
request.setDefineRequestBodyForJson(createZyJson(zxid, jhmc));
queue.add(1, request, new HttpResponseListener<>(getActivity(), request, callback, false, false, ""));
}
@ -312,8 +323,18 @@ public class XzxsjhFragment extends BaseFragment {
//保安计划下载
private void downDataBA(String zxid) {
selectCount++;
Log.i("app", Contans.IP + Contans.XSCB_PLAN_BA_DOWNLOAD);
Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.XSCB_PLAN_BA_DOWNLOAD, RequestMethod.POST);
String tokenTemp = (String) SPUtils.get(mActivity, Contans.LOGIN_TOKEN, "");
if(!TextUtils.isEmpty(tokenTemp)){
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);;
String credential = "Bearer " + token;
request.addHeader("Authorization", credential);
showLog(request.url());
if(!TextUtils.isEmpty(token)){
showLog(credential);
//showLog(new Gson().toJson(request.headers()));
}
}
request.setDefineRequestBodyForJson(createZyJsonBA(zxid));
queue.add(2, request, new HttpResponseListener<>(getActivity(), request, callbackBA, false, false, ""));
}

@ -16,10 +16,14 @@ import android.nfc.tech.NfcF;
import android.nfc.tech.NfcV;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.bjzc.yfdxj.BuildConfig;
import com.bjzc.yfdxj.R;
import com.bjzc.yfdxj.utils.ControllerActivity;
import com.zhy.autolayout.AutoLayoutActivity;
@ -112,7 +116,7 @@ public abstract class BaseActivity extends AutoLayoutActivity {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_UPDATE_CURRENT);
}
//设定要过滤的标签动作这里只接收ACTION_NDEF_DISCOVERED类型
ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
@ -196,4 +200,14 @@ public abstract class BaseActivity extends AutoLayoutActivity {
}
public void handleNfc(String result) {
}
public void showLog(String logText) {
if (BuildConfig.LOG_ERROR) {
if(TextUtils.isEmpty(logText)){
Log.i("app", "logText is null");
}else{
Log.i("app", logText);
}
}
}
}

@ -18,10 +18,13 @@ import android.nfc.tech.NfcF;
import android.nfc.tech.NfcV;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.bjzc.yfdxj.BuildConfig;
import com.bjzc.yfdxj.R;
import com.bjzc.yfdxj.utils.AppManager;
import com.bjzc.yfdxj.utils.OAToolbar;
@ -81,7 +84,7 @@ public abstract class BaseActivity3 extends AutoLayoutActivity {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_UPDATE_CURRENT);
}
//pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
//设定要过滤的标签动作这里只接收ACTION_NDEF_DISCOVERED类型
@ -234,4 +237,14 @@ public abstract class BaseActivity3 extends AutoLayoutActivity {
return editText.getText().toString();
}
public void showLog(String logText) {
if (BuildConfig.LOG_ERROR) {
if(TextUtils.isEmpty(logText)){
Log.i("app", "logText is null");
}else{
Log.i("app", logText);
}
}
}
}

@ -4,6 +4,8 @@ package com.bjzc.yfdxj.base;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,6 +14,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.bjzc.yfdxj.BuildConfig;
/**
* Created by Administrator on 2016/9/icon5.
@ -66,5 +70,14 @@ public abstract class BaseFragment extends Fragment {
Toast.makeText(getContext(), strId, Toast.LENGTH_SHORT).show();
}
public void showLog(String logText) {
if (BuildConfig.LOG_ERROR) {
if(TextUtils.isEmpty(logText)){
Log.i("app", "logText is null");
}else{
Log.i("app", logText);
}
}
}
}

@ -37,6 +37,8 @@ public class UserInfo {
private String PermissionsResult;
private String ZY;
private String token;
public String getPermissionsResult() {
return PermissionsResult;
}
@ -92,5 +94,13 @@ public class UserInfo {
public void setZY(String ZY) {
this.ZY = ZY;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
}

@ -104,6 +104,7 @@ public class Contans {
public final static String USERID = "USERID";
public final static String USERPWD = "USERPWD";
public final static String NETWORK_CHECK_TYPE = "NETWORK_CHECK_TYPE";
public final static String LOGIN_TOKEN = "LOGIN_TOKEN";
public final static String NFCBM = "NFCBM";
public final static String BZBH = "bzbh";
public final static String BZMC = "bzmc";

@ -137,7 +137,7 @@ public class PushService extends IntentService {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

@ -13,6 +13,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
@ -76,14 +77,16 @@ public class MqttSSLPublishServer {
private MqttMessage message;
private Context context;
private static String userID;
public MqttSSLPublishServer(Context context,String userId) {
public MqttSSLPublishServer(Context context) {
this.context=context;
userID=userId;
// host为主机名clientid即连接MQTT的客户端ID一般以唯一标识符表示MemoryPersistence设置clientid的保存形式默认为以内存保存
try {
clientid=UUID.randomUUID().toString();
clientid=(String) SPUtils.get(context,"clientid",String.valueOf(""));
if(TextUtils.isEmpty(clientid)){
clientid=UUID.randomUUID().toString();
SPUtils.put(context,"clientid",clientid);
}
client = new MqttClient(HOST, clientid, new MemoryPersistence());
// MQTT的连接设置

@ -4,8 +4,13 @@ package com.bjzc.yfdxj.utils;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.bjzc.yfdxj.BuildConfig;
import com.bjzc.yfdxj.R;
import com.bjzc.yfdxj.contans.Contans;
import com.google.gson.Gson;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.download.DownloadQueue;
import com.yolanda.nohttp.rest.Request;
@ -65,9 +70,30 @@ public class NoProgresshttpUtils {
public <T> void add(Activity mActivity, int what, Request<T> request, HttpListener<T> callback) {
String tokenTemp = (String) SPUtils.get(mActivity, Contans.LOGIN_TOKEN, "");
if(!TextUtils.isEmpty(tokenTemp)){
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);;
String credential = "Bearer " + token;
request.addHeader("Authorization", credential);
showLog(request.url());
if(!TextUtils.isEmpty(token)){
showLog(credential);
//showLog(new Gson().toJson(request.headers()));
}
}
mQueue.add(what, request, new HttpResponseListenerNoProgress<T>(mActivity, request, callback));
}
public void showLog(String logText) {
if (BuildConfig.LOG_ERROR) {
if(TextUtils.isEmpty(logText)){
Log.i("app", "logText is null");
}else{
Log.i("app", logText);
}
}
}
/**
* sign
*

@ -2,8 +2,13 @@ package com.bjzc.yfdxj.utils;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.bjzc.yfdxj.BuildConfig;
import com.bjzc.yfdxj.R;
import com.bjzc.yfdxj.contans.Contans;
import com.google.gson.Gson;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.download.DownloadQueue;
import com.yolanda.nohttp.rest.Request;
@ -74,14 +79,46 @@ public class NohttpUtils {
* @param <T>
*/
public <T> void add(Activity mActivity, int what, Request<T> request, HttpListener<T> callback, boolean canCanel, boolean isLoading, String msg) {
String tokenTemp = (String) SPUtils.get(mActivity, Contans.LOGIN_TOKEN, "");
if(!TextUtils.isEmpty(tokenTemp)){
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);;
String credential = "Bearer " + token;
request.addHeader("Authorization", credential);
showLog(request.url());
if(!TextUtils.isEmpty(token)){
showLog(credential);
//showLog(new Gson().toJson(request.headers()));
}
}
mQueue.add(what, request, new HttpResponseListener<T>(mActivity, request, callback, canCanel, isLoading, msg));
}
public <T> void add(Activity mActivity, int what, Request<T> request, HttpListener<T> callback) {
String tokenTemp = (String) SPUtils.get(mActivity, Contans.LOGIN_TOKEN, "");
if(!TextUtils.isEmpty(tokenTemp)){
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);;
String credential = "Bearer " + token;
request.addHeader("Authorization", credential);
showLog(request.url());
if(!TextUtils.isEmpty(token)){
showLog(credential);
//showLog(new Gson().toJson(request.headers()));
}
}
mQueue.add(what, request, new HttpResponseListener<T>(mActivity, request, callback, true, true, "加载中..."));
}
public void showLog(String logText) {
if (BuildConfig.LOG_ERROR) {
if(TextUtils.isEmpty(logText)){
Log.i("app", "logText is null");
}else{
Log.i("app", logText);
}
}
}
/**
* sign
*

@ -4,6 +4,7 @@ package com.bjzc.yfdxj.utils;
import android.util.Base64;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
@ -24,11 +25,21 @@ public class RSAUtils {
* RSA
*/
public static final String RSA = "RSA";
public static final String ECB_None_PKCS1_PADDING = "RSA/None/PKCS1Padding";//java默认加密填充方式 RSA/None/PKCS1Padding
private static final String PUBLIC_KEY = "RSAPublicKey";
private static final String PRIVATE_KEY = "RSAPrivateKey";
public static final int DEFAULT_KEY_SIZE = 2048;//秘钥默认长度
//RSA最大加密明文大小 1024位是117 算法 最大加密明文大小 = 1024(bit) / 8 - 11(byte) = 117 byte 最大加密明文大小 = 2048(bit) / 8 - 11(byte) = 245 byte
//private static final int MAX_ENCRYPT_BLOCK = 245;
private static final int MAX_ENCRYPT_BLOCK = (DEFAULT_KEY_SIZE / 8) - 11;
//RSA最大解密密文大小 1024位是128 2048位是 256 依此类推
//private static final int MAX_DECRYPT_BLOCK = 256;
private static final int MAX_DECRYPT_BLOCK = DEFAULT_KEY_SIZE / 8;
//java默认加密填充方式 RSA 对应安卓 RSA/None/PKCS1Padding
//public static final String ECB_None_PKCS1_PADDING = "RSA";
//安卓手机加密填充方式用 RSA/None/PKCS1Padding
public static final String ECB_None_PKCS1_PADDING = "RSA/None/PKCS1Padding";
public static final String public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnRh8MAqfpBZffouPsU3hToRZl3soo2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Vv/mS9FzzxmBRFOwUXFD8iXyEKI8xkteyHGniKRwBYoWR32kQw7H/Mnpamo1fCrHA6Dg55CBeIEkg2oyPGKzvhkPVopJzj9zukW8w2F0iR5ll0QBl7XzGyy3EHmIsYsod3LSIh1g5A2zsscJ0ouorKGLwY1LK06a34JTkYz5p7lx6Nn6589Re8GwIDAQAB";
@ -50,7 +61,17 @@ public class RSAUtils {
public static String decryptBASE64Str(String encryptString) {
try {
byte[] decodeByte = decryptBASE64(encryptString);
return new String(decryptByPrivateKey(decodeByte, private_key));
return new String(decryptByPrivateKeyLongText(decodeByte, private_key));
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static String decryptBASE64StrByPublic(String encryptString) {
try {
byte[] decodeByte = decryptBASE64(encryptString);
return new String(decryptByPublicKeyLongText(decodeByte, public_key));
} catch (Exception e) {
e.printStackTrace();
}
@ -60,7 +81,7 @@ public class RSAUtils {
public static String decryptBASE64StrLocal(String encryptString) {
try {
byte[] decodeByte = decryptBASE64(encryptString);
return new String(decryptByPrivateKey(decodeByte, private_key_local));
return new String(decryptByPrivateKeyLongText(decodeByte, private_key_local));
} catch (Exception e) {
e.printStackTrace();
}
@ -70,7 +91,7 @@ public class RSAUtils {
public static String decryptBASE64StrMqtt(String encryptString) {
try {
byte[] decodeByte = decryptBASE64(encryptString);
return new String(decryptByPrivateKey(decodeByte, private_key_mqtt));
return new String(decryptByPrivateKeyLongText(decodeByte, private_key_mqtt));
} catch (Exception e) {
e.printStackTrace();
}
@ -79,7 +100,7 @@ public class RSAUtils {
public static String encryptBASE64Str(String text) {
try {
return encryptBASE64(encryptByPublicKey(text.getBytes(), public_key));
return encryptBASE64(encryptByPublicKeyLongText(text.getBytes(), public_key));
} catch (Exception e) {
e.printStackTrace();
}
@ -88,7 +109,7 @@ public class RSAUtils {
public static String encryptBASE64StrLocal(String text) {
try {
return encryptBASE64(encryptByPublicKey(text.getBytes(), public_key_local));
return encryptBASE64(encryptByPublicKeyLongText(text.getBytes(), public_key_local));
} catch (Exception e) {
e.printStackTrace();
}
@ -97,7 +118,7 @@ public class RSAUtils {
public static String encryptBASE64StrMqtt(String text) {
try {
return encryptBASE64(encryptByPublicKey(text.getBytes(), public_key_mqtt));
return encryptBASE64(encryptByPublicKeyLongText(text.getBytes(), public_key_mqtt));
} catch (Exception e) {
e.printStackTrace();
}
@ -127,6 +148,44 @@ public class RSAUtils {
return cipher.doFinal(data);
}
/**
*
* @param encryptedData
* @param privateKey
* @return
* @throws Exception
*/
public static byte[] decryptByPrivateKeyLongText(byte[] encryptedData, String privateKey) throws Exception {
byte[] keyBytes = decryptBASE64(privateKey);
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(RSA);
Key privateK = keyFactory.generatePrivate(pkcs8KeySpec);
Cipher cipher = Cipher.getInstance(ECB_None_PKCS1_PADDING);
cipher.init(Cipher.DECRYPT_MODE, privateK);
int inputLen = encryptedData.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 对数据分段解密
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK);
} else {
cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_DECRYPT_BLOCK;
}
byte[] decryptedData = out.toByteArray();
out.close();
return decryptedData;
}
/**
* <br>
*
@ -136,8 +195,7 @@ public class RSAUtils {
* @return
* @throws Exception
*/
public static byte[] decryptByPublicKey(byte[] data, String key)
throws Exception {
public static byte[] decryptByPublicKey(byte[] data, String key) throws Exception {
// 对密钥解密
byte[] keyBytes = decryptBASE64(key);
// 取得公钥
@ -150,6 +208,68 @@ public class RSAUtils {
return cipher.doFinal(data);
}
/**
*
* @param encryptedData
* @param publicKey
* @return
* @throws Exception
*/
public static byte[] decryptByPublicKeyLongText(byte[] encryptedData, String publicKey) throws Exception {
byte[] keyBytes = decryptBASE64(publicKey);
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(RSA);
Key publicK = keyFactory.generatePublic(x509KeySpec);
Cipher cipher = Cipher.getInstance(ECB_None_PKCS1_PADDING);
cipher.init(Cipher.DECRYPT_MODE, publicK);
int inputLen = encryptedData.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 对数据分段解密
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK);
} else {
cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_DECRYPT_BLOCK;
}
byte[] decryptedData = out.toByteArray();
out.close();
return decryptedData;
}
/**
* <br>
*
@ -159,8 +279,7 @@ public class RSAUtils {
* @return
* @throws Exception
*/
public static byte[] encryptByPublicKey(byte[] data, String key)
throws Exception {
public static byte[] encryptByPublicKey(byte[] data, String key) throws Exception {
// 对公钥解密
byte[] keyBytes = decryptBASE64(key);
// 取得公钥
@ -173,6 +292,69 @@ public class RSAUtils {
return cipher.doFinal(data);
}
/**
*
* @param data
* @param publicKey
* @return
* @throws Exception
*/
public static byte[] encryptByPublicKeyLongText(byte[] data, String publicKey) throws Exception {
byte[] keyBytes = decryptBASE64(publicKey);
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(RSA);
Key publicK = keyFactory.generatePublic(x509KeySpec);
// 对数据加密
Cipher cipher = Cipher.getInstance(ECB_None_PKCS1_PADDING);
cipher.init(Cipher.ENCRYPT_MODE, publicK);
int inputLen = data.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 对数据分段加密
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
} else {
cache = cipher.doFinal(data, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_ENCRYPT_BLOCK;
}
byte[] encryptedData = out.toByteArray();
out.close();
return encryptedData;
}
/**
* <br>
*
@ -182,8 +364,7 @@ public class RSAUtils {
* @return
* @throws Exception
*/
public static byte[] encryptByPrivateKey(byte[] data, String key)
throws Exception {
public static byte[] encryptByPrivateKey(byte[] data, String key) throws Exception {
// 对密钥解密
byte[] keyBytes = decryptBASE64(key);
// 取得私钥
@ -196,6 +377,67 @@ public class RSAUtils {
return cipher.doFinal(data);
}
/**
*
* @param data
* @param privateKey
* @return
* @throws Exception
*/
public static byte[] encryptByPrivateKeyLongText(byte[] data, String privateKey) throws Exception {
byte[] keyBytes = decryptBASE64(privateKey);
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(RSA);
Key privateK = keyFactory.generatePrivate(pkcs8KeySpec);
Cipher cipher = Cipher.getInstance(ECB_None_PKCS1_PADDING);
cipher.init(Cipher.ENCRYPT_MODE, privateK);
int inputLen = data.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 对数据分段加密
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
} else {
cache = cipher.doFinal(data, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_ENCRYPT_BLOCK;
}
byte[] encryptedData = out.toByteArray();
out.close();
return encryptedData;
}
/**
*
*
@ -232,7 +474,7 @@ public class RSAUtils {
public static Map<String, Object> initKey() throws Exception {
KeyPairGenerator keyPairGen = KeyPairGenerator
.getInstance(RSA);
keyPairGen.initialize(2048);
keyPairGen.initialize(DEFAULT_KEY_SIZE);
KeyPair keyPair = keyPairGen.generateKeyPair();
// 公钥
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();

Loading…
Cancel
Save