Commit 4f0360ab authored by 33's avatar 33

Api版权接口

parent d46f29a4
...@@ -15,12 +15,15 @@ public class BaseOO<T> { ...@@ -15,12 +15,15 @@ public class BaseOO<T> {
@NotBlank(message = "appKey不能为空") @NotBlank(message = "appKey不能为空")
@ApiModelProperty(value = "appKey") @ApiModelProperty(value = "appKey")
private String appKey; private String appKey;
@NotBlank(message = "业务id不能为空") @NotBlank(message = "业务id不能为空")
@ApiModelProperty(value = "业务id") @ApiModelProperty(value = "业务id")
private String bizId; private String bizId;
@NotBlank(message = "签名不能为空") @NotBlank(message = "签名不能为空")
@ApiModelProperty("签名") @ApiModelProperty("签名")
private String signature; private String signature;
@NotNull(message = "数据不能为空") @NotNull(message = "数据不能为空")
@ApiModelProperty("数据") @ApiModelProperty("数据")
private T data; private T data;
......
...@@ -107,4 +107,19 @@ public class CopyrightOO { ...@@ -107,4 +107,19 @@ public class CopyrightOO {
@ApiModelProperty("内容") @ApiModelProperty("内容")
private String content; private String content;
public void setOpusCompleteDate(Date opusCompleteDate) {
if (opusCompleteDate == null) {
this.opusCompleteDate = new Date(0);
return;
}
this.opusCompleteDate = opusCompleteDate;
}
public void setFirstPublishDate(Date firstPublishDate) {
if (firstPublishDate == null) {
this.firstPublishDate = new Date(0);
return;
}
this.firstPublishDate = firstPublishDate;
}
} }
...@@ -76,4 +76,20 @@ public class CopyrightOwnerOO { ...@@ -76,4 +76,20 @@ public class CopyrightOwnerOO {
@ApiModelProperty(value = "委托证明") @ApiModelProperty(value = "委托证明")
private String entrustProve; private String entrustProve;
public void setEffectiveStartDate(Date effectiveStartDate) {
if (effectiveStartDate == null) {
this.effectiveStartDate = new Date(0);
return;
}
this.effectiveStartDate = effectiveStartDate;
}
public void setEffectiveEndDate(Date effectiveEndDate) {
if (effectiveEndDate == null) {
this.effectiveEndDate = new Date(0);
return;
}
this.effectiveEndDate = effectiveEndDate;
}
} }
package com.fzm.common.utils; package com.fzm.common.utils;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONUtil;
import com.fzm.common.enums.ResultCode; import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException; import com.fzm.common.exception.GlobalException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
...@@ -13,26 +20,95 @@ import java.util.TreeMap; ...@@ -13,26 +20,95 @@ import java.util.TreeMap;
*/ */
public class OpenSignUtils { public class OpenSignUtils {
public static void verify(String appKey, String appKeySecret, String bizId, String bizJson, String signature) { public static void verify(String appKey, String appKeySecret, String bizId, Object obj, String signature) {
Map<String, String> param = new TreeMap<>(); TreeMap<String, Object> param = new TreeMap<>();
param.put("appKey", appKey); param.put("appKey", appKey);
param.put("appKeySecret", appKeySecret); param.put("appKeySecret", appKeySecret);
param.put("bizId", bizId); param.put("bizId", bizId);
param.put("bizJson", bizJson);
StringBuilder sb = new StringBuilder(); String mapToStr = mapToStr(toTreeMap(obj));
for (Map.Entry<String, String> entry : param.entrySet()) { String bizHash = SecureUtil.md5(mapToStr);
String key = entry.getKey(); param.put("bizHash", bizHash);
String value = entry.getValue();
sb.append(key).append("=").append(value).append("&"); mapToStr = mapToStr(param);
}
String signStr = sb.deleteCharAt(sb.length() - 1).toString();
String md5 = SecureUtil.md5(signStr); String md5 = SecureUtil.md5(mapToStr);
boolean equals = signature.equals(md5); boolean equals = signature.equals(md5);
if (!equals) { if (!equals) {
throw GlobalException.newException(ResultCode.signature_wrong); throw GlobalException.newException(ResultCode.signature_wrong);
} }
} }
public static TreeMap<String, Object> toTreeMap(Object obj) {
return JSONUtil.toBean(JSONUtil.toJsonStr(obj), new TypeReference<TreeMap<String, Object>>() {
}, true);
}
private static String mapToStr(TreeMap<String, Object> treeMap) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Object> entry : treeMap.entrySet()) {
String k = entry.getKey();
Object v = entry.getValue();
if (v instanceof String) {
sb.append(k).append("=").append(v).append("&");
continue;
}
if (k.endsWith("Date")) {
long v1 = Long.parseLong(v.toString());
String s = "";
if (v1 > 0) {
s = dateFormat(timestamp2DateTime(v1));
}
sb.append(k).append("=").append(s).append("&");
continue;
}
if (v instanceof Integer) {
sb.append(k).append("=").append(v).append("&");
continue;
}
if (v instanceof Long) {
sb.append(k).append("=").append(v).append("&");
continue;
}
if (v == null) {
sb.append(k).append("=").append("&");
continue;
}
if (v instanceof List) {
List list = (List) v;
Object o1 = list.get(0);
if (o1 instanceof Integer) {
sb.append(k).append("=").append(list).append("&");
continue;
}
StringBuilder sbSub = new StringBuilder();
for (Object o : list) {
TreeMap<String, Object> map = toTreeMap(o);
sbSub.append(mapToStr(map)).append("&");
}
String sbSubStr = sbSub.deleteCharAt(sbSub.length() - 1).toString();
String md5 = SecureUtil.md5(sbSubStr);
sb.append(k).append("=").append(md5).append("&");
}
}
return sb.deleteCharAt(sb.length() - 1).toString();
}
private static final DateTimeFormatter ymd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static LocalDateTime timestamp2DateTime(long timestamp) {
Instant instant = Instant.ofEpochMilli(timestamp);
return LocalDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai"));
}
public static String dateFormat(LocalDateTime dateTime) {
return dateTime.format(ymd);
}
} }
package com.fzm.portal.controller.open; package com.fzm.portal.controller.open;
import cn.hutool.json.JSONUtil;
import com.fzm.common.constant.SystemConstant; import com.fzm.common.constant.SystemConstant;
import com.fzm.common.entity.vo.CopyrightStateVo; import com.fzm.common.entity.vo.CopyrightStateVo;
import com.fzm.common.enums.CopyrightApplyState; import com.fzm.common.enums.CopyrightApplyState;
...@@ -48,18 +47,18 @@ public class CopyrightApiController { ...@@ -48,18 +47,18 @@ public class CopyrightApiController {
throw GlobalException.newException(ResultCode.VALIDATE_FAILED); throw GlobalException.newException(ResultCode.VALIDATE_FAILED);
} }
String signature = baseOO.getSignature();
if (StringUtils.isBlank(signature)) {
throw GlobalException.newException(ResultCode.signature_wrong);
}
String bizId = baseOO.getBizId(); String bizId = baseOO.getBizId();
if (StringUtils.isBlank(bizId)) { if (StringUtils.isBlank(bizId)) {
throw GlobalException.newException(ResultCode.VALIDATE_FAILED); throw GlobalException.newException(ResultCode.VALIDATE_FAILED);
} }
String signature = baseOO.getSignature();
if (StringUtils.isBlank(signature)) {
throw GlobalException.newException(ResultCode.signature_wrong);
}
CopyrightOO copyrightOO = baseOO.getData(); CopyrightOO copyrightOO = baseOO.getData();
OpenSignUtils.verify(appKey, openKeyDO.getAppKeySecret(), bizId, JSONUtil.toJsonStr(copyrightOO), signature); OpenSignUtils.verify(appKey, openKeyDO.getAppKeySecret(), bizId, copyrightOO, signature);
CopyrightApiDO apiDO = copyrightApiService.getByAppKeyAndBizId(appKey, bizId); CopyrightApiDO apiDO = copyrightApiService.getByAppKeyAndBizId(appKey, bizId);
if (apiDO != null) { if (apiDO != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment