| package com.matrix.component.dingding; | 
|   | 
|   | 
| import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.tools.LogUtil; | 
| import com.matrix.core.tools.StringUtils; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.web.bind.annotation.PathVariable; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
|   | 
|   | 
| /** | 
|  * @author jiangyouyao | 
|  * @description 钉钉对外接口 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "/dingding") | 
| public class DingdingAction { | 
|   | 
|   | 
|     /** | 
|      * 列表显示 | 
|      */ | 
|     @RequestMapping(value = "/getDingdingConfig") | 
|     public @ResponseBody | 
|     AjaxResult getDingdingConfig() { | 
|         AjaxResult result = AjaxResult.buildSuccessInstance("success"); | 
|         result.setMapInfo(AuthHelper.getConfig()); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * @Description:检查是否绑定账号 | 
|      * @author:dingchuan | 
|      * @param code | 
|      * @return | 
|      * @throws Exception | 
|      *             返回类型 AjaxResult | 
|      * @date 2016年11月27日 | 
|      */ | 
|     @RequestMapping(value = "/getDdUserId/{code}") | 
|     public @ResponseBody | 
|     AjaxResult checkIsBinding(@PathVariable String code) { | 
|         LogUtil.debug(code); | 
|         String ddUserId=""; | 
|         try { | 
|             String accessToken = AuthHelper.getAccessToken(); | 
|             LogUtil.info(accessToken); | 
|             // 用户基本信息 | 
|              ddUserId = UserHelper.getUserInfo(accessToken, code); | 
|              LogUtil.info(ddUserId); | 
|         } catch (Exception e) { | 
|             LogUtil.error("获取ddUserId错误",e); | 
|         } | 
|         return AjaxResult.buildSuccessInstance(ddUserId); | 
|     } | 
|   | 
|   | 
|     @RequestMapping(value = "/sendOAMsg/{userId}") | 
|     public @ResponseBody | 
|     AjaxResult sendOAMsg(@PathVariable String userId) throws OApiException { | 
|         // 循环发送OA消息 | 
|         // 获取accessToken | 
|         String accessToken = AuthHelper.getAccessToken(); | 
|         OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg(); | 
|         msg.setMsgtype("link"); | 
|         msg.setLink(new OapiMessageCorpconversationAsyncsendV2Request.Link()); | 
|         msg.getLink().setTitle("审批通知"); | 
|         msg.getLink().setText("你还有几个流程需要审核请尽快处理"+ StringUtils.getRandomString(10)); | 
|         msg.getLink().setMessageUrl(DDEnvConfig.FUNCTION_URL); | 
|         msg.getLink().setPicUrl(DDEnvConfig.LOGO_IMG); | 
|         MessageSendUtil.sendOAMsg(accessToken, userId, msg); | 
|         return AjaxResult.buildSuccessInstance("发送成功"); | 
|     } | 
|   | 
|   | 
|   | 
| } |