RSA finish

master
hwf452 2 years ago
parent 16b88c599a
commit 5bc47b32fb

@ -120,7 +120,7 @@ public class ContactFragment extends BaseFragment {
public void getDatas() { public void getDatas() {
HttpUtils.getApi().getContactList().enqueue(new BaseCallBack<ContactListBean>(getContext()) { HttpUtils.getApi(context).getContactList().enqueue(new BaseCallBack<ContactListBean>(getContext()) {
@Override @Override
public void onSuccess(Call<ContactListBean> call, Response<ContactListBean> response) { public void onSuccess(Call<ContactListBean> call, Response<ContactListBean> response) {

@ -353,12 +353,10 @@ public class LoginActivity extends BaseActivity {
@Override @Override
public void onSucceed(int what, Response<String> response) throws ParseException { public void onSucceed(int what, Response<String> response) throws ParseException {
String json = response.get(); String json = response.get();
//String json = "PVZQuOAHHNLLZp4vjledRJZ+Y4RpO1Gq6MbZFgIK18AGQDfnlZtahunLOdMrKV5SgSvUurJXSIOF0nB208hsdU+1tQXW4UfpAeHLivC2J0PmL3jxnW7qMO6FYRYFNwlM+8JvPPkx8f2szJl/e6t5qsCPseUkdb7k8SlU5hR/ljs/gXYAlqrD3NRUvVzwRcYgWgCRgvxKZ6vNbvee2dcoHO49b3Ttoo7D8e2ATspWagMQgAuGe4BRv1a3qLcNujm7KI9eKcufMkWUxtA/q0K+Mf6P0RUBmiuSpODbS/jR47XfTjxGqxKwckrZtbi24VAHr3xe6ItaHyLUbXt3R6phZxYIfhVpmb16TSFmlFDq0PJ+GpEBxkEJ+fDeEN4RTuOtVrNrQhr+EL/pa03JvKPjcVDPxTZ5sKDdRylpIYRii8fOh4EKTILoui7doi22ZkSd+OOzAk3vT4UYktQ9H1+aPvmGSvdnIV5EuW9sh72d4Y9wL0VSK+CPB6kMsB/lAx4Y+yWxH3OTBRN6/aeIbvzGjIfnaxLMTj/VpJsswfBWAllyB4LVu363dTxv2kBR92WuOCLF0Ob2byXwnqnKDPlTw0mcr9KGXhp02MWzIpo4WlR16kk40MAyjCUudJQLQkkq8m8bCkCa2MwmLTGSD0z5Xrf6SnuuAiCqArmxPRWG9xBx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1pTSpuWEjW5JZYy4/PA8SU0lsenjTZ49y/PVkvRO6moEY9jnnRcuRe1k3bBl2A37Z4txX3vGatdG2N+1pWUk3/m57ehXN4rJd7btqDu/F9CfJW8bibkXlraVNu6hKajiCAc+U+l5wC3yFsjdQsjjDPYYawDNgL0jcvGy1sf0CXk0O3LuSLxoSv9+yMMttkagbzTfIjxLTc5gSnPIzb4LuxcoMeSaL8FFs/YlWS3GCXhgUdOmjbTTQ4kirXyjN4DeSMBKEJFP2oSyvJFctU7PJOx4/qHkZd5XPUTq+Fz0QGo9+6DFRUtScGXARIEt1TkYiIO1DquccX+HsmXFqqbfBxbPc9ieb8ozikhOMZv4jk7c2kdr7nleOt4PVx5oIIsQTiMD13mvqyxLvExu6M/mcUnIQ4mYPFTHJgi3dOP9Q5zWnwcscpXpya8iHRHXYcqxfghn9y7lAbYguGxkXfzQCdvb4at5rd79W6bIZ/iuzJDWroRmzIQfNox6BfK58KfJf0ZgXW1+QhBSja6Jb93+0C2of7PLojHaiKWWHyvva9D2jUQ==";
showLog("-----login-----"); showLog("-----login-----");
showLog(json); showLog(json);
String jsonDecode = RSAUtils.decryptBASE64Str(json); String jsonDecode = RSAUtils.decryptBASE64StrClient(json);
if (TextUtils.isEmpty(jsonDecode)) { if (TextUtils.isEmpty(jsonDecode)) {
showToast(UiUtlis.getString(context, R.string.data_error)); showToast(UiUtlis.getString(context, R.string.data_error));
} else { } else {
@ -502,7 +500,7 @@ public class LoginActivity extends BaseActivity {
} }
private void checkUpdateApk() { private void checkUpdateApk() {
HttpUtils.getApi().getCheckUpdataApk().enqueue(new BaseCallBackNoProgress<ApkUpdateBean>(context) { HttpUtils.getApi(context).getCheckUpdataApk().enqueue(new BaseCallBackNoProgress<ApkUpdateBean>(context) {
@Override @Override
public void onSuccess(Call<ApkUpdateBean> call, retrofit2.Response<ApkUpdateBean> response) { public void onSuccess(Call<ApkUpdateBean> call, retrofit2.Response<ApkUpdateBean> response) {
ApkUpdateBean appUploadInfo = response.body(); ApkUpdateBean appUploadInfo = response.body();
@ -540,7 +538,7 @@ public class LoginActivity extends BaseActivity {
.apkUrl(downloadURL) .apkUrl(downloadURL)
.apkName("云浮电厂点巡检.apk") .apkName("云浮电厂点巡检.apk")
.smallIcon(R.mipmap.logo1) .smallIcon(R.mipmap.logo1)
.showNewerToast(true) .showNewerToast(false)
.apkVersionCode(Integer.parseInt(versionCode)) .apkVersionCode(Integer.parseInt(versionCode))
.apkVersionName(versionName) .apkVersionName(versionName)
.apkDescription(description) .apkDescription(description)

@ -460,7 +460,7 @@ public class MainActivity extends BaseActivity3 {
private void checkUpdateApk() { private void checkUpdateApk() {
HttpUtils.getApi().getCheckUpdataApk().enqueue(new BaseCallBackNoProgress<ApkUpdateBean>(context) { HttpUtils.getApi(context).getCheckUpdataApk().enqueue(new BaseCallBackNoProgress<ApkUpdateBean>(context) {
@Override @Override
public void onSuccess(Call<ApkUpdateBean> call, retrofit2.Response<ApkUpdateBean> response) { public void onSuccess(Call<ApkUpdateBean> call, retrofit2.Response<ApkUpdateBean> response) {
ApkUpdateBean appUploadInfo = response.body(); ApkUpdateBean appUploadInfo = response.body();
@ -498,7 +498,7 @@ public class MainActivity extends BaseActivity3 {
.apkUrl(downloadURL) .apkUrl(downloadURL)
.apkName("云浮电厂点巡检.apk") .apkName("云浮电厂点巡检.apk")
.smallIcon(R.mipmap.logo1) .smallIcon(R.mipmap.logo1)
.showNewerToast(true) .showNewerToast(false)
.apkVersionCode(Integer.parseInt(versionCode)) .apkVersionCode(Integer.parseInt(versionCode))
.apkVersionName(versionName) .apkVersionName(versionName)
.apkDescription(description) .apkDescription(description)

@ -152,7 +152,7 @@ public class QxgdActivity extends BaseActivity3 {
private void GETJZ() { private void GETJZ() {
HttpUtils.GETMAXIMOIP().GetJzList().enqueue(new BaseCallBack<JzBean>(context) { HttpUtils.GETMAXIMOIP(context).GetJzList().enqueue(new BaseCallBack<JzBean>(context) {
@Override @Override
public void onSuccess(Call<JzBean> call, Response<JzBean> response) { public void onSuccess(Call<JzBean> call, Response<JzBean> response) {
JzBean bean1 = response.body(); JzBean bean1 = response.body();
@ -173,7 +173,7 @@ public class QxgdActivity extends BaseActivity3 {
private void GETZY() { private void GETZY() {
HttpUtils.GETMAXIMOIP().GetZyList().enqueue(new BaseCallBack<JzBean>(context) { HttpUtils.GETMAXIMOIP(context).GetZyList().enqueue(new BaseCallBack<JzBean>(context) {
@Override @Override
public void onSuccess(Call<JzBean> call, Response<JzBean> response) { public void onSuccess(Call<JzBean> call, Response<JzBean> response) {
JzBean bean = response.body(); JzBean bean = response.body();
@ -195,7 +195,7 @@ public class QxgdActivity extends BaseActivity3 {
private void GETLX() { private void GETLX() {
HttpUtils.GETMAXIMOIP().GetLxist().enqueue(new BaseCallBack<JzBean>(context) { HttpUtils.GETMAXIMOIP(context).GetLxist().enqueue(new BaseCallBack<JzBean>(context) {
@Override @Override
public void onSuccess(Call<JzBean> call, Response<JzBean> response) { public void onSuccess(Call<JzBean> call, Response<JzBean> response) {
JzBean bean = response.body(); JzBean bean = response.body();
@ -217,7 +217,7 @@ public class QxgdActivity extends BaseActivity3 {
private void GETQXDJ() { private void GETQXDJ() {
HttpUtils.GETMAXIMOIP().GetQXDJist().enqueue(new BaseCallBack<JzBean>(context) { HttpUtils.GETMAXIMOIP(context).GetQXDJist().enqueue(new BaseCallBack<JzBean>(context) {
@Override @Override
public void onSuccess(Call<JzBean> call, Response<JzBean> response) { public void onSuccess(Call<JzBean> call, Response<JzBean> response) {
JzBean bean = response.body(); JzBean bean = response.body();
@ -238,7 +238,7 @@ public class QxgdActivity extends BaseActivity3 {
private void GETGDAP() { private void GETGDAP() {
HttpUtils.GETMAXIMOIP().GetGDAPist().enqueue(new BaseCallBack<JzBean>(context) { HttpUtils.GETMAXIMOIP(context).GetGDAPist().enqueue(new BaseCallBack<JzBean>(context) {
@Override @Override
public void onSuccess(Call<JzBean> call, Response<JzBean> response) { public void onSuccess(Call<JzBean> call, Response<JzBean> response) {
JzBean bean = response.body(); JzBean bean = response.body();
@ -289,7 +289,7 @@ public class QxgdActivity extends BaseActivity3 {
private void UploadDatas() { private void UploadDatas() {
HttpUtils.GETMAXIMOIP().UploadQXgd(GetInfo()).enqueue(new BaseCallBack<QXGDResultBean>(context) { HttpUtils.GETMAXIMOIP(context).UploadQXgd(GetInfo()).enqueue(new BaseCallBack<QXGDResultBean>(context) {
@Override @Override
public void onSuccess(Call<QXGDResultBean> call, Response<QXGDResultBean> response) { public void onSuccess(Call<QXGDResultBean> call, Response<QXGDResultBean> response) {
QXGDResultBean bean = response.body(); QXGDResultBean bean = response.body();

@ -348,10 +348,10 @@ public class ScxsjhFragment extends BaseFragment {
String credential = "Bearer " + token; String credential = "Bearer " + token;
request.addHeader("Authorization", credential); request.addHeader("Authorization", credential);
showLog(request.url()); showLog(request.url());
if(!TextUtils.isEmpty(token)){ // if(!TextUtils.isEmpty(token)){
showLog(credential); // showLog(credential);
//showLog(new Gson().toJson(request.headers())); // showLog(new Gson().toJson(request.headers()));
} // }
} }
request.setDefineRequestBodyForJson(json); request.setDefineRequestBodyForJson(json);
queue.add(1, request, new OnResponseListener<>(){ queue.add(1, request, new OnResponseListener<>(){
@ -497,10 +497,10 @@ public class ScxsjhFragment extends BaseFragment {
String credential = "Bearer " + token; String credential = "Bearer " + token;
request.addHeader("Authorization", credential); request.addHeader("Authorization", credential);
showLog(request.url()); showLog(request.url());
if(!TextUtils.isEmpty(token)){ // if(!TextUtils.isEmpty(token)){
showLog(credential); // showLog(credential);
//showLog(new Gson().toJson(request.headers())); // showLog(new Gson().toJson(request.headers()));
} // }
} }
request.setDefineRequestBodyForJson(json); request.setDefineRequestBodyForJson(json);
queue.add(2, request, new OnResponseListener<>(){ queue.add(2, request, new OnResponseListener<>(){

@ -125,7 +125,7 @@ public class XJStatisticsActivity extends BaseActivity3 {
public void selectText(String text, int position) { public void selectText(String text, int position) {
if(professionList!=null&&professionList.size()>0){ if(professionList!=null&&professionList.size()>0){
Profession profession = professionList.get(position); Profession profession = professionList.get(position);
Log.i("app",profession.getZyid()); //Log.i("app",profession.getZyid());
getStatisticsData(profession.getZyid()); getStatisticsData(profession.getZyid());
} }
} }

@ -311,10 +311,10 @@ public class XzxsjhFragment extends BaseFragment {
String credential = "Bearer " + token; String credential = "Bearer " + token;
request.addHeader("Authorization", credential); request.addHeader("Authorization", credential);
showLog(request.url()); showLog(request.url());
if(!TextUtils.isEmpty(token)){ // if(!TextUtils.isEmpty(token)){
showLog(credential); // showLog(credential);
//showLog(new Gson().toJson(request.headers())); // showLog(new Gson().toJson(request.headers()));
} // }
} }
request.setDefineRequestBodyForJson(createZyJson(zxid, jhmc)); request.setDefineRequestBodyForJson(createZyJson(zxid, jhmc));
queue.add(1, request, new HttpResponseListener<>(getActivity(), request, callback, false, false, "")); queue.add(1, request, new HttpResponseListener<>(getActivity(), request, callback, false, false, ""));
@ -330,10 +330,10 @@ public class XzxsjhFragment extends BaseFragment {
String credential = "Bearer " + token; String credential = "Bearer " + token;
request.addHeader("Authorization", credential); request.addHeader("Authorization", credential);
showLog(request.url()); showLog(request.url());
if(!TextUtils.isEmpty(token)){ // if(!TextUtils.isEmpty(token)){
showLog(credential); // showLog(credential);
//showLog(new Gson().toJson(request.headers())); // showLog(new Gson().toJson(request.headers()));
} // }
} }
request.setDefineRequestBodyForJson(createZyJsonBA(zxid)); request.setDefineRequestBodyForJson(createZyJsonBA(zxid));
queue.add(2, request, new HttpResponseListener<>(getActivity(), request, callbackBA, false, false, "")); queue.add(2, request, new HttpResponseListener<>(getActivity(), request, callbackBA, false, false, ""));

@ -192,7 +192,7 @@ public class YhpcDataListActivity extends BaseActivity3 {
String yhwz = dataBaseYhpc.getWTQY(); String yhwz = dataBaseYhpc.getWTQY();
Api api = RetrofitHttpUtils.getApi(); Api api = RetrofitHttpUtils.getApi(context);
RequestBody body = RequestBody.create(MediaType.parse("application/json"), json); RequestBody body = RequestBody.create(MediaType.parse("application/json"), json);
api.upload_yhpcxx(body).enqueue(new BaseCallBack<YhpcResultBean>(context) { api.upload_yhpcxx(body).enqueue(new BaseCallBack<YhpcResultBean>(context) {
@Override @Override
@ -234,7 +234,7 @@ public class YhpcDataListActivity extends BaseActivity3 {
RequestBody imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); RequestBody imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
builder.addFormDataPart("file", file.getName(), imageBody); builder.addFormDataPart("file", file.getName(), imageBody);
} }
RetrofitHttpUtils.getApi().upload_yhpcPhoto(ID, "0", SCR, builder.build()).enqueue(new BaseCallBack<ResultBean3>(context) { RetrofitHttpUtils.getApi(context).upload_yhpcPhoto(ID, "0", SCR, builder.build()).enqueue(new BaseCallBack<ResultBean3>(context) {
@Override @Override
public void onSuccess(Call<ResultBean3> call, Response<ResultBean3> response) { public void onSuccess(Call<ResultBean3> call, Response<ResultBean3> response) {
ResultBean3 resultBean = response.body(); ResultBean3 resultBean = response.body();

@ -1,8 +1,11 @@
package com.bjzc.yfdxj.utils; package com.bjzc.yfdxj.utils;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import com.bjzc.yfdxj.contans.Contans; import com.bjzc.yfdxj.contans.Contans;
import java.io.IOException; import java.io.IOException;
@ -40,27 +43,27 @@ public class HttpUtils {
private HttpUtils(Context context, String url) { private HttpUtils(Context context, String url) {
Retrofit mRetrofit = new Retrofit.Builder() Retrofit mRetrofit = new Retrofit.Builder()
.baseUrl(url) .baseUrl(url)
.client(getOkHttpClient()) .client(getOkHttpClient(context))
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build(); .build();
api = mRetrofit.create(Api.class); api = mRetrofit.create(Api.class);
HttpUtils.context = context; HttpUtils.context = context;
} }
public static Api getApi() { public static Api getApi(Context context) {
return getApi(Contans.IP); return getApi(Contans.IP, context);
} }
public static Api GETMAXIMOIP() { public static Api GETMAXIMOIP(Context context) {
return getApi(Contans.MAXIMOIP); return getApi(Contans.MAXIMOIP, context);
} }
public static Api getApi(String url) { public static Api getApi(String url, Context context) {
Retrofit mRetrofit = new Retrofit.Builder() Retrofit mRetrofit = new Retrofit.Builder()
.baseUrl(url) .baseUrl(url)
.client(getOkHttpClient()) .client(getOkHttpClient(context))
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build(); .build();
Api api = mRetrofit.create(Api.class); Api api = mRetrofit.create(Api.class);
@ -69,10 +72,10 @@ public class HttpUtils {
} }
private static OkHttpClient getOkHttpClient() { private static OkHttpClient getOkHttpClient(Context context) {
HttpUtils.context = context;
OkHttpClient.Builder httpClientBuilder = new OkHttpClient OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
.Builder(); httpClientBuilder.addNetworkInterceptor(new TokenHeaderInterceptor());
//OkHttp进行添加拦截器loggingInterceptor //OkHttp进行添加拦截器loggingInterceptor
httpClientBuilder.addInterceptor(new LoggingInterceptor()); httpClientBuilder.addInterceptor(new LoggingInterceptor());
@ -84,6 +87,22 @@ public class HttpUtils {
return httpClientBuilder.build(); return httpClientBuilder.build();
} }
public static class TokenHeaderInterceptor implements Interceptor {
@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
String tokenTemp = (String) SPUtils.get(context, Contans.LOGIN_TOKEN, "");
if (!TextUtils.isEmpty(tokenTemp)) {
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);
String credential = "Bearer " + token;
Request originalRequest = chain.request();
Request updateRequest = originalRequest.newBuilder().header("Authorization", credential).build();
return chain.proceed(updateRequest);
}
return chain.proceed(chain.request());
}
}
public static class LoggingInterceptor implements Interceptor { public static class LoggingInterceptor implements Interceptor {
@Override @Override
public Response intercept(Chain chain) throws IOException { public Response intercept(Chain chain) throws IOException {

@ -76,10 +76,10 @@ public class NoProgresshttpUtils {
String credential = "Bearer " + token; String credential = "Bearer " + token;
request.addHeader("Authorization", credential); request.addHeader("Authorization", credential);
showLog(request.url()); showLog(request.url());
if(!TextUtils.isEmpty(token)){ // if(!TextUtils.isEmpty(token)){
showLog(credential); // showLog(credential);
showLog(new Gson().toJson(request.headers())); // showLog(new Gson().toJson(request.headers()));
} // }
} }
mQueue.add(what, request, new HttpResponseListenerNoProgress<T>(mActivity, request, callback)); mQueue.add(what, request, new HttpResponseListenerNoProgress<T>(mActivity, request, callback));
} }

@ -85,10 +85,10 @@ public class NohttpUtils {
String credential = "Bearer " + token; String credential = "Bearer " + token;
request.addHeader("Authorization", credential); request.addHeader("Authorization", credential);
showLog(request.url()); showLog(request.url());
if(!TextUtils.isEmpty(token)){ // if(!TextUtils.isEmpty(token)){
showLog(credential); // showLog(credential);
//showLog(new Gson().toJson(request.headers())); // showLog(new Gson().toJson(request.headers()));
} // }
} }
mQueue.add(what, request, new HttpResponseListener<T>(mActivity, request, callback, canCanel, isLoading, msg)); mQueue.add(what, request, new HttpResponseListener<T>(mActivity, request, callback, canCanel, isLoading, msg));
} }
@ -101,10 +101,10 @@ public class NohttpUtils {
String credential = "Bearer " + token; String credential = "Bearer " + token;
request.addHeader("Authorization", credential); request.addHeader("Authorization", credential);
showLog(request.url()); showLog(request.url());
if(!TextUtils.isEmpty(token)){ // if(!TextUtils.isEmpty(token)){
showLog(credential); // showLog(credential);
//showLog(new Gson().toJson(request.headers())); // showLog(new Gson().toJson(request.headers()));
} // }
} }
mQueue.add(what, request, new HttpResponseListener<T>(mActivity, request, callback, true, true, "加载中...")); mQueue.add(what, request, new HttpResponseListener<T>(mActivity, request, callback, true, true, "加载中..."));
} }

@ -1,8 +1,11 @@
package com.bjzc.yfdxj.utils; package com.bjzc.yfdxj.utils;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import com.bjzc.yfdxj.contans.Contans; import com.bjzc.yfdxj.contans.Contans;
import java.io.IOException; import java.io.IOException;
@ -38,26 +41,26 @@ public class RetrofitHttpUtils {
private RetrofitHttpUtils(Context context, String url) { private RetrofitHttpUtils(Context context, String url) {
Retrofit mRetrofit = new Retrofit.Builder() Retrofit mRetrofit = new Retrofit.Builder()
.baseUrl(url) .baseUrl(url)
.client(getOkHttpClient()) .client(getOkHttpClient(context))
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build(); .build();
api = mRetrofit.create(Api.class); api = mRetrofit.create(Api.class);
RetrofitHttpUtils.context = context; RetrofitHttpUtils.context = context;
} }
public static Api getApi() { public static Api getApi(Context context) {
return getApi(Contans.IP); return getApi(Contans.IP,context);
} }
public static Api GETMAXIMOIP() { public static Api GETMAXIMOIP(Context context) {
return getApi(Contans.MAXIMOIP); return getApi(Contans.MAXIMOIP,context);
} }
public static Api getApi(String url) { public static Api getApi(String url, Context context) {
Retrofit mRetrofit = new Retrofit.Builder() Retrofit mRetrofit = new Retrofit.Builder()
.baseUrl(url) .baseUrl(url)
.client(getOkHttpClient()) .client(getOkHttpClient(context))
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build(); .build();
Api api = mRetrofit.create(Api.class); Api api = mRetrofit.create(Api.class);
@ -66,10 +69,10 @@ public class RetrofitHttpUtils {
} }
public static OkHttpClient getOkHttpClient() { public static OkHttpClient getOkHttpClient(Context context) {
RetrofitHttpUtils.context = context;
OkHttpClient.Builder httpClientBuilder = new OkHttpClient OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
.Builder(); httpClientBuilder.addNetworkInterceptor(new TokenHeaderInterceptor());
//OkHttp进行添加拦截器loggingInterceptor //OkHttp进行添加拦截器loggingInterceptor
httpClientBuilder.addInterceptor(new LoggingInterceptor()); httpClientBuilder.addInterceptor(new LoggingInterceptor());
@ -109,4 +112,20 @@ public class RetrofitHttpUtils {
return response; return response;
} }
} }
public static class TokenHeaderInterceptor implements Interceptor {
@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
String tokenTemp = (String) SPUtils.get(context, Contans.LOGIN_TOKEN, "");
if (!TextUtils.isEmpty(tokenTemp)) {
String token = RSAUtils.decryptBASE64StrLocal(tokenTemp);
String credential = "Bearer " + token;
Request originalRequest = chain.request();
Request updateRequest = originalRequest.newBuilder().header("Authorization", credential).build();
return chain.proceed(updateRequest);
}
return chain.proceed(chain.request());
}
}
} }

Loading…
Cancel
Save