测试操作
This commit is contained in:
parent
35454f31b3
commit
90aed66376
|
@ -1,7 +1,9 @@
|
|||
package shkd.repc.recon.opplugin;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.operate.result.OperateErrorInfo;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||
|
@ -10,12 +12,16 @@ import kd.bos.framework.lifecycle.Service;
|
|||
import kd.bos.framework.lifecycle.SystemServiceConfig;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.util.HttpClientUtils;
|
||||
import kd.bos.util.StringUtils;
|
||||
import org.apache.commons.net.util.Base64;
|
||||
//import java.util.Base64;
|
||||
import shkd.utils.OAUtils;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
@ -26,6 +32,8 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
|
|||
|
||||
private static final Log logger = LogFactory.getLog(TestOPPlugin.class);
|
||||
|
||||
private static final String RESM_OFFICIAL_SUPPLIER = "resm_official_supplier";//正式供应商
|
||||
|
||||
@Override
|
||||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||
super.afterExecuteOperationTransaction(e);
|
||||
|
@ -193,21 +201,23 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
|
|||
/*
|
||||
---------------------生成上传文件链接----------------------------
|
||||
*/
|
||||
try {
|
||||
String linkUrl = "http://172.31.254.241:8869/file/v1/generateUploadUrl";
|
||||
//TODO: 一.请求头(2.2.1) 二.requestID
|
||||
|
||||
//生成上传文件链接接口请求体
|
||||
JSONObject linkBody = new JSONObject();
|
||||
linkBody.put("expire",5);
|
||||
linkBody.put("requestID", "4A6F3B4E5C2D1A9F8E7B6C5D4A3B2C1E");
|
||||
linkBody.put("type", 1);
|
||||
|
||||
//获取上传链接类型,0-上传文件并分割,适用于100M以内的pdf文件。1-上传文件,适用于大于100M的pdf文件,以及其他类型的文件:ofd、doc、docx、xls、xlsx、jpg、jpeg、png、zip、rar。
|
||||
Map<String, String> linkHeader = new HashMap<>();
|
||||
//body,项目密钥进行加密(HmacSHA256进行数据加密)
|
||||
String secret = linkBody.toJSONString();
|
||||
String message ="B69RSfJJ5yJ6gizo";
|
||||
//import org.apache.commons.net.util.Base64;
|
||||
//import java.util.Base64;
|
||||
// try {
|
||||
// String linkUrl = "http://172.31.254.241:8869/file/v1/generateUploadUrl";
|
||||
// //TODO: 一.请求头(2.2.1) 二.requestID
|
||||
//
|
||||
// //生成上传文件链接接口请求体
|
||||
// JSONObject linkBody = new JSONObject();
|
||||
// linkBody.put("expire",5);
|
||||
// linkBody.put("requestID", "4A6F3B4E5C2D1A9F8E7B6C5D4A3B2C1E");
|
||||
// linkBody.put("type", 1);
|
||||
//
|
||||
// //获取上传链接类型,0-上传文件并分割,适用于100M以内的pdf文件。1-上传文件,适用于大于100M的pdf文件,以及其他类型的文件:ofd、doc、docx、xls、xlsx、jpg、jpeg、png、zip、rar。
|
||||
// Map<String, String> linkHeader = new HashMap<>();
|
||||
// //body,项目密钥进行加密(HmacSHA256进行数据加密)
|
||||
// String secret = linkBody.toJSONString();
|
||||
// String message ="B69RSfJJ5yJ6gizo";
|
||||
|
||||
// //import org.apache.commons.net.util.Base64;
|
||||
// Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
|
||||
|
@ -216,7 +226,7 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
|
|||
// byte[] hash = sha256_HMAC.doFinal(message.getBytes());
|
||||
// String encodeStr = Base64.encodeBase64String(hash);//Ew6TnQg1i+e6GomCPBSoXfX+UFqmKy1AnP6gVKJrrQM=\r\n
|
||||
|
||||
//import java.util.Base64;
|
||||
//import java.util.Base64;
|
||||
// SecretKeySpec secretKey = new SecretKeySpec(message.getBytes(),"HmacSHA256");
|
||||
// sha256_HMAC.init(secretKey);
|
||||
// byte[] hash = sha256_HMAC.doFinal(secret.getBytes());
|
||||
|
@ -225,27 +235,21 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
|
|||
|
||||
// String encodestr16 = byte2Hex(hash);//130e939d08358be7ba1a89823c14a85df5fe505aa62b2d409cfea054a26bad03 //6bb17135126cbb9ab4aae15217ce11d1e3a10225d85e82afaeb3f0da8fc9c1b3
|
||||
|
||||
String HMACsha256 = calculateHMACSHA256(secret, message);//130e939d08358be7ba1a89823c14a85df5fe505aa62b2d409cfea054a26bad03
|
||||
String HMACsha256s = calculateHMACSHA256(message,secret );//6bb17135126cbb9ab4aae15217ce11d1e3a10225d85e82afaeb3f0da8fc9c1b3
|
||||
|
||||
|
||||
linkHeader.put("Content-Type", "application/json");
|
||||
linkHeader.put("x-timevale-project-id", "1000000");
|
||||
linkHeader.put("x-timevale-signature", "4c45b39ebe42818aa90001849dffda622c9894454bc6d68c03aff67c55730661");
|
||||
|
||||
|
||||
|
||||
String linkPostjson = HttpClientUtils.postjson(linkUrl, linkHeader,linkBody.toJSONString());
|
||||
if (StringUtils.isNotEmpty(linkPostjson)) {
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
|
||||
String messages = jsonObject.getString("message");
|
||||
|
||||
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
|
||||
operateErrorInfo.setMessage(messages);
|
||||
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
|
||||
operateErrorInfo.setPkValue(dataEntity.getPkValue());
|
||||
this.operationResult.addErrorInfo(operateErrorInfo);
|
||||
// String HMACsha256 = calculateHMACSHA256(secret, message);//130e939d08358be7ba1a89823c14a85df5fe505aa62b2d409cfea054a26bad03
|
||||
// String HMACsha256s = calculateHMACSHA256(message,secret );//6bb17135126cbb9ab4aae15217ce11d1e3a10225d85e82afaeb3f0da8fc9c1b3
|
||||
//
|
||||
//
|
||||
// linkHeader.put("Content-Type", "application/json");
|
||||
// linkHeader.put("x-timevale-project-id", "1000000");
|
||||
// linkHeader.put("x-timevale-signature", "4c45b39ebe42818aa90001849dffda622c9894454bc6d68c03aff67c55730661");
|
||||
//
|
||||
//
|
||||
//
|
||||
// String linkPostjson = HttpClientUtils.postjson(linkUrl, linkHeader,linkBody.toJSONString());
|
||||
// if (StringUtils.isNotEmpty(linkPostjson)) {
|
||||
//
|
||||
// JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
|
||||
// String messages = jsonObject.getString("message");
|
||||
// /*
|
||||
// ---------------------上传文件----------------------------
|
||||
// */
|
||||
|
@ -264,49 +268,12 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
|
|||
// default:
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
|
||||
operateErrorInfo.setMessage(ex.getMessage());
|
||||
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
|
||||
operateErrorInfo.setPkValue(dataEntity.getPkValue());
|
||||
this.operationResult.addErrorInfo(operateErrorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String byte2Hex(byte[] bytes){
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
String temp = null;
|
||||
for(int i=0 ; i < bytes.length; i++) {
|
||||
temp = Integer.toHexString(bytes[i] & 0xFF);
|
||||
//1得到一位的进行补0操作
|
||||
if (temp.length() == 1) {
|
||||
stringBuffer.append("0");
|
||||
}
|
||||
stringBuffer.append(temp);
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public static String calculateHMACSHA256(String key, String message) {
|
||||
try {
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
|
||||
mac.init(secretKeySpec);
|
||||
byte[] hmac = mac.doFinal(message.getBytes(StandardCharsets.UTF_8));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : hmac) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
// String[] split = encodeStr.split("=", 4);
|
||||
// String s = split[0];
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
|
||||
// operateErrorInfo.setMessage(ex.getMessage());
|
||||
// operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
|
||||
// operateErrorInfo.setPkValue(dataEntity.getPkValue());
|
||||
// this.operationResult.addErrorInfo(operateErrorInfo);
|
||||
// }
|
||||
// }
|
Loading…
Reference in New Issue