Commit c9658c3bf848534a720b16c45efaf9df41f93636
1 parent
70ac3b7e
Exists in
dev
1:钉钉代码优化
Showing
20 changed files
with
187 additions
and
862 deletions
Show diff stats
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/constant/DingtalkConstant.java
0 → 100644
... | ... | @@ -0,0 +1,70 @@ |
1 | +package com.chinagas.modules.schsf.constant; | |
2 | + | |
3 | +import lombok.Data; | |
4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
5 | +import org.springframework.stereotype.Component; | |
6 | + | |
7 | +@ConfigurationProperties(prefix = "dingtalk") | |
8 | +@Component | |
9 | +@Data | |
10 | +public class DingtalkConstant { | |
11 | + | |
12 | + /** | |
13 | + * 企业corpid | |
14 | + */ | |
15 | + private String corpId; | |
16 | + | |
17 | + /** | |
18 | + * 应用agentId | |
19 | + */ | |
20 | + private String agentId; | |
21 | + | |
22 | + /** | |
23 | + * 应用的appkey | |
24 | + */ | |
25 | + private String appKey; | |
26 | + | |
27 | + /** | |
28 | + * 应用的appsecret | |
29 | + */ | |
30 | + private String appSecret; | |
31 | + | |
32 | + /** | |
33 | + * 回调host | |
34 | + */ | |
35 | + private String callbackUrlHost; | |
36 | + | |
37 | + /** | |
38 | + * 加解密需要用到的token,企业可以随机填写。如 "123456" | |
39 | + */ | |
40 | + private String token; | |
41 | + | |
42 | + /** | |
43 | + * 数据加密密钥。用于回调数据的加密,长度固定为43个字符,从a-z, A-Z, 0-9共62个字符中选取,您可以随机生成 | |
44 | + */ | |
45 | + private String encodingAesKey; | |
46 | + | |
47 | + /** | |
48 | + * DING API地址 | |
49 | + */ | |
50 | + private String oapiHost; | |
51 | + | |
52 | + /** | |
53 | + * 删除企业回调接口url | |
54 | + */ | |
55 | + private String deleteCallback; | |
56 | + | |
57 | + /** | |
58 | + * 注册企业回调接口url | |
59 | + */ | |
60 | + private String registerCallback; | |
61 | + | |
62 | + /** | |
63 | + * 企业应用后台地址,用户管理后台免登使用 | |
64 | + */ | |
65 | + private String oaBackgroundUrl; | |
66 | + | |
67 | + private String ssoSecret; | |
68 | + | |
69 | + | |
70 | +} | ... | ... |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/constant/Env.java
... | ... | @@ -1,65 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.constant; | |
2 | - | |
3 | - | |
4 | -/** | |
5 | - * 企业应用接入时的常量定义 | |
6 | - */ | |
7 | -public class Env { | |
8 | - | |
9 | - /** | |
10 | - * 企业corpid | |
11 | - */ | |
12 | - public static final String CORP_ID = "dingf2f9115915afcb54a39a90f97fcb1e09"; | |
13 | - | |
14 | - /** | |
15 | - * 应用agentId | |
16 | - */ | |
17 | - public static final String AGENT_ID = "3129896987"; | |
18 | - | |
19 | - /** | |
20 | - * 应用的appkey | |
21 | - */ | |
22 | - public static final String APP_KEY = "dingplin6zezdw81rqjd"; | |
23 | - | |
24 | - /** | |
25 | - * 应用的appsecret | |
26 | - */ | |
27 | - public static final String APP_SECRET = "urDzarTDCpo6A7nJfPiGUJRTGY8O-JO0pvDl0O6wm3Eih6zL92hDdThIdmeKUh2C"; | |
28 | - | |
29 | - /** | |
30 | - * 回调host | |
31 | - */ | |
32 | - public static final String CALLBACK_URL_HOST = ""; | |
33 | - | |
34 | - /** | |
35 | - * 加解密需要用到的token,企业可以随机填写。如 "123456" | |
36 | - */ | |
37 | - public static final String TOKEN = "123456"; | |
38 | - | |
39 | - /** | |
40 | - * 数据加密密钥。用于回调数据的加密,长度固定为43个字符,从a-z, A-Z, 0-9共62个字符中选取,您可以随机生成 | |
41 | - */ | |
42 | - public static final String ENCODING_AES_KEY = "abcdefghijabcdefghijabcdefghijabcdefghij123"; | |
43 | - | |
44 | - /** | |
45 | - * DING API地址 | |
46 | - */ | |
47 | - public static final String OAPI_HOST = "https://oapi.dingtalk.com"; | |
48 | - | |
49 | - /** | |
50 | - * 删除企业回调接口url | |
51 | - */ | |
52 | - public static final String DELETE_CALLBACK = "https://oapi.dingtalk.com/call_back/delete_call_back"; | |
53 | - | |
54 | - /** | |
55 | - * 注册企业回调接口url | |
56 | - */ | |
57 | - public static final String REGISTER_CALLBACK = "https://oapi.dingtalk.com/call_back/register_call_back"; | |
58 | - | |
59 | - /** | |
60 | - * 企业应用后台地址,用户管理后台免登使用 | |
61 | - */ | |
62 | - public static final String OA_BACKGROUND_URL = ""; | |
63 | - | |
64 | - public static final String SSO_Secret = ""; | |
65 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/controller/DingtalkController.java
1 | 1 | package com.chinagas.modules.schsf.controller; |
2 | 2 | |
3 | 3 | import com.chinagas.common.core.domain.AjaxResult; |
4 | -import com.chinagas.modules.schsf.constant.Env; | |
4 | +import com.chinagas.modules.schsf.constant.DingtalkConstant; | |
5 | 5 | import com.chinagas.modules.schsf.exception.OApiException; |
6 | -import com.chinagas.modules.schsf.openApi.auth.AuthHelper; | |
6 | +import com.chinagas.modules.schsf.service.DingtalkService; | |
7 | 7 | import lombok.extern.slf4j.Slf4j; |
8 | +import org.springframework.beans.factory.annotation.Autowired; | |
8 | 9 | import org.springframework.web.bind.annotation.GetMapping; |
9 | 10 | import org.springframework.web.bind.annotation.RequestMapping; |
10 | 11 | import org.springframework.web.bind.annotation.RestController; |
... | ... | @@ -15,34 +16,42 @@ import java.util.HashMap; |
15 | 16 | @RequestMapping("/dingtalk") |
16 | 17 | @Slf4j |
17 | 18 | public class DingtalkController { |
19 | + @Autowired | |
20 | + private DingtalkService dingtalkService; | |
21 | + | |
22 | + @Autowired | |
23 | + private DingtalkConstant dingtalkConstant; | |
18 | 24 | |
19 | 25 | @GetMapping("/getConfig") |
20 | 26 | public AjaxResult getConfig(String url) throws OApiException { |
21 | - log.info("getConfig:{}",1); | |
22 | - String appKey = Env.APP_KEY; | |
23 | - String agentId = Env.AGENT_ID; | |
24 | - String corpId = Env.CORP_ID; | |
27 | + log.info("getConfig:{}", 1); | |
28 | + String appKey = dingtalkConstant.getAppKey(); | |
29 | + String agentId = dingtalkConstant.getAgentId(); | |
30 | + String corpId = dingtalkConstant.getCorpId(); | |
25 | 31 | long timeStamp = System.currentTimeMillis(); |
26 | 32 | String nonceStr = "nonceStr"; |
27 | 33 | |
34 | + | |
28 | 35 | // 获取access token |
29 | - String accessToken = AuthHelper.getAccessToken(timeStamp); | |
36 | + String accessToken = dingtalkService.getAccessToken(timeStamp); | |
30 | 37 | System.out.println("成功获取access token: " + accessToken); |
38 | + | |
39 | + | |
31 | 40 | // 获取jsapi ticket |
32 | - String ticket = AuthHelper.getJsapiTicket(accessToken,timeStamp); | |
33 | - System.out.println("成功获取jsapi ticket: "+ticket); | |
41 | + String ticket = dingtalkService.getJsapiTicket(accessToken, timeStamp); | |
42 | + System.out.println("成功获取jsapi ticket: " + ticket); | |
34 | 43 | // 获取签名 |
35 | 44 | // String url = "http://www.dingtalk.com"; |
36 | - String signature = AuthHelper.sign(ticket, nonceStr, timeStamp, url); | |
45 | + String signature = dingtalkService.getSign(ticket, nonceStr, timeStamp, url); | |
37 | 46 | System.out.println("成功签名: " + signature); |
38 | 47 | |
39 | 48 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); |
40 | - objectObjectHashMap.put("appKey",appKey); | |
41 | - objectObjectHashMap.put("agentId",agentId); | |
42 | - objectObjectHashMap.put("corpId",corpId); | |
43 | - objectObjectHashMap.put("timeStamp",timeStamp); | |
44 | - objectObjectHashMap.put("nonceStr",nonceStr); | |
45 | - objectObjectHashMap.put("signature",signature); | |
49 | + objectObjectHashMap.put("appKey", appKey); | |
50 | + objectObjectHashMap.put("agentId", agentId); | |
51 | + objectObjectHashMap.put("corpId", corpId); | |
52 | + objectObjectHashMap.put("timeStamp", timeStamp); | |
53 | + objectObjectHashMap.put("nonceStr", nonceStr); | |
54 | + objectObjectHashMap.put("signature", signature); | |
46 | 55 | System.out.println(objectObjectHashMap); |
47 | 56 | return AjaxResult.success(objectObjectHashMap); |
48 | 57 | } | ... | ... |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/auth/AuthHelper.java
... | ... | @@ -1,180 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.auth; | |
2 | - | |
3 | -import com.chinagas.modules.schsf.constant.Env; | |
4 | -import com.chinagas.modules.schsf.exception.OApiException; | |
5 | -import com.chinagas.modules.schsf.utils.FileUtils; | |
6 | -import com.chinagas.modules.schsf.utils.HttpHelper; | |
7 | -import com.alibaba.fastjson.JSON; | |
8 | -import com.alibaba.fastjson.JSONObject; | |
9 | -import com.dingtalk.oapi.lib.aes.DingTalkJsApiSingnature; | |
10 | -import com.dingtalk.open.client.ServiceFactory; | |
11 | -import com.dingtalk.open.client.api.model.corp.JsapiTicket; | |
12 | -import com.dingtalk.open.client.api.service.corp.CorpConnectionService; | |
13 | -import com.dingtalk.open.client.api.service.corp.JsapiService; | |
14 | - | |
15 | -import javax.servlet.http.HttpServletRequest; | |
16 | -import java.net.URLDecoder; | |
17 | -import java.util.HashMap; | |
18 | -import java.util.Map; | |
19 | - | |
20 | -/** | |
21 | - * AccessToken和jsticket的获取封装 | |
22 | - */ | |
23 | -public class AuthHelper { | |
24 | - | |
25 | - /** | |
26 | - * 调整到1小时50分钟 | |
27 | - */ | |
28 | - public static final long cacheTime = 1000 * 60 * 55 * 2; | |
29 | - | |
30 | - /** | |
31 | - * 在此方法中,为了避免频繁获取access_token, | |
32 | - * 在距离上一次获取access_token时间在两个小时之内的情况, | |
33 | - * 将直接从持久化存储中读取access_token | |
34 | - * <p> | |
35 | - * 因为access_token和jsapi_ticket的过期时间都是7200秒 | |
36 | - * 所以在获取access_token的同时也去获取了jsapi_ticket | |
37 | - * 注:jsapi_ticket是在前端页面JSAPI做权限验证配置的时候需要使用的 | |
38 | - * 具体信息请查看开发者文档--权限验证配置 | |
39 | - */ | |
40 | - public static String getAccessToken(Long timeStamp) throws OApiException { | |
41 | - long curTime = timeStamp == null ? System.currentTimeMillis() : timeStamp; | |
42 | - JSONObject accessTokenValue = (JSONObject) FileUtils.getValue("accesstoken", Env.APP_KEY); | |
43 | - String accToken = ""; | |
44 | - JSONObject jsontemp = new JSONObject(); | |
45 | - if (accessTokenValue == null || curTime - accessTokenValue.getLong("begin_time") >= cacheTime) { | |
46 | - try { | |
47 | - ServiceFactory serviceFactory = ServiceFactory.getInstance(); | |
48 | - CorpConnectionService corpConnectionService = serviceFactory.getOpenService(CorpConnectionService.class); | |
49 | - accToken = corpConnectionService.getCorpToken(Env.APP_KEY, Env.APP_SECRET); | |
50 | - // save accessToken | |
51 | - JSONObject jsonAccess = new JSONObject(); | |
52 | - jsontemp.clear(); | |
53 | - jsontemp.put("access_token", accToken); | |
54 | - jsontemp.put("begin_time", curTime); | |
55 | - jsonAccess.put(Env.APP_KEY, jsontemp); | |
56 | - //真实项目中最好保存到数据库中 | |
57 | - FileUtils.write2File(jsonAccess, "accesstoken"); | |
58 | - | |
59 | - } catch (Exception e) { | |
60 | - e.printStackTrace(); | |
61 | - } | |
62 | - } else { | |
63 | - return accessTokenValue.getString("access_token"); | |
64 | - } | |
65 | - return accToken; | |
66 | - } | |
67 | - | |
68 | - /** | |
69 | - * 获取JSTicket, 用于js的签名计算 | |
70 | - * 正常的情况下,jsapi_ticket的有效期为7200秒,所以开发者需要在某个地方设计一个定时器,定期去更新jsapi_ticket | |
71 | - */ | |
72 | - public static String getJsapiTicket(String accessToken,Long timeStamp) throws OApiException { | |
73 | - JSONObject jsTicketValue = (JSONObject) FileUtils.getValue("jsticket", Env.APP_KEY); | |
74 | - long curTime =timeStamp==null? System.currentTimeMillis():timeStamp; | |
75 | - String jsTicket = ""; | |
76 | - | |
77 | - if (jsTicketValue == null || curTime - | |
78 | - jsTicketValue.getLong("begin_time") >= cacheTime) { | |
79 | - ServiceFactory serviceFactory; | |
80 | - try { | |
81 | - serviceFactory = ServiceFactory.getInstance(); | |
82 | - JsapiService jsapiService = serviceFactory.getOpenService(JsapiService.class); | |
83 | - | |
84 | - JsapiTicket JsapiTicket = jsapiService.getJsapiTicket(accessToken, "jsapi"); | |
85 | - jsTicket = JsapiTicket.getTicket(); | |
86 | - | |
87 | - JSONObject jsonTicket = new JSONObject(); | |
88 | - JSONObject jsontemp = new JSONObject(); | |
89 | - jsontemp.clear(); | |
90 | - jsontemp.put("ticket", jsTicket); | |
91 | - jsontemp.put("begin_time", curTime); | |
92 | - jsonTicket.put(Env.APP_KEY, jsontemp); | |
93 | - FileUtils.write2File(jsonTicket, "jsticket"); | |
94 | - } catch (Exception e) { | |
95 | - e.printStackTrace(); | |
96 | - } | |
97 | - return jsTicket; | |
98 | - } else { | |
99 | - return jsTicketValue.getString("ticket"); | |
100 | - } | |
101 | - } | |
102 | - | |
103 | - public static String sign(String ticket, String nonceStr, long timeStamp, String url) throws OApiException { | |
104 | - try { | |
105 | - return DingTalkJsApiSingnature.getJsApiSingnature(url, nonceStr, timeStamp, ticket); | |
106 | - } catch (Exception ex) { | |
107 | - throw new OApiException(0, ex.getMessage()); | |
108 | - } | |
109 | - } | |
110 | - | |
111 | - /** | |
112 | - * 计算当前请求的jsapi的签名数据<br/> | |
113 | - * <p> | |
114 | - * 如果签名数据是通过ajax异步请求的话,签名计算中的url必须是给用户展示页面的url | |
115 | - * | |
116 | - * @param request | |
117 | - * @return | |
118 | - */ | |
119 | - public static String getConfig(HttpServletRequest request) { | |
120 | - String urlString = request.getRequestURL().toString(); | |
121 | - String queryString = request.getQueryString(); | |
122 | - | |
123 | - String queryStringEncode = null; | |
124 | - String url; | |
125 | - if (queryString != null) { | |
126 | - queryStringEncode = URLDecoder.decode(queryString); | |
127 | - url = urlString + "?" + queryStringEncode; | |
128 | - } else { | |
129 | - url = urlString; | |
130 | - } | |
131 | - /** | |
132 | - * 确认url与配置的应用首页地址一致 | |
133 | - */ | |
134 | - System.out.println(url); | |
135 | - | |
136 | - /** | |
137 | - * 随机字符串 | |
138 | - */ | |
139 | - String nonceStr = "abcdefg"; | |
140 | - long timeStamp = System.currentTimeMillis() / 1000; | |
141 | - String signedUrl = url; | |
142 | - String accessToken = null; | |
143 | - String ticket = null; | |
144 | - String signature = null; | |
145 | - | |
146 | - try { | |
147 | - accessToken = AuthHelper.getAccessToken(null); | |
148 | - | |
149 | - ticket = AuthHelper.getJsapiTicket(accessToken,null); | |
150 | - signature = AuthHelper.sign(ticket, nonceStr, timeStamp, signedUrl); | |
151 | - | |
152 | - } catch (OApiException e) { | |
153 | - e.printStackTrace(); | |
154 | - } | |
155 | - | |
156 | - Map<String, Object> configValue = new HashMap<>(); | |
157 | - configValue.put("jsticket", ticket); | |
158 | - configValue.put("signature", signature); | |
159 | - configValue.put("nonceStr", nonceStr); | |
160 | - configValue.put("timeStamp", timeStamp); | |
161 | - configValue.put("corpId", Env.CORP_ID); | |
162 | - configValue.put("agentId", Env.AGENT_ID); | |
163 | - | |
164 | - String config = JSON.toJSONString(configValue); | |
165 | - return config; | |
166 | - } | |
167 | - | |
168 | - public static String getSsoToken() throws OApiException { | |
169 | - String url = "https://oapi.dingtalk.com/sso/gettoken?corpid=" + Env.CORP_ID + "&corpsecret=" + Env.SSO_Secret; | |
170 | - JSONObject response = HttpHelper.httpGet(url); | |
171 | - String ssoToken; | |
172 | - if (response.containsKey("access_token")) { | |
173 | - ssoToken = response.getString("access_token"); | |
174 | - } else { | |
175 | - throw new OApiException("Sso_token"); | |
176 | - } | |
177 | - return ssoToken; | |
178 | - | |
179 | - } | |
180 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/department/DepartmentHelper.java
... | ... | @@ -1,62 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.department; | |
2 | - | |
3 | -import com.dingtalk.open.client.ServiceFactory; | |
4 | -import com.dingtalk.open.client.api.model.corp.Department; | |
5 | -import com.dingtalk.open.client.api.service.corp.CorpDepartmentService; | |
6 | -import com.dingtalk.open.client.common.SdkInitException; | |
7 | -import com.dingtalk.open.client.common.ServiceException; | |
8 | -import com.dingtalk.open.client.common.ServiceNotExistException; | |
9 | - | |
10 | -import java.util.List; | |
11 | - | |
12 | -/** | |
13 | - * 部门相关API | |
14 | - * | |
15 | - * https://open-doc.dingtalk.com/docs/doc.htm?treeId=371&articleId=106817&docType=1 | |
16 | - */ | |
17 | -public class DepartmentHelper { | |
18 | - | |
19 | - /** | |
20 | - * 创建部门 | |
21 | - */ | |
22 | - public static String createDepartment(String accessToken, String name, | |
23 | - String parentId, String order, boolean createDeptGroup) throws Exception { | |
24 | - | |
25 | - CorpDepartmentService corpDepartmentService = ServiceFactory.getInstance().getOpenService(CorpDepartmentService.class); | |
26 | - return corpDepartmentService.deptCreate(accessToken, name, parentId, order, createDeptGroup); | |
27 | - } | |
28 | - | |
29 | - /** | |
30 | - * 获取部门列表 | |
31 | - */ | |
32 | - public static List<Department> listDepartments(String accessToken, String parentDeptId) | |
33 | - throws ServiceNotExistException, SdkInitException, ServiceException { | |
34 | - CorpDepartmentService corpDepartmentService = ServiceFactory.getInstance().getOpenService(CorpDepartmentService.class); | |
35 | - List<Department> deptList = corpDepartmentService.getDeptList(accessToken, parentDeptId); | |
36 | - return deptList; | |
37 | - } | |
38 | - | |
39 | - | |
40 | - /** | |
41 | - * 删除部门 | |
42 | - */ | |
43 | - public static void deleteDepartment(String accessToken, Long id) throws Exception { | |
44 | - CorpDepartmentService corpDepartmentService = ServiceFactory.getInstance().getOpenService(CorpDepartmentService.class); | |
45 | - corpDepartmentService.deptDelete(accessToken, id); | |
46 | - } | |
47 | - | |
48 | - /** | |
49 | - * 更新部门 | |
50 | - */ | |
51 | - public static void updateDepartment(String accessToken, long id, String name, | |
52 | - String parentId, String order, Boolean createDeptGroup, | |
53 | - boolean autoAddUser, String deptManagerUseridList, boolean deptHiding, String deptPerimits, | |
54 | - String userPerimits, Boolean outerDept, String outerPermitDepts, | |
55 | - String outerPermitUsers, String orgDeptOwner) throws Exception { | |
56 | - CorpDepartmentService corpDepartmentService = ServiceFactory.getInstance().getOpenService(CorpDepartmentService.class); | |
57 | - corpDepartmentService.deptUpdate(accessToken, id, name, parentId, order, createDeptGroup, | |
58 | - autoAddUser, deptManagerUseridList, deptHiding, deptPerimits, userPerimits, | |
59 | - outerDept, outerPermitDepts, outerPermitUsers, orgDeptOwner); | |
60 | - | |
61 | - } | |
62 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/eventchange/eventChangeHelper.java
... | ... | @@ -1,80 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.eventchange; | |
2 | - | |
3 | -import com.chinagas.modules.schsf.constant.Env; | |
4 | -import com.chinagas.modules.schsf.exception.OApiException; | |
5 | -import com.chinagas.modules.schsf.utils.HttpHelper; | |
6 | -import com.alibaba.fastjson.JSONObject; | |
7 | - | |
8 | -import java.util.List; | |
9 | - | |
10 | -/** | |
11 | - * 通讯录回调相关事件 | |
12 | - * <p> | |
13 | - * https://open-doc.dingtalk.com/docs/doc.htm?treeId=371&articleId=104975&docType=1 | |
14 | - */ | |
15 | -public class eventChangeHelper { | |
16 | - | |
17 | - /** | |
18 | - * 注册事件回调接口 | |
19 | - */ | |
20 | - public static String registerEventChange(String accessToken, List<String> callBackTag, String token, String aesKey, String url) throws OApiException { | |
21 | - String signUpUrl = Env.OAPI_HOST + "/call_back/register_call_back?" + | |
22 | - "access_token=" + accessToken; | |
23 | - JSONObject args = new JSONObject(); | |
24 | - args.put("call_back_tag", callBackTag); | |
25 | - args.put("token", token); | |
26 | - args.put("aes_key", aesKey); | |
27 | - args.put("url", url); | |
28 | - | |
29 | - JSONObject response = HttpHelper.httpPost(signUpUrl, args); | |
30 | - if (response.containsKey("errcode")) { | |
31 | - return response.getString("errcode"); | |
32 | - } else { | |
33 | - return null; | |
34 | - } | |
35 | - } | |
36 | - | |
37 | - //查询事件回调接口 | |
38 | - public static String getEventChange(String accessToken) throws OApiException { | |
39 | - String url = Env.OAPI_HOST + "/call_back/get_call_back?" + | |
40 | - "access_token=" + accessToken; | |
41 | - JSONObject response = HttpHelper.httpGet(url); | |
42 | - return response.toString(); | |
43 | - } | |
44 | - | |
45 | - //更新事件回调接口 | |
46 | - public static String updateEventChange(String accessToken, List<String> callBackTag, String token, String aesKey, String url) throws OApiException { | |
47 | - String signUpUrl = Env.OAPI_HOST + "/call_back/update_call_back?" + | |
48 | - "access_token=" + accessToken; | |
49 | - JSONObject args = new JSONObject(); | |
50 | - args.put("call_back_tag", callBackTag); | |
51 | - args.put("token", token); | |
52 | - args.put("aes_key", aesKey); | |
53 | - args.put("url", url); | |
54 | - | |
55 | - JSONObject response = HttpHelper.httpPost(signUpUrl, args); | |
56 | - if (response.containsKey("errcode")) { | |
57 | - return response.getString("errcode"); | |
58 | - } else { | |
59 | - return null; | |
60 | - } | |
61 | - } | |
62 | - | |
63 | - //删除事件回调接口 | |
64 | - public static String deleteEventChange(String accessToken) throws OApiException { | |
65 | - String url = Env.OAPI_HOST + "/call_back/delete_call_back?" + | |
66 | - "access_token=" + accessToken; | |
67 | - JSONObject response = HttpHelper.httpGet(url); | |
68 | - return response.toString(); | |
69 | - } | |
70 | - | |
71 | - | |
72 | - public static String getFailedResult(String accessToken) throws OApiException { | |
73 | - String url = Env.OAPI_HOST + "/call_back/get_call_back_failed_result?" + | |
74 | - "access_token=" + accessToken; | |
75 | - JSONObject response = HttpHelper.httpGet(url); | |
76 | - return response.toString(); | |
77 | - } | |
78 | - | |
79 | - | |
80 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/media/MediaHelper.java
... | ... | @@ -1,53 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.media; | |
2 | - | |
3 | -import com.chinagas.modules.schsf.constant.Env; | |
4 | -import com.chinagas.modules.schsf.utils.HttpHelper; | |
5 | -import com.alibaba.fastjson.JSONObject; | |
6 | -import com.dingtalk.open.client.ServiceFactory; | |
7 | -import com.dingtalk.open.client.api.model.corp.UploadResult; | |
8 | -import com.dingtalk.open.client.api.service.corp.MediaService; | |
9 | - | |
10 | -import java.io.File; | |
11 | - | |
12 | -/** | |
13 | - * 管理多媒体文件 | |
14 | - * https://open-doc.dingtalk.com/docs/doc.htm?source=search&treeId=373&articleId=104971&docType=1 | |
15 | - */ | |
16 | -public class MediaHelper { | |
17 | - | |
18 | - /** | |
19 | - * 资源文件类型 | |
20 | - */ | |
21 | - public static final String TYPE_IMAGE = "image"; | |
22 | - public static final String TYPE_VOICE = "voice"; | |
23 | - public static final String TYPE_VIDEO = "video"; | |
24 | - public static final String TYPE_FILE = "file"; | |
25 | - | |
26 | - | |
27 | - public static class MediaUploadResult { | |
28 | - public String type; | |
29 | - public String media_id; | |
30 | - public String created_at; | |
31 | - } | |
32 | - | |
33 | - /** | |
34 | - * 上传多媒体文件 | |
35 | - * <p> | |
36 | - */ | |
37 | - public static UploadResult upload(String accessToken, String type, File file) throws Exception { | |
38 | - | |
39 | - MediaService mediaService = ServiceFactory.getInstance().getOpenService(MediaService.class); | |
40 | - UploadResult uploadResult = mediaService.uploadMediaFile(accessToken, type, file); | |
41 | - return uploadResult; | |
42 | - } | |
43 | - | |
44 | - /** | |
45 | - * 下载多媒体文件,目前sdk没有封装此接口,需要通过HTTP访问 | |
46 | - */ | |
47 | - public static void download(String accessToken, String mediaId, String fileDir) throws Exception { | |
48 | - String url = Env.OAPI_HOST + "/media/downloadFile?" + | |
49 | - "access_token=" + accessToken + "&media_id=" + mediaId; | |
50 | - JSONObject response = HttpHelper.downloadMedia(url, fileDir); | |
51 | - System.out.println(response); | |
52 | - } | |
53 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/ConversationMessageDelivery.java
... | ... | @@ -1,16 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | -public class ConversationMessageDelivery extends MessageDelivery { | |
4 | - | |
5 | - public String sender; | |
6 | - public String cid; | |
7 | - public String agentid; | |
8 | - | |
9 | - public ConversationMessageDelivery(String sender, String cid, | |
10 | - String agentId) { | |
11 | - this.sender = sender; | |
12 | - this.cid = cid; | |
13 | - this.agentid = agentId; | |
14 | - } | |
15 | - | |
16 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/ImageMessage.java
... | ... | @@ -1,17 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | - | |
4 | -public class ImageMessage extends Message { | |
5 | - | |
6 | - public String media_id; | |
7 | - | |
8 | - public ImageMessage(String mediaId) { | |
9 | - super(); | |
10 | - media_id = mediaId; | |
11 | - } | |
12 | - | |
13 | - @Override | |
14 | - public String type() { | |
15 | - return "image"; | |
16 | - } | |
17 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/LightAppMessageDelivery.java
... | ... | @@ -1,15 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | -public class LightAppMessageDelivery extends MessageDelivery { | |
4 | - | |
5 | - public String touser; | |
6 | - public String toparty; | |
7 | - public String agentid; | |
8 | - | |
9 | - public LightAppMessageDelivery(String toUsers, String toParties, String agentId) { | |
10 | - this.touser = toUsers; | |
11 | - this.toparty = toParties; | |
12 | - this.agentid = agentId; | |
13 | - } | |
14 | - | |
15 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/LinkMessage.java
... | ... | @@ -1,22 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | -public class LinkMessage extends Message { | |
4 | - | |
5 | - public String messageUrl; | |
6 | - public String picUrl; | |
7 | - public String title; | |
8 | - public String text; | |
9 | - | |
10 | - public LinkMessage(String messageUrl, String picUrl, String title, String text) { | |
11 | - super(); | |
12 | - this.messageUrl = messageUrl; | |
13 | - this.picUrl = picUrl; | |
14 | - this.title = title; | |
15 | - this.text = text; | |
16 | - } | |
17 | - | |
18 | - @Override | |
19 | - public String type() { | |
20 | - return "link"; | |
21 | - } | |
22 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/Message.java
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/MessageDelivery.java
... | ... | @@ -1,15 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | -import com.dingtalk.open.client.api.model.corp.MessageBody; | |
4 | - | |
5 | -public class MessageDelivery { | |
6 | - | |
7 | - public String msgType; | |
8 | - public MessageBody message; | |
9 | - | |
10 | - public MessageDelivery withMessage(String msgType, MessageBody msg) { | |
11 | - this.msgType = msgType; | |
12 | - this.message = msg; | |
13 | - return this; | |
14 | - } | |
15 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/MessageHelper.java
... | ... | @@ -1,43 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | -import com.dingtalk.open.client.ServiceFactory; | |
4 | -import com.dingtalk.open.client.api.model.corp.MessageSendResult; | |
5 | -import com.dingtalk.open.client.api.service.corp.MessageService; | |
6 | - | |
7 | -/** | |
8 | - * 发送消息 | |
9 | - */ | |
10 | -public class MessageHelper { | |
11 | - | |
12 | - public static class Receipt { | |
13 | - String invaliduser; | |
14 | - String invalidparty; | |
15 | - } | |
16 | - | |
17 | - /** | |
18 | - * 发送普通消息 | |
19 | - * | |
20 | - * @param accessToken | |
21 | - * @param delivery | |
22 | - * @return | |
23 | - * @throws Exception | |
24 | - */ | |
25 | - public static Receipt send(String accessToken, LightAppMessageDelivery delivery) | |
26 | - throws Exception { | |
27 | - MessageService messageService = ServiceFactory.getInstance().getOpenService(MessageService.class); | |
28 | - MessageSendResult reulst = messageService.sendToCorpConversation(accessToken, delivery.touser, | |
29 | - delivery.toparty, delivery.agentid, delivery.msgType, delivery.message); | |
30 | - Receipt receipt = new Receipt(); | |
31 | - receipt.invaliduser = reulst.getInvaliduser(); | |
32 | - receipt.invalidparty = reulst.getInvalidparty(); | |
33 | - return receipt; | |
34 | - } | |
35 | - | |
36 | - | |
37 | - public static String send(String accessToken, ConversationMessageDelivery delivery) | |
38 | - throws Exception { | |
39 | - MessageService messageService = ServiceFactory.getInstance().getOpenService(MessageService.class); | |
40 | - return messageService.sendToNormalConversation(accessToken, delivery.sender, | |
41 | - delivery.cid, delivery.msgType, delivery.message); | |
42 | - } | |
43 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/OAMessage.java
... | ... | @@ -1,69 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | -import java.util.List; | |
4 | - | |
5 | -/** | |
6 | - { | |
7 | - "message_url": "http://dingtalk.com", | |
8 | - "head": { | |
9 | - "bgcolor": "FFCC0000" | |
10 | - }, | |
11 | - "body": { | |
12 | - "title": "标题", | |
13 | - "form": [ | |
14 | - { | |
15 | - "key": "姓名", | |
16 | - "value": "张三" | |
17 | - }, | |
18 | - { | |
19 | - "key": "年龄", | |
20 | - "value": "30" | |
21 | - } | |
22 | - ], | |
23 | - "rich": { | |
24 | - "num": "15.6", | |
25 | - "unit": "元" | |
26 | - }, | |
27 | - "content": "大段文本", | |
28 | - "image": "@lADOAAGXIszazQKA", | |
29 | - "file_count": "3", | |
30 | - "author": "李四" | |
31 | - } | |
32 | - */ | |
33 | -public class OAMessage extends Message { | |
34 | - | |
35 | - public String message_url; | |
36 | - public Head head; | |
37 | - public Body body; | |
38 | - | |
39 | - | |
40 | - @Override | |
41 | - public String type() { | |
42 | - return "oa"; | |
43 | - } | |
44 | - | |
45 | - //content | |
46 | - public static class Head { | |
47 | - public String bgcolor; | |
48 | - } | |
49 | - | |
50 | - public static class Body { | |
51 | - public String title; | |
52 | - public List<Form> form; | |
53 | - public Rich rich; | |
54 | - public String content; | |
55 | - public String image; | |
56 | - public String file_found; | |
57 | - public String author; | |
58 | - | |
59 | - public static class Form { | |
60 | - public String key; | |
61 | - public String value; | |
62 | - } | |
63 | - | |
64 | - public static class Rich { | |
65 | - public String num; | |
66 | - public String unit; | |
67 | - } | |
68 | - } | |
69 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/message/TextMessage.java
... | ... | @@ -1,17 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.message; | |
2 | - | |
3 | - | |
4 | -public class TextMessage extends Message { | |
5 | - | |
6 | - public String content; | |
7 | - | |
8 | - public TextMessage(String content) { | |
9 | - super(); | |
10 | - this.content = content; | |
11 | - } | |
12 | - | |
13 | - @Override | |
14 | - public String type() { | |
15 | - return "text"; | |
16 | - } | |
17 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/user/User.java
... | ... | @@ -1,43 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.user; | |
2 | - | |
3 | -import java.util.List; | |
4 | - | |
5 | -import com.alibaba.fastjson.JSONObject; | |
6 | - | |
7 | -public class User { | |
8 | - public String userid; | |
9 | - public String name; | |
10 | - public boolean active; | |
11 | - public String avatar; | |
12 | - public List<Long> department; | |
13 | - public String position; | |
14 | - public String mobile; | |
15 | - public String tel; | |
16 | - public String workPlace; | |
17 | - public String remark; | |
18 | - public String email; | |
19 | - public String jobnumber; | |
20 | - public JSONObject extattr; | |
21 | - public boolean isAdmin; | |
22 | - public boolean isBoss; | |
23 | - public String dingId; | |
24 | - | |
25 | - | |
26 | - | |
27 | - public User() { | |
28 | - } | |
29 | - | |
30 | - public User(String userid, String name) { | |
31 | - this.userid = userid; | |
32 | - this.name = name; | |
33 | - } | |
34 | - | |
35 | - @Override | |
36 | - public String toString() { | |
37 | - List<User> users; | |
38 | - return "User[userid:" + userid + ", name:" + name + ", active:" + active + ", " | |
39 | - + "avatar:" + avatar + ", department:" + department + | |
40 | - ", position:" + position + ", mobile:" + mobile + ", email:" + email + | |
41 | - ", extattr:" + extattr; | |
42 | - } | |
43 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/openApi/user/UserHelper.java
... | ... | @@ -1,143 +0,0 @@ |
1 | -package com.chinagas.modules.schsf.openApi.user; | |
2 | - | |
3 | -import com.chinagas.modules.schsf.constant.Env; | |
4 | -import com.chinagas.modules.schsf.exception.OApiException; | |
5 | -import com.chinagas.modules.schsf.utils.FileUtils; | |
6 | -import com.chinagas.modules.schsf.utils.HttpHelper; | |
7 | -import com.alibaba.fastjson.JSONObject; | |
8 | -import com.dingtalk.open.client.ServiceFactory; | |
9 | -import com.dingtalk.open.client.api.model.corp.CorpUserBaseInfo; | |
10 | -import com.dingtalk.open.client.api.model.corp.CorpUserDetail; | |
11 | -import com.dingtalk.open.client.api.model.corp.CorpUserDetailList; | |
12 | -import com.dingtalk.open.client.api.model.corp.CorpUserList; | |
13 | -import com.dingtalk.open.client.api.service.corp.CorpUserService; | |
14 | - | |
15 | -import java.util.List; | |
16 | -import java.util.Map; | |
17 | - | |
18 | -/** | |
19 | - * 通讯录成员相关的接口调用 | |
20 | - */ | |
21 | -public class UserHelper { | |
22 | - | |
23 | - | |
24 | - /** | |
25 | - * 根据免登授权码查询免登用户userId | |
26 | - * | |
27 | - * @param accessToken | |
28 | - * @param code | |
29 | - * @return | |
30 | - * @throws Exception | |
31 | - */ | |
32 | - public static CorpUserBaseInfo getUserInfo(String accessToken, String code) throws Exception { | |
33 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
34 | - return corpUserService.getUserinfo(accessToken, code); | |
35 | - } | |
36 | - | |
37 | - /** | |
38 | - * 创建企业成员 | |
39 | - * <p> | |
40 | - * https://open-doc.dingtalk.com/docs/doc.htm?treeId=385&articleId=106816&docType=1#s1 | |
41 | - */ | |
42 | - public static String createUser(String accessToken, CorpUserDetail userDetail) throws Exception { | |
43 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
44 | - JSONObject js = (JSONObject) JSONObject.parse(userDetail.getOrderInDepts()); | |
45 | - Map<Long, Long> orderInDepts = FileUtils.toHashMap(js); | |
46 | - | |
47 | - String userId = corpUserService.createCorpUser(accessToken, userDetail.getUserid(), userDetail.getName(), orderInDepts, | |
48 | - userDetail.getDepartment(), userDetail.getPosition(), userDetail.getMobile(), userDetail.getTel(), userDetail.getWorkPlace(), | |
49 | - userDetail.getRemark(), userDetail.getEmail(), userDetail.getJobnumber(), | |
50 | - userDetail.getIsHide(), userDetail.getSenior(), userDetail.getExtattr()); | |
51 | - | |
52 | - // 员工唯一标识ID | |
53 | - return userId; | |
54 | - } | |
55 | - | |
56 | - | |
57 | - /** | |
58 | - * 更新成员 | |
59 | - * <p> | |
60 | - * https://open-doc.dingtalk.com/docs/doc.htm?treeId=385&articleId=106816&docType=1#s2 | |
61 | - */ | |
62 | - public static void updateUser(String accessToken, CorpUserDetail userDetail) throws Exception { | |
63 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
64 | - JSONObject js = (JSONObject) JSONObject.parse(userDetail.getOrderInDepts()); | |
65 | - Map<Long, Long> orderInDepts = FileUtils.toHashMap(js); | |
66 | - | |
67 | - corpUserService.updateCorpUser(accessToken, userDetail.getUserid(), userDetail.getName(), orderInDepts, | |
68 | - userDetail.getDepartment(), userDetail.getPosition(), userDetail.getMobile(), userDetail.getTel(), userDetail.getWorkPlace(), | |
69 | - userDetail.getRemark(), userDetail.getEmail(), userDetail.getJobnumber(), | |
70 | - userDetail.getIsHide(), userDetail.getSenior(), userDetail.getExtattr()); | |
71 | - } | |
72 | - | |
73 | - | |
74 | - /** | |
75 | - * 删除成员 | |
76 | - */ | |
77 | - public static void deleteUser(String accessToken, String userid) throws Exception { | |
78 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
79 | - corpUserService.deleteCorpUser(accessToken, userid); | |
80 | - } | |
81 | - | |
82 | - | |
83 | - //获取成员 | |
84 | - public static CorpUserDetail getUser(String accessToken, String userid) throws Exception { | |
85 | - | |
86 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
87 | - return corpUserService.getCorpUser(accessToken, userid); | |
88 | - } | |
89 | - | |
90 | - //批量删除成员 | |
91 | - public static void batchDeleteUser(String accessToken, List<String> useridlist) | |
92 | - throws Exception { | |
93 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
94 | - corpUserService.batchdeleteCorpUserListByUserids(accessToken, useridlist); | |
95 | - | |
96 | - } | |
97 | - | |
98 | - | |
99 | - //获取部门成员 | |
100 | - public static CorpUserList getDepartmentUser( | |
101 | - String accessToken, | |
102 | - long departmentId, | |
103 | - Long offset, | |
104 | - Integer size, | |
105 | - String order) | |
106 | - throws Exception { | |
107 | - | |
108 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
109 | - return corpUserService.getCorpUserSimpleList(accessToken, departmentId, | |
110 | - offset, size, order); | |
111 | - } | |
112 | - | |
113 | - | |
114 | - //获取部门成员(详情) | |
115 | - public static CorpUserDetailList getUserDetails( | |
116 | - String accessToken, | |
117 | - long departmentId, | |
118 | - Long offset, | |
119 | - Integer size, | |
120 | - String order) | |
121 | - throws Exception { | |
122 | - | |
123 | - CorpUserService corpUserService = ServiceFactory.getInstance().getOpenService(CorpUserService.class); | |
124 | - return corpUserService.getCorpUserList(accessToken, departmentId, | |
125 | - offset, size, order); | |
126 | - } | |
127 | - | |
128 | - | |
129 | - /** | |
130 | - * 管理后台免登时通过CODE换取微应用管理员的身份信息 | |
131 | - * | |
132 | - * @param ssoToken | |
133 | - * @param code | |
134 | - * @return | |
135 | - * @throws OApiException | |
136 | - */ | |
137 | - public static JSONObject getAgentUserInfo(String ssoToken, String code) throws OApiException { | |
138 | - String url = Env.OAPI_HOST + "/sso/getuserinfo?" + "access_token=" + ssoToken + "&code=" + code; | |
139 | - JSONObject response = HttpHelper.httpGet(url); | |
140 | - return response; | |
141 | - } | |
142 | - | |
143 | -} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/service/DingtalkService.java
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +package com.chinagas.modules.schsf.service; | |
2 | + | |
3 | +public interface DingtalkService { | |
4 | + | |
5 | + | |
6 | + String getAccessToken(Long timeStamp); | |
7 | + | |
8 | + | |
9 | + String getJsapiTicket(String accessToken, Long timeStamp); | |
10 | + | |
11 | + String getSign(String ticket, String nonceStr, Long timeStamp, String url); | |
12 | + | |
13 | +} | ... | ... |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/service/impl/DingtalkServiceImpl.java
0 → 100644
... | ... | @@ -0,0 +1,79 @@ |
1 | +package com.chinagas.modules.schsf.service.impl; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSONObject; | |
4 | +import com.chinagas.common.core.exceptions.ServiceException; | |
5 | +import com.chinagas.modules.schsf.constant.DingtalkConstant; | |
6 | +import com.chinagas.modules.schsf.exception.OApiException; | |
7 | +import com.chinagas.modules.schsf.service.DingtalkService; | |
8 | +import com.dingtalk.oapi.lib.aes.DingTalkJsApiSingnature; | |
9 | +import com.dingtalk.open.client.ServiceFactory; | |
10 | +import com.dingtalk.open.client.api.model.corp.JsapiTicket; | |
11 | +import com.dingtalk.open.client.api.service.corp.CorpConnectionService; | |
12 | +import com.dingtalk.open.client.api.service.corp.JsapiService; | |
13 | +import org.springframework.beans.factory.annotation.Autowired; | |
14 | +import org.springframework.stereotype.Service; | |
15 | + | |
16 | +@Service | |
17 | +public class DingtalkServiceImpl implements DingtalkService { | |
18 | + | |
19 | + @Autowired | |
20 | + private DingtalkConstant dingtalkConstant; | |
21 | + | |
22 | + | |
23 | + /** | |
24 | + * 调整到1小时50分钟 | |
25 | + */ | |
26 | + public static final long cacheTime = 1000 * 60 * 55 * 2; | |
27 | + | |
28 | + @Override | |
29 | + public String getAccessToken(Long timeStamp) { | |
30 | + long curTime = timeStamp == null ? System.currentTimeMillis() : timeStamp; | |
31 | + String accToken = ""; | |
32 | + JSONObject jsontemp = new JSONObject(); | |
33 | + try { | |
34 | + ServiceFactory serviceFactory = ServiceFactory.getInstance(); | |
35 | + CorpConnectionService corpConnectionService = serviceFactory.getOpenService(CorpConnectionService.class); | |
36 | + accToken = corpConnectionService.getCorpToken(dingtalkConstant.getAppKey(), dingtalkConstant.getAppSecret()); | |
37 | + JSONObject jsonAccess = new JSONObject(); | |
38 | + jsontemp.clear(); | |
39 | + jsontemp.put("access_token", accToken); | |
40 | + jsontemp.put("begin_time", curTime); | |
41 | + jsonAccess.put(dingtalkConstant.getAppKey(), jsontemp); | |
42 | + } catch (Exception e) { | |
43 | + e.printStackTrace(); | |
44 | + } | |
45 | + return accToken; | |
46 | + } | |
47 | + | |
48 | + @Override | |
49 | + public String getJsapiTicket(String accessToken, Long timeStamp) { | |
50 | + long curTime = timeStamp == null ? System.currentTimeMillis() : timeStamp; | |
51 | + String jsTicket = ""; | |
52 | + ServiceFactory serviceFactory; | |
53 | + try { | |
54 | + serviceFactory = ServiceFactory.getInstance(); | |
55 | + JsapiService jsapiService = serviceFactory.getOpenService(JsapiService.class); | |
56 | + JsapiTicket JsapiTicket = jsapiService.getJsapiTicket(accessToken, "jsapi"); | |
57 | + jsTicket = JsapiTicket.getTicket(); | |
58 | + JSONObject jsonTicket = new JSONObject(); | |
59 | + JSONObject jsontemp = new JSONObject(); | |
60 | + jsontemp.clear(); | |
61 | + jsontemp.put("ticket", jsTicket); | |
62 | + jsontemp.put("begin_time", curTime); | |
63 | + jsonTicket.put(dingtalkConstant.getAppKey(), jsontemp); | |
64 | + } catch (Exception e) { | |
65 | + e.printStackTrace(); | |
66 | + } | |
67 | + return jsTicket; | |
68 | + | |
69 | + } | |
70 | + | |
71 | + @Override | |
72 | + public String getSign(String ticket, String nonceStr, Long timeStamp, String url) { | |
73 | + try { | |
74 | + return DingTalkJsApiSingnature.getJsApiSingnature(url, nonceStr, timeStamp, ticket); | |
75 | + } catch (Exception ex) { | |
76 | + throw new ServiceException(ex.getMessage()); | |
77 | + } | |
78 | + } | |
79 | +} | ... | ... |