接口配置解码
This commit is contained in:
parent
2102a3bfc2
commit
2e1eb3c7b4
@ -80,7 +80,7 @@ public class API extends BaseApi {
|
|||||||
.addInterceptor(initQuery(isNeedUid, isNeedToken, CommonAppContext.sInstance.getApplicationContext()))
|
.addInterceptor(initQuery(isNeedUid, isNeedToken, CommonAppContext.sInstance.getApplicationContext()))
|
||||||
.addInterceptor(loggingInterceptor);
|
.addInterceptor(loggingInterceptor);
|
||||||
return create(builder.build(),
|
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 String mUrl;
|
||||||
|
|
||||||
private HttpClient() {
|
private HttpClient() {
|
||||||
mUrl = CommonAppConfig.HOST + "/api/public/?service=";
|
mUrl = CommonAppConfig.HOST + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpClient getInstance() {
|
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);
|
||||||
|
if(jsonObject!=null){
|
||||||
|
allResponseData = jsonObject.getString("data");
|
||||||
|
if(allResponseData!=null){
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,18 @@
|
|||||||
package com.yunbao.common.http;
|
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.
|
* Created by cxf on 2017/8/5.
|
||||||
*/
|
*/
|
||||||
@ -7,7 +20,7 @@ package com.yunbao.common.http;
|
|||||||
public class JsonBean {
|
public class JsonBean {
|
||||||
private int ret;
|
private int ret;
|
||||||
private String msg;
|
private String msg;
|
||||||
private Data data;
|
private String data;
|
||||||
|
|
||||||
public int getRet() {
|
public int getRet() {
|
||||||
return ret;
|
return ret;
|
||||||
@ -26,10 +39,43 @@ public class JsonBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Data getData() {
|
public Data getData() {
|
||||||
return data;
|
if(data.indexOf(":")>0){
|
||||||
|
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);
|
||||||
|
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"));
|
||||||
|
L.e("这是一个数组");
|
||||||
|
}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"));
|
||||||
|
L.e("这是一个对象");
|
||||||
|
} catch (JSONException ex) {
|
||||||
|
L.e("字符串格式错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(Data data) {
|
public void setData(String data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -34,20 +34,39 @@ public class AesUtils {
|
|||||||
* 如果需要将解密后的字节数组转换为字符串(注意:这可能会导致数据丢失或乱码)
|
* 如果需要将解密后的字节数组转换为字符串(注意:这可能会导致数据丢失或乱码)
|
||||||
*
|
*
|
||||||
* @param encryptedData 加密后的字节数组(或Base64解码后的结果)
|
* @param encryptedData 加密后的字节数组(或Base64解码后的结果)
|
||||||
* @param keyBytes AES密钥
|
|
||||||
* @param charset 用于将解密后的字节数组转换为字符串的字符集
|
|
||||||
* @return 解密后的字符串,如果解密失败则返回null
|
* @return 解密后的字符串,如果解密失败则返回null
|
||||||
*/
|
*/
|
||||||
public static String decryptToString(byte[] encryptedData, byte[] keyBytes, String charset) {
|
public static String decryptToString(byte[] encryptedData) {
|
||||||
byte[] decryptedBytes = decrypt(encryptedData, keyBytes);
|
byte[] decryptedBytes = decrypt(encryptedData,"LhHBfcsN2VmBpHCn".getBytes());
|
||||||
if (decryptedBytes != null) {
|
if (decryptedBytes != null) {
|
||||||
// 尝试将字节数组转换为字符串(使用指定的字符集)
|
// 尝试将字节数组转换为字符串(使用指定的字符集)
|
||||||
try {
|
try {
|
||||||
return new String(decryptedBytes, charset);
|
return decodeUnicode(new String(decryptedBytes, "UTF-8"));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
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 sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ ext {
|
|||||||
serverHost : "https://napi.yaoulive.com",
|
serverHost : "https://napi.yaoulive.com",
|
||||||
|
|
||||||
buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")),
|
buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")),
|
||||||
testServerHost : "https://ceshi.yaoulive.com",
|
testServerHost : "https://api.poyoshow.com",
|
||||||
|
|
||||||
//百度语音识别
|
//百度语音识别
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ import com.yunbao.common.manager.IMLoginManager;
|
|||||||
import com.yunbao.common.manager.NoviceInstructorManager;
|
import com.yunbao.common.manager.NoviceInstructorManager;
|
||||||
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
||||||
import com.yunbao.common.utils.DialogUitl;
|
import com.yunbao.common.utils.DialogUitl;
|
||||||
|
import com.yunbao.common.utils.L;
|
||||||
import com.yunbao.common.utils.RouteUtil;
|
import com.yunbao.common.utils.RouteUtil;
|
||||||
import com.yunbao.common.utils.ToastUtil;
|
import com.yunbao.common.utils.ToastUtil;
|
||||||
import com.yunbao.common.http.LiveHttpUtil;
|
import com.yunbao.common.http.LiveHttpUtil;
|
||||||
@ -240,7 +241,8 @@ public class RegisterActivity extends AbsActivity {
|
|||||||
webSettings.setJavaScriptEnabled(true);
|
webSettings.setJavaScriptEnabled(true);
|
||||||
webview.addJavascriptInterface(new JsBridge(), "jsBridge");
|
webview.addJavascriptInterface(new JsBridge(), "jsBridge");
|
||||||
// 也可以加载本地html(webView.loadUrl("file:///android_asset/xxx.html"))
|
// 也可以加载本地html(webView.loadUrl("file:///android_asset/xxx.html"))
|
||||||
webview.loadUrl(CommonAppConfig.HOST + "/h5/live/TCaptcha.html" + "?isZh=" + (WordUtil.isNewZh() ? "1" : 0));
|
webview.loadUrl(CommonAppConfig.HOST + "/TCaptcha.html" + "?isZh=" + (WordUtil.isNewZh() ? "1" : 0));
|
||||||
|
L.e(CommonAppConfig.HOST + "/h5/live/TCaptcha.html" + "?isZh=" + (WordUtil.isNewZh() ? "1" : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ public class MainHttpUtil {
|
|||||||
* 获取用户钱
|
* 获取用户钱
|
||||||
*/
|
*/
|
||||||
public static void getBalance(HttpCallback callback) {
|
public static void getBalance(HttpCallback callback) {
|
||||||
HttpClient.getInstance().get("huoquyonghuyue", "huoquyonghuyue")
|
HttpClient.getInstance().get("chaxunyonghuyue", "chaxunyonghuyue")
|
||||||
.execute(callback);
|
.execute(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder {
|
|||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
decodedData = Base64.getDecoder().decode(aesStr);
|
decodedData = Base64.getDecoder().decode(aesStr);
|
||||||
}
|
}
|
||||||
String decryptedText = AesUtils.decryptToString(decodedData, "LhHBfcsN2VmBpHCn".getBytes(), "UTF-8");
|
String decryptedText = AesUtils.decryptToString(decodedData);
|
||||||
L.e("decryptedText:"+decryptedText);
|
L.e("decryptedText:"+decryptedText);
|
||||||
}
|
}
|
||||||
public void setCurPosition(int position) {
|
public void setCurPosition(int position) {
|
||||||
|
@ -32,7 +32,7 @@ public class VideoUploadFtpImpl implements VideoUploadStrategy {
|
|||||||
if (videoUploadBean == null || callback == null) {
|
if (videoUploadBean == null || callback == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PostRequest<String> postRequest = OkGo.<String>post("http://www.mytoday.net/api/public/?service=Video.uploadvideo")
|
PostRequest<String> postRequest = OkGo.<String>post("http://www.mytoday.net/Video.uploadvideo")
|
||||||
.params("uid", "13640")
|
.params("uid", "13640")
|
||||||
.params("token", "0e6371c5a642e8b48748a4d994303473")
|
.params("token", "0e6371c5a642e8b48748a4d994303473")
|
||||||
.params("file", videoUploadBean.getVideoFile())
|
.params("file", videoUploadBean.getVideoFile())
|
||||||
|
Loading…
Reference in New Issue
Block a user