|
|
@@ -1,6 +1,8 @@
|
|
|
package com.zsElectric.boot.common.util.electric;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.zsElectric.boot.common.constant.ConnectivityConstants;
|
|
|
import com.zsElectric.boot.common.util.AESCryptoUtil;
|
|
|
@@ -11,6 +13,7 @@ import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
@@ -24,6 +27,13 @@ public class ChargingUtil {
|
|
|
@Resource
|
|
|
private OkHttpUtil okHttpUtil;
|
|
|
|
|
|
+ /**
|
|
|
+ * 请求封装
|
|
|
+ * @param url
|
|
|
+ * @param queryParms
|
|
|
+ * @param tokenRequired
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public JsonObject chargingRequest(String url, Map<String,Object> queryParms,boolean tokenRequired) {
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
if(tokenRequired){
|
|
|
@@ -51,4 +61,51 @@ public class ChargingUtil {
|
|
|
throw new RuntimeException("调用第三方接口发生异常", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 响应解密
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JsonObject responseDecode(JsonObject response){
|
|
|
+
|
|
|
+ try {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ ResponseParmsEntity responseParms = gson.fromJson(response, ResponseParmsEntity.class);
|
|
|
+ boolean verify = HmacMD5Util.verify(responseParms.getData(), ConnectivityConstants.PLATFORM_DATA_SECRET, responseParms.getSig());
|
|
|
+ if (!verify) {
|
|
|
+ log.error("第三方接口响应数据签名验证失败");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (responseParms.getRet() != 0){
|
|
|
+ switch (responseParms.getRet()) {
|
|
|
+ case -1:
|
|
|
+ log.error("系统繁忙,此时请求方稍后重试");
|
|
|
+ break;
|
|
|
+ case 4001:
|
|
|
+ log.error("签名错误");
|
|
|
+ break;
|
|
|
+ case 4002:
|
|
|
+ log.error("Token错误");
|
|
|
+ break;
|
|
|
+ case 4003:
|
|
|
+ log.error("参数不合法,缺少必需的示例:OperatorID、Sig、TimeStamp、Data、Seq五个参数");
|
|
|
+ break;
|
|
|
+ case 4004:
|
|
|
+ log.error("请求的业务参数不合法,各接口定义自己的必须参数");
|
|
|
+ break;
|
|
|
+ case 500:
|
|
|
+ log.error("系统错误");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String decodeData = AESCryptoUtil.decrypt(responseParms.getData(), ConnectivityConstants.PLATFORM_DATA_SECRET,
|
|
|
+ ConnectivityConstants.PLATFORM_DATA_SECRET_IV);
|
|
|
+ return gson.fromJson(decodeData, JsonObject.class);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException("第三方接口响应发生异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|