package com.safeluck.aaej.app.utils.feign;
|
|
|
import com.google.gson.Gson;
|
import com.google.gson.JsonIOException;
|
import com.safeluck.aaej.app.utils.PayJsonResult;
|
import com.safeluck.aaej.app.utils.PayMessageEncryptor;
|
import com.safeluck.aaej.base.utils.DefaultGson;
|
import feign.Response;
|
import feign.Util;
|
import feign.codec.Decoder;
|
import ikidou.reflect.TypeBuilder;
|
import org.springframework.util.StreamUtils;
|
|
import java.io.IOException;
|
import java.lang.reflect.Type;
|
|
public class FeignGsonDecoder implements Decoder {
|
private Gson gson = DefaultGson.get();
|
|
PayMessageEncryptor payMessageEncryptor = new PayMessageEncryptor();
|
|
public Object decode(Response response, Type type) throws IOException {
|
if (response.status() == 404) {
|
return Util.emptyValueOf(type);
|
} else if (response.body() == null) {
|
return null;
|
} else {
|
// Reader reader = response.body().asReader();
|
|
// PayJsonResult var4;
|
try {
|
byte[] bytes = StreamUtils.copyToByteArray(response.body().asInputStream());
|
String b64_string = payMessageEncryptor.decrypt(bytes);
|
|
// String b64_string = new String(encrypt_bytes,"utf-8");
|
if(type==String.class)
|
{
|
return b64_string;
|
}
|
Type newtype = TypeBuilder.newInstance(PayJsonResult.class).addTypeParam(type).build();
|
|
PayJsonResult var4 = this.gson.fromJson(b64_string, newtype);
|
if(var4.getErrorFlag())
|
{
|
throw new RuntimeException(var4.getErrorMessage());
|
}
|
return var4.getData();
|
// var4 = this.gson.fromJson(reader, type);
|
} catch (JsonIOException var8) {
|
if (var8.getCause() != null && var8.getCause() instanceof IOException) {
|
throw (IOException)IOException.class.cast(var8.getCause());
|
}
|
|
throw var8;
|
} finally {
|
// Util.ensureClosed(reader);
|
}
|
|
|
}
|
}
|
}
|