|
@@ -40,10 +40,14 @@ public class DingTalkSendUtils {
|
|
|
|
|
|
|
|
|
|
|
|
|
public void sendActioncardMsgToDingRobot(String content,String title) throws ApiException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
|
|
public void sendActioncardMsgToDingRobot(String content,String title) throws ApiException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
|
|
+ this.sendActioncardMsgToDingRobot(token, secret, content, title);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void sendActioncardMsgToDingRobot(String accessToken, String accessSecret, String content,String title) throws ApiException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
- String sign = getSign(timestamp);
|
|
|
|
|
|
|
+ String sign = getSign(timestamp, accessSecret);
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?" +
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?" +
|
|
|
- "access_token="+token +
|
|
|
|
|
|
|
+ "access_token="+accessToken +
|
|
|
"×tamp=".concat(String.valueOf(timestamp)).concat("&sign=").concat(sign));
|
|
"×tamp=".concat(String.valueOf(timestamp)).concat("&sign=").concat(sign));
|
|
|
OapiRobotSendRequest request = new OapiRobotSendRequest();
|
|
OapiRobotSendRequest request = new OapiRobotSendRequest();
|
|
|
request.setMsgtype("actionCard");
|
|
request.setMsgtype("actionCard");
|
|
@@ -60,10 +64,10 @@ public class DingTalkSendUtils {
|
|
|
System.out.println(re.getBody());
|
|
System.out.println(re.getBody());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static String getSign(Long timestamp) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
|
|
|
|
- String stringToSign = timestamp + "\n" + secret;
|
|
|
|
|
|
|
+ public static String getSign(Long timestamp, String accessSecret) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
|
|
|
|
+ String stringToSign = timestamp + "\n" + accessSecret;
|
|
|
Mac mac = Mac.getInstance("HmacSHA256");
|
|
Mac mac = Mac.getInstance("HmacSHA256");
|
|
|
- mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
|
|
|
|
|
|
|
+ mac.init(new SecretKeySpec(accessSecret.getBytes("UTF-8"), "HmacSHA256"));
|
|
|
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
|
|
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
|
|
|
System.out.println(new String(signData));
|
|
System.out.println(new String(signData));
|
|
|
return URLEncoder.encode(Base64Converter.encode(signData));
|
|
return URLEncoder.encode(Base64Converter.encode(signData));
|