Commit 990f8b6d authored by 赵啸非's avatar 赵啸非

Merge remote-tracking branch 'origin/master'

parents 66f7a678 3562659e
......@@ -71,6 +71,8 @@
<profiles.dingtalk.agentId>2652674890</profiles.dingtalk.agentId>
<profiles.dingtalk.appKey>dingpqzradgfr4efdi2j</profiles.dingtalk.appKey>
<profiles.dingtalk.appSecret>bF2WALmo5_Wuj3hg5gXeWqezrYnZChUJ88HjzNWpkA9ivdOxfBDGOGYcfVRfB3vd</profiles.dingtalk.appSecret>
<profiles.dingtalk.aesKey>1QcPYuSpAc98OS3qQwwx5HPH85CZDidxF95yBGad2fJ</profiles.dingtalk.aesKey>
<profiles.dingtalk.token>m3WeuVx5kcTY76kh22uWZOTSu0XjvcwNhd</profiles.dingtalk.token>
<profiles.webUrl>http://8.136.255.30:11039/attendance</profiles.webUrl>
<package.environment>test</package.environment>
<skipUi>false</skipUi>
......@@ -99,6 +101,8 @@
<profiles.dingtalk.agentId>2652674890</profiles.dingtalk.agentId>
<profiles.dingtalk.appKey>dingpqzradgfr4efdi2j</profiles.dingtalk.appKey>
<profiles.dingtalk.appSecret>bF2WALmo5_Wuj3hg5gXeWqezrYnZChUJ88HjzNWpkA9ivdOxfBDGOGYcfVRfB3vd</profiles.dingtalk.appSecret>
<profiles.dingtalk.aesKey>1QcPYuSpAc98OS3qQwwx5HPH85CZDidxF95yBGad2fJ</profiles.dingtalk.aesKey>
<profiles.dingtalk.token>m3WeuVx5kcTY76kh22uWZOTSu0XjvcwNhd</profiles.dingtalk.token>
<profiles.webUrl>https://ybswxxcx.zwfwhfgjjfzj.yibin.gov.cn/performance-h5</profiles.webUrl>
<package.environment>build</package.environment>
<skipUi>false</skipUi>
......
package com.mortals.xhx.module.attendance.dingmsg.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.common.pdu.ApiRespPdu;
import com.mortals.xhx.module.attendance.dingmsg.DingCallbackCrypto;
import com.mortals.xhx.module.attendance.dingmsg.dingmsgreq.DingResponsMeassageReq;
import com.mortals.xhx.module.attendance.dingmsg.dingmsgreq.EncryptReq;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
*
* 接收钉钉的审批消息推送
*
* @author ZYW
* @date 2023-07-18 9:52
*/
@RestController
@Slf4j
public class DingMessageController {
/**
* appKey
*/
@Value("${dingtalk.AppKey:''}")
protected String appKey;
/**
* aesKey
*/
@Value("${dingtalk.AesKey:''}")
protected String aesKey;
/**
* 订阅消息token
*/
@Value("${dingtalk.token:''}")
protected String token;
/**
* 接收钉钉消息
*
* @return
*/
@PostMapping("/dingtalk/getOaMeassge")
@UnAuth
public Map<String, String> getOaMessage(@RequestParam(value = "msg_signature", required = false) String msg_signature,
@RequestParam(value = "timestamp", required = false) String timeStamp,
@RequestParam(value = "nonce", required = false) String nonce,
@RequestBody(required = false) JSONObject json) throws DingCallbackCrypto.DingTalkEncryptException {
try {
// 1. 从http请求中获取加解密参数
// 2. 使用加解密类型
// Constant.OWNER_KEY 说明:
// 1、开发者后台配置的订阅事件为应用级事件推送,此时OWNER_KEY为应用的APP_KEY。
// 2、调用订阅事件接口订阅的事件为企业级事件推送,
// 此时OWNER_KEY为:企业的appkey(企业内部应用)或SUITE_KEY(三方应用)
DingCallbackCrypto callbackCrypto = new DingCallbackCrypto(token, aesKey, appKey);
String encryptMsg = json.getString("encrypt");
String decryptMsg = callbackCrypto.getDecryptMsg(msg_signature, timeStamp, nonce, encryptMsg);
// 3. 反序列化回调事件json数据
JSONObject eventJson = JSON.parseObject(decryptMsg);
String eventType = eventJson.getString("EventType");
// 4. 根据EventType分类处理
if ("check_url".equals(eventType)) {
// 测试回调url的正确性
log.info("测试回调url的正确性");
} else if ("user_add_org".equals(eventType)) {
// 处理通讯录用户增加事件
log.info("发生了:" + eventType + "事件");
} else {
// 添加其他已注册的
log.info("发生了:" + eventType + "事件");
}
// 5. 返回success的加密数据
Map<String, String> successMap = callbackCrypto.getEncryptedMap("success");
return successMap;
} catch (DingCallbackCrypto.DingTalkEncryptException e) {
e.printStackTrace();
}
return null;
}
}
package com.mortals.xhx.module.attendance.dingmsg.dingmsgreq;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author ZYW
* @date 2023-07-18 10:20
*/
@NoArgsConstructor
@Data
public class DingResponsMeassageReq {
@JsonProperty("msg_signature")
private String msgSignature;
@JsonProperty("timeStamp")
private String timeStamp;
@JsonProperty("nonce")
private String nonce;
@JsonProperty("encrypt")
private String encrypt;
}
package com.mortals.xhx.module.attendance.dingmsg.dingmsgreq;
/**
* @author ZYW
* @date 2023-07-18 10:14
*/
public class EncryptReq {
String encrypt;
public String getEncrypt() {
return encrypt;
}
public void setEncrypt(String encrypt) {
this.encrypt = encrypt;
}
}
......@@ -72,5 +72,7 @@ dingtalk:
agentId: @profiles.dingtalk.agentId@
AppKey: @profiles.dingtalk.appKey@
AppSecret: @profiles.dingtalk.appSecret@
webUrl: @profiles.webUrl@
webUrl: @profiles.webUrl@
AesKey: @profiles.dingtalk.aesKey@
token: @profiles.dingtalk.token@
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment