dingtalk.corp.message.corpconversation.asyncsend企业会话消息异步发送,Missing method
Redingtalk.corp.message.corpconversation.asyncsend企业会话消息异步发送,Missing meth
三。源码
AsyncMessage
package com.ray.dingtalk.model.message.asyncsend;/**@desc : * * 参考文档地址:https://open-doc.dingtalk.com/docs/ * doc.htm?spm=a219a.7629140.0.0.hZSBgV&treeId=385& * articleId=28915&docType=2 * * @author: shirayner * @date : 2017年10月13日 下午1:53:40 */public class AsyncMessage { //1.公共参数 //必须 ,API接口名称 private String method; //必须 ,钉钉提供的授权Token private String session; //必须,时间戳,格式为yyyy-MM-dd HH:mm:ss,时区为GMT+8,例如:2015-01-01 12:00:00。 //淘宝API服务端允许客户端请求最大时间误差为10分钟。 private String timestamp; //必须,API协议版本,可选值:2.0。 private String v; //2.请求参数 private String msgtype; //必须,微应用的id private Number agent_id; //必须,与msgtype对应的消息体,参见文档 private String msgcontent; //否 private String [] userid_list; //否 private Boolean to_all_user; public String getMethod() { return method; } public void setMethod(String method) { this.method = method; } public String getSession() { return session; } public void setSession(String session) { this.session = session; } public String getTimestamp() { return timestamp; } public void setTimestamp(String timestamp) { this.timestamp = timestamp; } public String getV() { return v; } public void setV(String v) { this.v = v; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public Number getAgent_id() { return agent_id; } public void setAgent_id(Number agent_id) { this.agent_id = agent_id; } public String getMsgcontent() { return msgcontent; } public String[] getUserid_list() { return userid_list; } public void setUserid_list(String[] userid_list) { this.userid_list = userid_list; } public Boolean getTo_all_user() { return to_all_user; } public void setTo_all_user(Boolean to_all_user) { this.to_all_user = to_all_user; } public void setMsgcontent(String msgcontent) { this.msgcontent = msgcontent; } }
2.AsyncSendMessageService
package com.ray.dingtalk.service.message.asyncsend;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;import com.ray.dingtalk.model.message.asyncsend.AsyncMessage;import com.ray.dingtalk.util.HttpHelper;/**@desc : 主动发送异步消息 * * @author: shirayner * @date : 2017年10月13日 下午1:39:46 */public class AsyncSendMessageService { private static final String SEND_ASYNCSENDMESSAGE_URL='https://eco.taobao.com/router/rest'; public void sendMessage(String accessToken) throws Exception{ //1.封装请求参数 String method='dingtalk.corp.message.corpconversation.asyncsend'; String session =accessToken; String timestamp= String.valueOf( System.currentTimeMillis() / 1000 ); String v='2.0'; String msgtype ='text'; Number agent_id=128838526; String msgcontent='发送异步消息测试'; Boolean to_all_user=true; AsyncMessage cca=new AsyncMessage(); cca.setMethod(method); cca.setSession(session); cca.setTimestamp(timestamp); cca.setV(v); cca.setMsgtype(msgtype); cca.setAgent_id(agent_id); cca.setMsgcontent(msgcontent); cca.setTo_all_user(to_all_user); //1.准备POST请求参数 Object data=JSON.toJSON(cca); //将javaBean 转为 json System.out.println(data); //2.获取请求url String url=SEND_ASYNCSENDMESSAGE_URL; //3.发起POST请求,获取返回结果 JSONObject jsonObject=HttpHelper.httpPost(url, data); System.out.println('jsonObject:'+jsonObject.toString()); //4.解析结果,获取 if (null != jsonObject) { //5.错误消息处理 if (0 != jsonObject.getInteger('errcode')) { int errCode = jsonObject.getInteger('errcode'); String errMsg = jsonObject.getString('errmsg'); throw new Exception('error code:'+errCode+', error message:'+errMsg); } } } }
3.AsyncSendMessageServiceTest
/**@desc : * * @author: shirayner * @date : 2017年10月13日 下午2:36:27 */public class AsyncSendMessageServiceTest { @Test public void testSendNotice() throws Exception { String accessToken=AuthHelper.getAccessToken(Env.CORP_ID, Env.CORP_SECRET); AsyncSendMessageService asm=new AsyncSendMessageService(); asm.sendMessage(accessToken); } }
赞0
踩0