nilupeng
2022-08-09 c504d9b9e12cad60dec083012fb5eeee16d9efeb
app/src/main/java/com/runt/open/mvvm/retrofit/converter/DecryptGsonResponseBodyConverter.java
@@ -2,16 +2,15 @@
import android.util.Log;
import com.runt.open.mvvm.data.BaseApiResult;
import com.runt.open.mvvm.util.GsonUtils;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.runt.open.mvvm.data.HttpApiResult;
import com.runt.open.mvvm.util.GsonUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -51,13 +50,13 @@
            response = decryptJsonStr(val);//解密
        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
            e.printStackTrace();
            BaseApiResult apiResult = new BaseApiResult<>();
            HttpApiResult apiResult = new HttpApiResult<>();
            apiResult.code = 412;
            apiResult.msg = "解密数据出错"+e.getMessage();
            response = new Gson().toJson(apiResult);
        } catch (JSONException e) {
            e.printStackTrace();
            BaseApiResult apiResult = new BaseApiResult<>();
            HttpApiResult apiResult = new HttpApiResult<>();
            apiResult.code = 414;
            apiResult.msg = "非标准json";
            response = new Gson().toJson(apiResult);
@@ -84,11 +83,11 @@
     */
    protected String decryptJsonStr(String body) throws Exception {
        Log.e("Converter","decryptJsonStr body:"+body);
        if(body.indexOf("{") == 0) {
        /*if(body.indexOf("{") == 0) {
            JSONObject json = new JSONObject(body);
            body = json.toString();
            //body = RSAUtils.decrypt(json.getString(ENCRYPT), RSAUtils.getPublicKey(RSAUtils.PUBLIC_KEY));//
        }
        }*/
        return transHump? GsonUtils.toHumpJson(body):body;
    }