|
@@ -16,12 +16,19 @@
|
|
|
*/
|
|
*/
|
|
|
package com.trade.purchase.extra.service.impl;
|
|
package com.trade.purchase.extra.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.smecloud.apigw.client.ApigwClient;
|
|
|
|
|
+import com.smecloud.apigw.constant.HttpMethod;
|
|
|
|
|
+import com.smecloud.apigw.model.ApiRequest;
|
|
|
|
|
+import com.smecloud.apigw.model.ApiResult;
|
|
|
|
|
+import com.smecloud.apigw.model.ApigwConfig;
|
|
|
import com.smecloud.apigw.util.SHAUtil;
|
|
import com.smecloud.apigw.util.SHAUtil;
|
|
|
|
|
+import com.trade.purchase.config.MD5Util;
|
|
|
import com.trade.purchase.extra.entity.Claim;
|
|
import com.trade.purchase.extra.entity.Claim;
|
|
|
import com.trade.purchase.extra.entity.ClaimItem;
|
|
import com.trade.purchase.extra.entity.ClaimItem;
|
|
|
import com.trade.purchase.extra.entity.JdTenant;
|
|
import com.trade.purchase.extra.entity.JdTenant;
|
|
@@ -539,8 +546,7 @@ public class ClaimServiceImpl extends ServiceImpl<ClaimMapper, Claim> implements
|
|
|
if (jdTenant == null) {
|
|
if (jdTenant == null) {
|
|
|
throw new SecurityException("当前租户未配置凭证信息");
|
|
throw new SecurityException("当前租户未配置凭证信息");
|
|
|
}
|
|
}
|
|
|
-/*
|
|
|
|
|
- ApigwConfig config = new ApigwConfig();
|
|
|
|
|
|
|
+ /*ApigwConfig config = new ApigwConfig();
|
|
|
//设置client_id 245905
|
|
//设置client_id 245905
|
|
|
String client_id = "245905";
|
|
String client_id = "245905";
|
|
|
config.setClientID(client_id);
|
|
config.setClientID(client_id);
|
|
@@ -551,13 +557,23 @@ public class ClaimServiceImpl extends ServiceImpl<ClaimMapper, Claim> implements
|
|
|
//初始化API网关客户端
|
|
//初始化API网关客户端
|
|
|
apigwClient.init(config);
|
|
apigwClient.init(config);
|
|
|
|
|
|
|
|
- //设置headers参数
|
|
|
|
|
|
|
+ //获得当天的appSecret
|
|
|
|
|
+ ApiRequest requestSecret = new ApiRequest(HttpMethod.POST_FORM, "api.kingdee.com", "/jdyconnector/app_management/push_app_authorize");
|
|
|
|
|
+ Map<String, String> querysSecret = new LinkedHashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ querysSecret.put("outerInstanceId", "127580462150455296");
|
|
|
|
|
+
|
|
|
|
|
+ requestSecret.setQuerys(querysSecret);
|
|
|
|
|
+ ApiResult resultsSecret = ApigwClient.getInstance().send(requestSecret);
|
|
|
|
|
+
|
|
|
|
|
+ token2DTO token2DTO = JSONObject.parseObject(resultsSecret.getBody(), token2DTO.class);
|
|
|
|
|
+
|
|
|
|
|
+ //获得token
|
|
|
ApiRequest request = new ApiRequest(HttpMethod.GET, "api.kingdee.com", "/jdyconnector/app_management/kingdee_auth_token");
|
|
ApiRequest request = new ApiRequest(HttpMethod.GET, "api.kingdee.com", "/jdyconnector/app_management/kingdee_auth_token");
|
|
|
|
|
|
|
|
- String key = "qidi75E9";
|
|
|
|
|
- String secret = "7255a5699d326559b5abaf887e25226a158565ed";
|
|
|
|
|
|
|
+ String key = token2DTO.getData().get(0).appKey;
|
|
|
|
|
+ String secret = token2DTO.getData().get(0).appSecret;
|
|
|
|
|
|
|
|
- //String s = SHAUtil.SHA256HMAC(key, secret);
|
|
|
|
|
String s = MD5Util.hashMAC(key, secret);
|
|
String s = MD5Util.hashMAC(key, secret);
|
|
|
Map<String, String> querys = new LinkedHashMap<>();
|
|
Map<String, String> querys = new LinkedHashMap<>();
|
|
|
querys.put("app_key", key);
|
|
querys.put("app_key", key);
|
|
@@ -565,8 +581,9 @@ public class ClaimServiceImpl extends ServiceImpl<ClaimMapper, Claim> implements
|
|
|
request.setQuerys(querys);
|
|
request.setQuerys(querys);
|
|
|
ApiResult results = ApigwClient.getInstance().send(request);
|
|
ApiResult results = ApigwClient.getInstance().send(request);
|
|
|
System.out.println("金蝶返回数据======》"+results.getBody());
|
|
System.out.println("金蝶返回数据======》"+results.getBody());
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(results.getBody());
|
|
|
|
|
+ System.out.println("app-token======>"+jsonObject.getJSONObject("data").getString("app-token"));*/
|
|
|
|
|
|
|
|
-*/
|
|
|
|
|
//获取测试账套token的url
|
|
//获取测试账套token的url
|
|
|
String getTokenUrl = "https://api.kingdee.com/auth/user/access_token?client_id=" + jdTenant.getClientId() +
|
|
String getTokenUrl = "https://api.kingdee.com/auth/user/access_token?client_id=" + jdTenant.getClientId() +
|
|
|
"&client_secret=" + jdTenant.getClientSecret() +
|
|
"&client_secret=" + jdTenant.getClientSecret() +
|
|
@@ -582,51 +599,6 @@ public class ClaimServiceImpl extends ServiceImpl<ClaimMapper, Claim> implements
|
|
|
return tokenDTO.getData().getAccess_token();
|
|
return tokenDTO.getData().getAccess_token();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String getSignature(String appKey, String appSignature, String timestamp, String nonce, String clientSecret) {
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- //1、对path部分进行url编码
|
|
|
|
|
- String path = URLEncoder.encode("/jdyconnector/app_management/kingdee_auth_token", "UTF-8");
|
|
|
|
|
- System.out.println("对path部分进行url编码======>"+path);
|
|
|
|
|
-
|
|
|
|
|
- //2、params请求参数
|
|
|
|
|
- //2.1 进行第一次url编码
|
|
|
|
|
- appSignature = URLEncoder.encode(appSignature, "UTF-8");
|
|
|
|
|
- System.out.println("进行第一次url编码======>"+appSignature);
|
|
|
|
|
-
|
|
|
|
|
- //2.2 进行第二次url编码
|
|
|
|
|
- appSignature = URLEncoder.encode(appSignature, "UTF-8");
|
|
|
|
|
- System.out.println("进行第二次url编码======>"+appSignature);
|
|
|
|
|
-
|
|
|
|
|
- //2.3 拼接params请求参数部分(按ASCII码升序顺序进行排序)
|
|
|
|
|
- String params = "app_key=" + appKey + "&app_signature=" + appSignature;
|
|
|
|
|
- System.out.println("拼接params请求参数部分======>"+params);
|
|
|
|
|
-
|
|
|
|
|
- //3、headers请求参数
|
|
|
|
|
- nonce = "x-api-nonce:" + nonce;//随机随机正整数
|
|
|
|
|
- timestamp = "x-api-timestamp:" + timestamp;//请求发起的时间戳
|
|
|
|
|
-
|
|
|
|
|
- //4、拼接得到签名字符串
|
|
|
|
|
- String srcStr = "GET" + "\n"
|
|
|
|
|
- + path + "\n"
|
|
|
|
|
- + params + "\n"
|
|
|
|
|
- + nonce + "\n"
|
|
|
|
|
- + timestamp + "\n";
|
|
|
|
|
- System.out.println("拼接得到签名字符串======>"+srcStr);
|
|
|
|
|
-
|
|
|
|
|
- //4、签名字符串生成X-Api-Signature
|
|
|
|
|
- String spec = SHAUtil.SHA256HMAC(srcStr, clientSecret);
|
|
|
|
|
- System.out.println("签名字符串生成X-Api-Signature======>"+spec);
|
|
|
|
|
- String value = Base64.encodeBase64String(spec.getBytes());
|
|
|
|
|
- System.out.println("Base64签名======>"+value);
|
|
|
|
|
-
|
|
|
|
|
- return value;
|
|
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public static Map<String,String> sortHashMap(Map<String,String> map){
|
|
public static Map<String,String> sortHashMap(Map<String,String> map){
|
|
|
Map<String,String> sortedMap = new LinkedHashMap<String,String>();
|
|
Map<String,String> sortedMap = new LinkedHashMap<String,String>();
|
|
|
List<String> list = new ArrayList<String>();
|
|
List<String> list = new ArrayList<String>();
|
|
@@ -796,34 +768,48 @@ public class ClaimServiceImpl extends ServiceImpl<ClaimMapper, Claim> implements
|
|
|
private String gender;
|
|
private String gender;
|
|
|
private String nickname;
|
|
private String nickname;
|
|
|
private String uid;
|
|
private String uid;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ @Data
|
|
|
|
|
+ public static class token2DTO {
|
|
|
|
|
+ private Long code;
|
|
|
|
|
+
|
|
|
|
|
+ private String msg;
|
|
|
|
|
|
|
|
|
|
+ private List<ClaimServiceImpl.token2Data> data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据时间戳+atomicInteger生成13位长度数字,只能支持小并发不重复,仅适用于后台系统
|
|
|
|
|
- *
|
|
|
|
|
- * @return Number
|
|
|
|
|
- */
|
|
|
|
|
- public static String getThirteenNumber() {
|
|
|
|
|
- AtomicInteger atomicInteger = new AtomicInteger(0);
|
|
|
|
|
- //后10位时间戳
|
|
|
|
|
- String timeStr = String.valueOf(System.currentTimeMillis()).substring(3);
|
|
|
|
|
- // 递增生成最大999的递增ID
|
|
|
|
|
- if (atomicInteger.get() == 999) {
|
|
|
|
|
- atomicInteger.set(0);
|
|
|
|
|
- }
|
|
|
|
|
- int atomicIntegerNum = atomicInteger.getAndIncrement();
|
|
|
|
|
- String atomicString = String.valueOf(atomicIntegerNum);
|
|
|
|
|
- if (atomicString.length() < 3) {
|
|
|
|
|
- switch (atomicString.length()) {
|
|
|
|
|
- case 1:
|
|
|
|
|
- return timeStr.concat("00" + atomicString);
|
|
|
|
|
- case 2:
|
|
|
|
|
- return timeStr.concat("0" + atomicString);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return timeStr.concat(atomicString);
|
|
|
|
|
|
|
+ @Data
|
|
|
|
|
+ public static class token2Data {
|
|
|
|
|
+ private String id;
|
|
|
|
|
+ private String appKey;
|
|
|
|
|
+ private String appSecret;
|
|
|
|
|
+ private String oldAppSecret;
|
|
|
|
|
+ private String status;
|
|
|
|
|
+ private String accessToken;
|
|
|
|
|
+ private String appToken;
|
|
|
|
|
+ private String expires;
|
|
|
|
|
+ private String userNumber;
|
|
|
|
|
+ private String serviceId;
|
|
|
|
|
+ private String clientId;
|
|
|
|
|
+ private String externalNumber;
|
|
|
|
|
+ private String outerInstanceId;
|
|
|
|
|
+ private String agreementCompanyName;
|
|
|
|
|
+ private String agreementAuthProductType;
|
|
|
|
|
+ private String agreementAdministratorName;
|
|
|
|
|
+ private String agreementAdministratorAccountNumber;
|
|
|
|
|
+ private String tenantId;
|
|
|
|
|
+ private String accountId;
|
|
|
|
|
+ private String uid;
|
|
|
|
|
+ private String tid;
|
|
|
|
|
+ private String createTime;
|
|
|
|
|
+ private String openTime;
|
|
|
|
|
+ private String secretUpdateTime;
|
|
|
|
|
+ private String isBrand;
|
|
|
|
|
+ private String brandSupplierId;
|
|
|
|
|
+ private String groupName;
|
|
|
|
|
+ private String accountName;
|
|
|
|
|
+ private String domain;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|