| | |
| | | package com.ycl.controller.dingding; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient; |
| | | import com.alibaba.xxpt.gateway.shared.client.http.GetClient; |
| | | import com.alibaba.xxpt.gateway.shared.client.http.PostClient; |
| | | import com.ycl.api.CommonResult; |
| | | import com.ycl.bo.AdminUserDetails; |
| | | import com.ycl.common.dingding.DingCommon; |
| | | import com.ycl.config.DingConfig; |
| | | import com.ycl.controller.BaseController; |
| | | import com.ycl.entity.dingding.DingUserInfo; |
| | | import com.ycl.service.auth.AuthService; |
| | |
| | | import com.ycl.vo.NewAddressBookVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.ycl.common.constant.DingConst.GET_TIKER; |
| | | import static com.ycl.common.constant.DingConst.GET_TOKEN; |
| | | |
| | | @RestController |
| | | @RequestMapping("/ding") |
| | | @Api(tags = "钉钉") |
| | | @Slf4j |
| | | public class DingController extends BaseController { |
| | | |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private BookRemarkService bookRemarkService; |
| | | |
| | | @Resource |
| | | private ExecutableClient executableClient; |
| | | |
| | | @Resource |
| | | private DingConfig dingConfig; |
| | | |
| | | |
| | | @ApiOperation(value = "根据钉钉授权码获取token") |
| | | @GetMapping("/dingLogin") |
| | | public CommonResult<Map> dingLogin(@RequestParam String code) { |
| | |
| | | map.put("tokenHead", tokenHead); |
| | | map.put("accountId", dingUser.getAccountId()); |
| | | return CommonResult.success(map); |
| | | } |
| | | |
| | | @ApiOperation(value = "根据钉钉授权码获取jsapiToken") |
| | | @GetMapping("/dingTicker") |
| | | public CommonResult<Map> dingTicker() { |
| | | String accessToken = getToken(); |
| | | String ticket = getTiker(accessToken); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | |
| | | map.put("accessToken", accessToken); |
| | | |
| | | map.put("ticket", ticket); |
| | | return CommonResult.success(map); |
| | | } |
| | | |
| | | private String getToken() { |
| | | //调用API |
| | | GetClient getTokenClient = executableClient.newGetClient(GET_TOKEN); |
| | | //设置参数 |
| | | getTokenClient.addParameter("appkey", dingConfig.getAppKey()); |
| | | getTokenClient.addParameter("appsecret", dingConfig.getAppSecret()); |
| | | String apiResult = getTokenClient.get(); |
| | | return parsingResult(apiResult); |
| | | } |
| | | |
| | | private String getTiker(String accToken) { |
| | | //调用API |
| | | PostClient postClient = executableClient.newPostClient(GET_TIKER); |
| | | //设置参数 |
| | | if (ObjectUtil.isNotNull(accToken)) { |
| | | postClient.addParameter("accessToken", accToken); |
| | | postClient.addParameter("appkey", dingConfig.getAppKey()); |
| | | postClient.addParameter("appsecret", dingConfig.getAppSecret()); |
| | | String apiResult = postClient.post(); |
| | | return parsingResult(apiResult); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String parsingResult(String apiResult) { |
| | | if (ObjectUtil.isNotNull(apiResult)) { |
| | | JSONObject resJson = JSONObject.parseObject(apiResult); |
| | | if (resJson.getBoolean("success")) { |
| | | JSONObject content = resJson.getJSONObject("content"); |
| | | if (content.getBoolean("success")) { |
| | | JSONObject dataObj = content.getJSONObject("data"); |
| | | String accessToken = dataObj.getString("accessToken"); |
| | | return accessToken; |
| | | } |
| | | } else { |
| | | log.error(resJson.toJSONString()); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @ApiOperation(value = "通讯录") |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "通讯录递归") |
| | | @GetMapping("/getDddressBook") |
| | | public CommonResult<NewAddressBookVO> getNewAddressBook(@RequestParam("id") Long id) { |
| | | AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| | | return CommonResult.success(dingService.getAddressBookById(id, user.getUserId())); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "修改通讯录备注") |