资源简介

已实现项目开发钉钉向个人推送消息和与H5微应用操作步骤,内含代码,亲测有效。

资源截图

代码片段和文件信息

package com.yfajh.dingding.service;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.dingtalk.api.request.OapiUserGetRequest;
import com.dingtalk.api.request.OapiUserGetuserinfoRequest;
import com.dingtalk.api.request.OapiUserSimplelistRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
import com.dingtalk.api.response.OapiUserGetResponse;
import com.dingtalk.api.response.OapiUserGetuserinfoResponse;
import com.dingtalk.api.response.OapiUserSimplelistResponse;
import com.sdjxd.pms.platform.data.DbOper;
 
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.RowSet;
 
/**
 * @Auther: XXX
 * @Date: 2019/4/3 10:37
 * @Description: 钉钉发送工作消息
 */
public class MobilePushMsg {
//E应用接口需要参数
    private static String APPKEY = “XXX“;
 
    private static String APPSECRET = “XXX“;
 
    private static long AGENT_ID = XXX;
    
    //微应用接口需要参数
    private static String APPKEY_W = “dingdmil6usotg3cfsma“;
 
    private static String APPSECRET_W = “XXXX“;
 
    private static long AGENT_ID_W = XXXX;
 
    private static Map map = new HashMap(16);
 
   
    
 
    /**
     * 根据手机号码发送工作消息
     * @param mobile
     * @param content
     */
    public static void send(String mobile String content) {
        try {
            String accessToken = getAccessToken();
            if (map == null) {
                initUserList(accessToken);
            }
            int userListCount = getUserListCount(accessToken);
            if (userListCount > map.size()) {
                initUserList(accessToken);
            }
            senWorkMsg(accessToken map.get(mobile) content);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取E应用 accessToken
     *
     * @return
     * @throws Exception
     */
    public static String getAccessToken() throws Exception {
        DefaultDingTalkClient client = new DefaultDingTalkClient(“https://oapi.dingtalk.com/gettoken“);
        OapiGettokenRequest request = new OapiGettokenRequest();
 
        request.setAppkey(APPKEY);
        request.setAppsecret(APPSECRET);
        request.setHttpMethod(“GET“);
        OapiGettokenResponse response = client.execute(request);
        String accessToken = response.getAccessToken();
        return accessToken;
    }
    /**
     * 获取微应用 accessToken
     *
     * @return
     * @throws Exception
     */
    public static String getWAccessToken() throws Exception {
        DefaultDingTalkClient client = new DefaultDingTalkClient(“https://oapi.dingtalk.com/gettoken“);
        OapiGettokenReques

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       8435  2019-09-19 09:10  钉钉推送消息和H5微应用集成\MobilePushMsg.java

     文件     371816  2019-09-19 09:41  钉钉推送消息和H5微应用集成\钉钉H5微应用集成方案说明书.docx

     文件     300881  2019-09-19 09:38  钉钉推送消息和H5微应用集成\钉钉消息集成方案说明书.docx

     目录          0  2019-09-19 09:42  钉钉推送消息和H5微应用集成

----------- ---------  ---------- -----  ----

               681132                    4


评论

共有 条评论