新的ui及数据解密基本完成
This commit is contained in:
parent
e1b9e3348c
commit
6628f66b3f
@ -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);
|
||||
}
|
||||
|
||||
//公共参数
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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>>() {
|
||||
|
74
common/src/main/java/com/yunbao/common/utils/AesUtils.java
Normal file
74
common/src/main/java/com/yunbao/common/utils/AesUtils.java
Normal 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();
|
||||
}
|
||||
}
|
@ -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")),
|
||||
|
Loading…
Reference in New Issue
Block a user