新的ui及数据解密基本完成

This commit is contained in:
ningwenqiang 2024-10-25 15:20:32 +08:00
parent e1b9e3348c
commit 6628f66b3f
9 changed files with 242 additions and 8 deletions

View File

@ -80,7 +80,7 @@ public class API extends BaseApi {
.addInterceptor(initQuery(isNeedUid, isNeedToken, CommonAppContext.sInstance.getApplicationContext()))
.addInterceptor(loggingInterceptor);
return create(builder.build(),
GsonConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class);
JavaConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class);
}
//公共参数

View File

@ -34,7 +34,7 @@ public class HttpClient {
private String mUrl;
private HttpClient() {
mUrl = CommonAppConfig.HOST + "/api/public/?service=";
mUrl = CommonAppConfig.HOST + "/";//去掉 api/public/?service="
}
public static HttpClient getInstance() {

View File

@ -0,0 +1,97 @@
package com.yunbao.common.http;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
import com.yunbao.common.utils.AesUtils;
import com.yunbao.common.utils.L;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Base64;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
public final class JavaConverterFactory extends Converter.Factory {
/**
* Create an instance using a default {@link Gson} instance for conversion. Encoding to JSON and
* decoding from JSON (when no charset is specified by a header) will use UTF-8.
*/
public static JavaConverterFactory create() {
return create(new Gson());
}
/**
* Create an instance using {@code gson} for conversion. Encoding to JSON and
* decoding from JSON (when no charset is specified by a header) will use UTF-8.
*/
public static JavaConverterFactory create(Gson gson) {
return new JavaConverterFactory(gson);
}
private final Gson gson;
private JavaConverterFactory(Gson gson) {
if (gson == null) throw new NullPointerException("gson == null");
this.gson = gson;
}
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
return new JsonResponseBodyConverter<>(gson, adapter);
}
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return super.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
}
final class JsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
private final Gson gson;
private final TypeAdapter<T> adapter;
JsonResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
this.gson = gson;
this.adapter = adapter;
}
@Override
public T convert(ResponseBody value) throws IOException {
String response = value.string();
String allResponseData;
L.e("解密前::" + response);
JSONObject jsonObject = JSONObject.parseObject(response);
allResponseData = jsonObject.getString("data");
if (allResponseData.indexOf(":") <= 0) {
byte[] decodedData = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
decodedData = Base64.getDecoder().decode(allResponseData);
}
response = AesUtils.decryptToString(decodedData);
jsonObject.put("data", JSONObject.parseObject(response));
response = JSON.toJSONString(jsonObject);
L.e("解密后::" + response);
//获取加密数据解密之后再让adapter去处理json串解析具体的数据就可以了
try {
return adapter.fromJson(response);
} catch (Exception e) {
e.printStackTrace();
} finally {
value.close();
}
} else {
return adapter.fromJson(response);
}
return null;
}
}
}

View File

@ -1,5 +1,18 @@
package com.yunbao.common.http;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.GsonUtils;
import com.google.gson.Gson;
import com.yunbao.common.bean.AdBean;
import com.yunbao.common.utils.AesUtils;
import com.yunbao.common.utils.L;
import java.util.Base64;
import java.util.List;
/**
* Created by cxf on 2017/8/5.
*/
@ -7,7 +20,7 @@ package com.yunbao.common.http;
public class JsonBean {
private int ret;
private String msg;
private Data data;
private String data;
public int getRet() {
return ret;
@ -26,10 +39,47 @@ public class JsonBean {
}
public Data getData() {
return data;
L.e("data:" + data);
if (data.indexOf(":") > 0) {
L.e("未加密::" + data);
return JSON.parseObject(data, Data.class);
//return GsonUtils.fromJson(data, Data.class);
} else {
Data resultData = new Data();
byte[] decodedData = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
decodedData = Base64.getDecoder().decode(data);
}
String decryptedText = AesUtils.decryptToString(decodedData);
L.e("解码前:" + data);
L.e("解码前-转成base64" + decodedData);
L.e("解码前-解密後:" + decryptedText);
JSONObject object = JSON.parseObject(decryptedText);
try {
JSONArray jsonArray = object.getJSONArray("info");
String[] array = new String[jsonArray.size()];
for (int i = 0; i < array.length; i++) {
array[i] = jsonArray.getString(i);
}
resultData.setInfo(array);
resultData.setCode(object.getInteger("code"));
resultData.setMsg(object.getString("msg"));
} catch (Exception e) {
try {
String[] array = new String[1];
array[0] = object.getString("info");
resultData.setInfo(array);
resultData.setCode(object.getInteger("code"));
resultData.setMsg(object.getString("msg"));
} catch (JSONException ex) {
L.e("字符串格式错误");
}
}
return resultData;
}
}
public void setData(Data data) {
public void setData(String data) {
this.data = data;
}
}

View File

@ -55,6 +55,7 @@ import com.yunbao.common.bean.LiveRoomVoteModel;
import com.yunbao.common.bean.LiveStetUpStatusModel;
import com.yunbao.common.bean.LiveTaskModel;
import com.yunbao.common.bean.LiveUserMailBoxModel;
import com.yunbao.common.bean.MainMessageChatListTimer;
import com.yunbao.common.bean.MedalAchievementModel;
import com.yunbao.common.bean.MessageChatIsAnchor;
import com.yunbao.common.bean.MessageChatUserBean;
@ -1068,7 +1069,6 @@ public interface PDLiveApi {
@Query("room_name") String roomName,
@Query("golden_bean_number") String goldenBeanNumber,
@Query("currency_type") String currencyType,
@Query("activity_game") String isActivity,
@Query("game_id") String gameId);
/**
@ -1488,6 +1488,17 @@ public interface PDLiveApi {
Observable<ResponseModel<BaseModel>> ballClearanceTableStatus(
@Query("room_id")String roomId
);
@GET("/ylahuoququanbuxinxi")
Observable<ResponseModel<List<MessageChatUserBean>>> getOtherList(@Query("ids") String uids);
@GET("/ylapdlzhuboyonghuguanxi")
Observable<ResponseModel<List<String>>> getRelation(@Query("type") String type);
@GET("/ylahuoquzhidingyonghzhiboxinxi")
Observable<ResponseModel<List<MainMessageChatListTimer>>> getIsLook(@Query("ids") String uids);
// @GET("/ylahuoquyouxijiesuanjifen")
// Observable<ResponseModel<List<SudActivityGameInfoBean>>> ballClearanceTableGetResultScore(
// @Query("room_id")String roomId

View File

@ -2358,6 +2358,7 @@ public class LiveNetManager {
}).isDisposed();
}
//TODO 合并后有POPO了一个参数
public void createSudRoom(String roomName, String goldenBeanNumber, String currencyType, String gameId, HttpCallback<CreateSudRoomModel> callback) {
API.get().pdLiveApi(mContext)
.createSudRoom(roomName, goldenBeanNumber, currencyType, gameId)

View File

@ -13,6 +13,7 @@ import com.yunbao.common.http.API;
import com.yunbao.common.http.ResponseData;
import com.yunbao.common.http.ResponseModel;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
import com.yunbao.common.utils.WordUtil;
import java.util.HashMap;
@ -55,7 +56,7 @@ public class MainNetManager {
* @param callback 网络请求回调
*/
public void login(String phoneNum, String pwd, String uuid, HttpCallback<IMLoginModel> callback) {
API.get().pdLiveApi(mContext).loginByManager(phoneNum, pwd, uuid, "", "Android", WordUtil.isNewZh()?"chinese":"english")
API.get().pdLiveApi(mContext).loginByManager(phoneNum, pwd, uuid, "", "Android", WordUtil.isNewZh()?"chinese":"english",RongcloudIMManager.RONG_IM_KEY)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<IMLoginModel>>() {

View File

@ -0,0 +1,74 @@
package com.yunbao.common.utils;
import com.alibaba.fastjson.JSON;
import java.io.UnsupportedEncodingException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class AesUtils {
/**
* 使用AES/ECB/PKCS5Padding模式解密数据
*
* @param encryptedData 加密后的字节数组Base64解码后的结果如果原始数据是Base64编码的话
* @param keyBytes AES密钥16/24/32字节长对应AES-128/192/256
* @return 解密后的明文字节数组如果解密失败则返回null
*/
public static byte[] decrypt(byte[] encryptedData, byte[] keyBytes) {
try {
// 创建密钥规格
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES-128-ECB");
// 获取Cipher实例并初始化为解密模式
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec);
// 执行解密
byte[] decryptedBytes = cipher.doFinal(encryptedData);
// 返回解密后的字节数组
return decryptedBytes;
} catch (Exception e) {
e.printStackTrace();
return null; // 解密失败时返回null
}
}
/**
* 如果需要将解密后的字节数组转换为字符串注意这可能会导致数据丢失或乱码
*
* @param encryptedData 加密后的字节数组或Base64解码后的结果
* @return 解密后的字符串如果解密失败则返回null
*/
public static String decryptToString(byte[] encryptedData) {
byte[] decryptedBytes = decrypt(encryptedData,"LhHBfcsN2VmBpHCn".getBytes());
if (decryptedBytes != null) {
// 尝试将字节数组转换为字符串使用指定的字符集
try {
return decodeUnicode(new String(decryptedBytes, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
return null;
}
public static String decodeUnicode(String unicode) {
/* StringBuilder sb = new StringBuilder();
for (int i = 0; i < unicode.length();) {
if (unicode.charAt(i) == '\\') {
if (i + 5 < unicode.length()) {
String codePointStr = unicode.substring(i + 2, i + 6);
try {
int codePoint = Integer.parseInt(codePointStr, 16);
sb.append((char) codePoint);
i += 6;
continue;
} catch (NumberFormatException e) {
// Handle format error
}
}
}
sb.append(unicode.charAt(i++));
}*/
return JSON.parseObject(unicode).toString();
}
}

View File

@ -10,7 +10,7 @@ ext {
]
manifestPlaceholders = [
//
serverHost : "https://napi.yaoulive.com",
serverHost : "https://api.yolaashow.com",//https://api.yolaashow.com https://napi.yaoulive.com
//
testServerHost : "https://ceshi.yaoulive.com",
buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")),