|
|
@@ -38,13 +38,13 @@ import java.lang.String;
|
|
|
public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeControllerBean
|
|
|
{
|
|
|
/**
|
|
|
- * 娣诲姞浠诲姟
|
|
|
+ * 添加任务
|
|
|
* @param ctx
|
|
|
- * @param url 璇锋眰鍦板潃
|
|
|
- * @param requestId 璇锋眰id
|
|
|
- * @param osfServiceName 鍥炶皟osf鏈嶅姟鍚�
|
|
|
- * @param backParam 鍥炶皟鍙傛暟
|
|
|
- * @param catalog 浠诲姟绫诲瀷
|
|
|
+ * @param url 请求地址
|
|
|
+ * @param requestId 请求id
|
|
|
+ * @param osfServiceName 回调osf服务名
|
|
|
+ * @param backParam 回调参数
|
|
|
+ * @param catalog 任务类型
|
|
|
* @return
|
|
|
* @throws BOSException
|
|
|
*/
|
|
|
@@ -84,7 +84,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
return taskInfo.getId().toString();
|
|
|
}
|
|
|
/**
|
|
|
- * 鍙戣捣post璇锋眰
|
|
|
+ * 发起post请求
|
|
|
* @param ctx
|
|
|
* @param url
|
|
|
* @param param
|
|
|
@@ -97,8 +97,8 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
String result = "";
|
|
|
LogInfoInfo logInfo = new LogInfoInfo();
|
|
|
try {
|
|
|
- //鏃ュ織
|
|
|
- logInfo.setEntrance(this.getClass().getName());//鍏ュ彛
|
|
|
+ //日志
|
|
|
+ logInfo.setEntrance(this.getClass().getName());//入口
|
|
|
Long timestampLong = System.currentTimeMillis();
|
|
|
UserInfo userInfo = (UserInfo)ctx.get("UserInfo");
|
|
|
logInfo.setCreator(userInfo);
|
|
|
@@ -110,7 +110,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
|
|
|
JSONObject paramMap = JSONUtil.parseObj(param);
|
|
|
|
|
|
- //鑾峰彇閰嶇疆鏂囦欢
|
|
|
+ //获取配置文件
|
|
|
Map<String,String> propt = this._getConfig(ctx);
|
|
|
Map signaMap = Maps.newHashMap();
|
|
|
if(StrUtil.isBlank(paramMap.getStr("timestamp"))){
|
|
|
@@ -120,7 +120,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
signaMap.put("timestamp",paramMap.getStr("timestamp"));
|
|
|
}
|
|
|
if(StrUtil.isBlank(paramMap.getStr("xReqNonce"))){
|
|
|
- String xReqNonce = UUID.randomUUID().toString().replace("-", "");//璋冪敤鑰呯敓鎴愮殑 UUID(32浣�)锛岀粨鍚堟椂闂存埑timestamp 闃查噸鏀�
|
|
|
+ String xReqNonce = UUID.randomUUID().toString().replace("-", "");//调用者生成的 UUID(32位),结合时间戳timestamp 防重放
|
|
|
signaMap.put("xReqNonce",xReqNonce);
|
|
|
}else {
|
|
|
signaMap.put("xReqNonce",paramMap.getStr("xReqNonce"));
|
|
|
@@ -129,9 +129,9 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
String signature = this._getSignature(ctx,propt,signaMap);
|
|
|
Map<String,String> headers = new HashMap<String,String>();
|
|
|
headers.put("appKey",propt.get("appKey"));
|
|
|
- headers.put("timestamp",paramMap.getStr("timestamp"));
|
|
|
+ headers.put("timestamp", (String) signaMap.get("timestamp"));
|
|
|
headers.put("version",propt.get("version"));
|
|
|
- headers.put("xReqNonce",paramMap.getStr("xReqNonce"));
|
|
|
+ headers.put("xReqNonce", (String) signaMap.get("xReqNonce"));
|
|
|
headers.put("signature",signature);
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
RequestBody body = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
@@ -143,24 +143,24 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
if (sYResponse.isSuccessful()) {
|
|
|
result = sYResponse.body().string();
|
|
|
}else {
|
|
|
- logInfo.setErrorInfo(sYResponse.message());//閿欒�淇℃伅
|
|
|
+ logInfo.setErrorInfo(sYResponse.message());//错误信息
|
|
|
}
|
|
|
}catch (IOException e){
|
|
|
e.printStackTrace();
|
|
|
logger.error(e);
|
|
|
- logInfo.setErrorInfo(e.getMessage());//鎺ュ彛鍦板潃
|
|
|
+ logInfo.setErrorInfo(e.getMessage());//接口地址
|
|
|
}finally {
|
|
|
- logInfo.setInterfaceAddress(url);//鎺ュ彛鍦板潃
|
|
|
- logInfo.setInterfaceName(url);//鎺ュ彛鍚�
|
|
|
- logInfo.setInParameter(param);//鍏ュ弬
|
|
|
- logInfo.setOutParameter(result);//鍥炲弬
|
|
|
+ logInfo.setInterfaceAddress(url);//接口地址
|
|
|
+ logInfo.setInterfaceName(url);//接口名
|
|
|
+ logInfo.setInParameter(param);//入参
|
|
|
+ logInfo.setOutParameter(result);//回参
|
|
|
this._log(ctx,logInfo);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 鍙戣捣get璇锋眰
|
|
|
+ * 发起get请求
|
|
|
* @param ctx
|
|
|
* @param url
|
|
|
* @param param
|
|
|
@@ -173,8 +173,8 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
String result = "";
|
|
|
LogInfoInfo logInfo = new LogInfoInfo();
|
|
|
try {
|
|
|
- //鏃ュ織
|
|
|
- logInfo.setEntrance(this.getClass().getName());//鍏ュ彛
|
|
|
+ //日志
|
|
|
+ logInfo.setEntrance(this.getClass().getName());//入口
|
|
|
Long timestampLong = System.currentTimeMillis();
|
|
|
UserInfo userInfo = (UserInfo)ctx.get("UserInfo");
|
|
|
logInfo.setCreator(userInfo);
|
|
|
@@ -185,14 +185,14 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
logInfo.setBizDate(timestamp);
|
|
|
|
|
|
JSONObject paramMap = JSONUtil.parseObj(param);
|
|
|
- //鑾峰彇閰嶇疆鏂囦欢
|
|
|
+ //获取配置文件
|
|
|
Map<String,String> propt = this._getConfig(ctx);
|
|
|
if(StrUtil.isBlank(paramMap.getStr("timestamp"))){
|
|
|
|
|
|
paramMap.set("timestamp",String.valueOf(timestampLong));
|
|
|
}
|
|
|
if(StrUtil.isBlank(paramMap.getStr("xReqNonce"))){
|
|
|
- String xReqNonce = UUID.randomUUID().toString().replace("-", "");//璋冪敤鑰呯敓鎴愮殑 UUID(32浣�)锛岀粨鍚堟椂闂存埑timestamp 闃查噸鏀�
|
|
|
+ String xReqNonce = UUID.randomUUID().toString().replace("-", "");//调用者生成的 UUID(32位),结合时间戳timestamp 防重放
|
|
|
paramMap.set("xReqNonce",xReqNonce);
|
|
|
}
|
|
|
param=JSONUtil.toJsonStr(paramMap);
|
|
|
@@ -218,17 +218,17 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
if (sYResponse.isSuccessful()) {
|
|
|
result = sYResponse.body().string();
|
|
|
}else {
|
|
|
- logInfo.setErrorInfo(sYResponse.message());//閿欒�淇℃伅
|
|
|
+ logInfo.setErrorInfo(sYResponse.message());//错误信息
|
|
|
}
|
|
|
}catch (IOException e){
|
|
|
e.printStackTrace();
|
|
|
logger.error(e);
|
|
|
- logInfo.setErrorInfo(e.getMessage());//鎺ュ彛鍦板潃
|
|
|
+ logInfo.setErrorInfo(e.getMessage());//接口地址
|
|
|
}finally {
|
|
|
- logInfo.setInterfaceAddress(url);//鎺ュ彛鍦板潃
|
|
|
- logInfo.setInterfaceName(url);//鎺ュ彛鍚�
|
|
|
- logInfo.setInParameter(param);//鍏ュ弬
|
|
|
- logInfo.setOutParameter(result);//鍥炲弬
|
|
|
+ logInfo.setInterfaceAddress(url);//接口地址
|
|
|
+ logInfo.setInterfaceName(url);//接口名
|
|
|
+ logInfo.setInParameter(param);//入参
|
|
|
+ logInfo.setOutParameter(result);//回参
|
|
|
this._log(ctx,logInfo);
|
|
|
}
|
|
|
return result;
|
|
|
@@ -240,16 +240,16 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
|
|
|
@Override
|
|
|
protected String _getSignature(Context ctx, Map propt,Map paramMap) throws BOSException {
|
|
|
- logger.error("====鑾峰彇绛惧悕===杩涘叆鍒颁簡com.kingdee.eas.custom.jiuzhoutong.utils.SYUtils.getSignature=======");
|
|
|
+ logger.error("====获取签名===进入到了com.kingdee.eas.custom.jiuzhoutong.utils.SYUtils.getSignature=======");
|
|
|
TreeMap<String, String> treeMap = new TreeMap<>();
|
|
|
|
|
|
- String version = (String) propt.get("version");//鐗堟湰
|
|
|
- String appKey = (String) propt.get("appKey");//韬�唤鏍囪瘑
|
|
|
- String appSecret = (String) propt.get("appSecret");//绉橀挜
|
|
|
- logger.error("=============鍙傛暟鍒�================");
|
|
|
- logger.error("version锛�"+version);
|
|
|
- logger.error("param锛�"+paramMap.toString());
|
|
|
- logger.error("appSecret锛�"+appSecret);
|
|
|
+ String version = (String) propt.get("version");//版本
|
|
|
+ String appKey = (String) propt.get("appKey");//身份标识
|
|
|
+ String appSecret = (String) propt.get("appSecret");//秘钥
|
|
|
+ logger.error("=============参数列================");
|
|
|
+ logger.error("version:"+version);
|
|
|
+ logger.error("param:"+paramMap.toString());
|
|
|
+ logger.error("appSecret:"+appSecret);
|
|
|
logger.error("==================================");
|
|
|
treeMap.put("appKey", appKey);
|
|
|
treeMap.put("appSecret", appSecret);
|
|
|
@@ -262,18 +262,18 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
for (Map.Entry<String, String> stringStringEntry : treeMap.entrySet()) {
|
|
|
mergeStr.append(stringStringEntry.getValue());
|
|
|
}
|
|
|
- logger.error("灏嗕互涓妅ey=value瀵圭殑value杩涜�鍚堝苟,鐢熸垚涓€涓嬪瓧绗︿覆mergeStr锛�"+mergeStr.toString());
|
|
|
+ logger.error("将以上key=value对的value进行合并,生成一下字符串mergeStr:"+mergeStr.toString());
|
|
|
String encodedStr = null;
|
|
|
try {
|
|
|
encodedStr = URLEncoder.encode(mergeStr.toString(), "UTF-8");
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
- // URL 缂栫爜澶辫触
|
|
|
+ // URL 编码失败
|
|
|
e.printStackTrace();
|
|
|
- throw new RuntimeException("url缂栫爜澶辫触");
|
|
|
+ throw new RuntimeException("url编码失败");
|
|
|
}
|
|
|
- logger.error("灏嗙敓鎴愮殑mergeStr杩涜�Url缂栫爜锛�"+encodedStr);
|
|
|
+ logger.error("将生成的mergeStr进行Url编码:"+encodedStr);
|
|
|
|
|
|
- // 4.鍒╃敤HmacSHA256绠楁硶瀵箂ignStr杩涜�鍝堝笇杩愮畻鐢熸垚娑堟伅鎽樿�,鎽樿�缁撴灉浠�ase64缁撴灉褰㈠紡杩斿洖锛宻ignStr鍗充负璇锋眰鍙傛暟涓�殑signature瀛楁�
|
|
|
+ // 4.利用HmacSHA256算法对signStr进行哈希运算生成消息摘要,摘要结果以Base64结果形式返回,signStr即为请求参数中的signature字段
|
|
|
String signatureResult = "";
|
|
|
try {
|
|
|
Mac mac = Mac.getInstance("HmacSHA256");
|
|
|
@@ -283,18 +283,18 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
byte[] resultBytes = Base64.getEncoder().encode(signData);
|
|
|
signatureResult = new String(resultBytes, "UTF-8");
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
- throw new RuntimeException("骞冲彴涓嶆敮鎸� HmacSHA 鎽樿�鏂瑰紡");
|
|
|
+ throw new RuntimeException("平台不支持 HmacSHA 摘要方式");
|
|
|
} catch (InvalidKeyException e) {
|
|
|
throw new RuntimeException("Speicified access secret is not valid.");
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
- throw new RuntimeException("杞�爜澶辫触");
|
|
|
+ throw new RuntimeException("转码失败");
|
|
|
}
|
|
|
- logger.error("鐢℉macSHA256绠楁硶瀵箂ignStr杩涜�鍝堝笇杩愮畻鐢熸垚娑堟伅鎽樿�,鎽樿�缁撴灉浠�ase64缁撴灉褰㈠紡杩斿洖锛宻ignStr鍗充负璇锋眰鍙傛暟涓�殑signature瀛楁�"+signatureResult);
|
|
|
- logger.error("==========================閫€鍑�================================");
|
|
|
+ logger.error("用HmacSHA256算法对signStr进行哈希运算生成消息摘要,摘要结果以Base64结果形式返回,signStr即为请求参数中的signature字段"+signatureResult);
|
|
|
+ logger.error("==========================退出================================");
|
|
|
return signatureResult;
|
|
|
}
|
|
|
/**
|
|
|
- * 绛惧悕
|
|
|
+ * 签名
|
|
|
* @param ctx
|
|
|
* @param param
|
|
|
* @return
|
|
|
@@ -308,7 +308,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * /閰嶇疆鏂囦欢鏇存柊
|
|
|
+ * /配置文件更新
|
|
|
* /server/properties/sy/syConfig.properties
|
|
|
* @param ctx
|
|
|
* @param filePath
|
|
|
@@ -335,7 +335,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 鑾峰彇閰嶇疆鏂囦欢
|
|
|
+ * 获取配置文件
|
|
|
* @param ctx
|
|
|
* @return
|
|
|
* @throws BOSException
|
|
|
@@ -346,7 +346,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
Map map = SYUConfigUtil.getInstance().getConfig();
|
|
|
return map;
|
|
|
}
|
|
|
-//
|
|
|
+
|
|
|
// public static void main(String[] args) throws BOSException, IOException {
|
|
|
// SYUtilsFacadeControllerBean bean = new SYUtilsFacadeControllerBean();
|
|
|
// bean._initConfig(null,"D:\\jingdie\\yss\\8.6v2jar\\Project_86v2\\jiuzhoutong\\config\\server\\properties\\sy\\syConfig.properties");
|
|
|
@@ -355,7 +355,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
// OkHttpClient client = new OkHttpClient();
|
|
|
// Long timestampLong = System.currentTimeMillis();
|
|
|
// Map<String,String> postBody = new HashMap<>();
|
|
|
-// postBody.put("qymc","鑽嗗窞涔濆窞閫氬尰鑽�湁闄愬叕鍙�00");
|
|
|
+// postBody.put("qymc","荆州九州通医药有限公司00");
|
|
|
// postBody.put("nsrsbh","91310124834931897I");
|
|
|
// postBody.put("areaid","310101");
|
|
|
//// postBody.put("xReqNonce","c1fe0ae4344444979139360ad5fe5ee9");
|
|
|
@@ -366,7 +366,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
// signaMap.put("timestamp",String.valueOf(timestampLong));
|
|
|
// }
|
|
|
// if(StrUtil.isBlank(postBody.get("xReqNonce"))){
|
|
|
-// String xReqNonce = UUID.randomUUID().toString().replace("-", "");//璋冪敤鑰呯敓鎴愮殑 UUID(32浣�)锛岀粨鍚堟椂闂存埑timestamp 闃查噸鏀�
|
|
|
+// String xReqNonce = UUID.randomUUID().toString().replace("-", "");//调用者生成的 UUID(32位),结合时间戳timestamp 防重放
|
|
|
// signaMap.put("xReqNonce",xReqNonce);
|
|
|
// }
|
|
|
//
|