6
0
Fork 0

加入用户关系更新

master
nishengli 1 year ago
parent 4f0be77c2d
commit 5cbb5ed85a
  1. 4
      src/main/java/com/tsl3060/open/extend/core/ApiClient.java
  2. 41
      src/main/java/com/tsl3060/open/extend/core/payload/UserRelationPayload.java
  3. 13
      src/main/java/com/tsl3060/open/extend/core/response/UserRelationResponse.java
  4. 70
      src/main/java/com/tsl3060/open/extend/core/secure/RSASecure.java

@ -6,7 +6,7 @@ import cn.hutool.core.util.XmlUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.tsl3060.open.extend.core.constant.BuildInfo;
import com.tsl3060.open.extend.core.exception.ApiException;
import com.tsl3060.open.extend.core.exception.BadResourceException;
@ -132,7 +132,7 @@ public class ApiClient {
ISecure iSecure = getSecureTool().getSecure(apiRequest.getSignType());
String signStr = iSecure.requestSign(apiRequest);
apiRequest.setSign(signStr);
String fBody = JSON.toJSONString(apiRequest);
String fBody = JSON.toJSONString(apiRequest, JSONWriter.Feature.WriteNullStringAsEmpty, JSONWriter.Feature.WriteNullListAsEmpty);
log.debug(">>> {}", fBody);
RequestBody requestBody = RequestBody.create(fBody, contentType);
/**

@ -0,0 +1,41 @@
package com.tsl3060.open.extend.core.payload;
import com.tsl3060.open.extend.core.IApiRequest;
import java.util.List;
public class UserRelationPayload extends RequestPayload implements IApiRequest {
@Override
public String path() {
return "/v1/wanshun/user/relation";
}
private String openid;
private String parentId;
private List<String> children;
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public List<String> getChildren() {
return children;
}
public void setChildren(List<String> children) {
this.children = children;
}
}

@ -0,0 +1,13 @@
package com.tsl3060.open.extend.core.response;
public class UserRelationResponse {
private boolean result;
public boolean isResult() {
return result;
}
public void setResult(boolean result) {
this.result = result;
}
}

@ -1,14 +1,13 @@
package com.tsl3060.open.extend.core.secure;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.alibaba.fastjson2.JSONObject;
import com.tsl3060.open.extend.core.*;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
@ -36,33 +35,53 @@ public class RSASecure implements ISecure {
}
private String object2LinkStr(Object ob) {
List<String> payloadStr = new ArrayList<>();
if (ob != null) {
JSONObject j = JSONObject.from(ob);
//排序
Set<String> _keys = j.keySet();
List<String> keys = _keys.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
for (String key : keys) {
if (j.get(key) != null) {
Object v = j.get(key);
String vx;
if (v instanceof Double) {
vx = String.format("%s", v);
} else if (v instanceof Float) {
vx = String.format("%s", v);
} else if (v instanceof Boolean) {
vx = String.format("%s", v);
} else if (v instanceof BigDecimal) {
vx = String.format("%s", v);
} else {
vx = String.valueOf(v);
if (ob == null) {
return "";
}
if (ob instanceof String) {
if (StrUtil.isEmpty(ob.toString())) {
return "";
}
payloadStr.add(String.format("%s=%s", key, vx));
}
JSONObject root = JSONObject.from(ob);
Set<String> _keys = root.keySet();
List<String> keys = new ArrayList<>(_keys);
List<String> keyValuePairs = new ArrayList<>();
keys.forEach(key -> {
Object valueNode = root.get(key);
String valueStr;
if (valueNode instanceof Number) {
valueStr = String.format("%s", valueNode);
} else if (valueNode instanceof Boolean) {
valueStr = String.format("%s", valueNode);
} else if (valueNode instanceof List) {
List<String> arrayValues = new ArrayList<>();
List<?> values = (List<?>) valueNode;
values.forEach(value -> {
if (value instanceof String) {
arrayValues.add(String.format("%s", value));
}else{
arrayValues.add(object2LinkStr(value));
}
});
valueStr = String.join(",", arrayValues);
} else {
if(valueNode==null){
valueNode="";
}
valueStr = String.format("%s", valueNode);
}
return CollectionUtil.join(payloadStr, "&");
keyValuePairs.add(String.format("%s=%s",key,valueStr));
});
return keyValuePairs.stream()
.sorted()
.collect(Collectors.joining("&"));
}
public String sign(String content, String charset) {
@ -110,7 +129,6 @@ public class RSASecure implements ISecure {
request.getTime(),
waitStr
);
log.debug("req: {}", content);
return this.sign(content, request.getCharset());

Loading…
Cancel
Save