JAVA maven項(xiàng)目使用釘釘SDK獲取token、用戶
本文介紹了JAVA maven項(xiàng)目使用釘釘SDK獲取token、用戶,分享給大家,具體如下:
將SDK放一個(gè)文件里,記住文件地址。D:\eclipse-workspace\項(xiàng)目名\模塊名\lib
win+r cmd 敲下面的命令:
【進(jìn)入相應(yīng)盤】 D:
【進(jìn)入文件地址】 cd D:\eclipse-workspace\項(xiàng)目名\模塊名
【運(yùn)行命令】 mvn install:install-file -DgroupId=com.dingtalk.api -DartifactId=top-api-sdk-dev -Dversion=ding-open-mc-SNAPSHOT -Dfile=lib/taobao-sdk-java-auto_1479188381469-20200319.jar -Dpackaging=jar -DgeneratePom=true
然后在pom文件中增加以下內(nèi)容:
<!--釘釘工具包--> <dependency> <groupId>com.dingtalk.api</groupId> <artifactId>top-api-sdk-dev</artifactId> <version>ding-open-mc-SNAPSHOT</version> </dependency>
理解:普通的maven項(xiàng)目都會(huì)在pom里配置好jar,項(xiàng)目自動(dòng)從maven中配置的鏡像地址(就是網(wǎng)上)自己把jar包下載到你設(shè)置的位置
但是有些jar包下載不下來(lái),可以先本地保存,然后像上面那樣用命令把jar包掛到maven設(shè)置的jar庫(kù)里去
JAVA后臺(tái)代碼:
import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.request.OapiDepartmentListRequest; import com.dingtalk.api.request.OapiGettokenRequest; import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request; import com.dingtalk.api.request.OapiUserSimplelistRequest; import com.dingtalk.api.response.OapiDepartmentListResponse; import com.dingtalk.api.response.OapiGettokenResponse; import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response; import com.dingtalk.api.response.OapiUserSimplelistResponse; import com.taobao.api.ApiException; import com.dingtalk.api.response.OapiDepartmentListResponse.Department; import com.dingtalk.api.request.*; import com.dingtalk.api.response.*; 。。。 登錄接口方法(前端傳來(lái)code){ // 釘釘 /gettoken 獲取token,只需填寫(xiě)appkey和appsecret try { DingTalkClient client1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest req1 = new OapiGettokenRequest(); req1.setAppkey("xxxxxxxx"); req1.setAppsecret("xxxxxxxx"); req1.setHttpMethod("GET"); OapiGettokenResponse rsp1 = client1.execute(req1); System.out.println(rsp1.getBody()); accessToken = rsp1.getAccessToken(); } catch (Exception e) { //} catch (ApiException e) { e.printStackTrace(); } // 釘釘 /user/getuserinfo 獲取用戶userid try { DingTalkClient client2 = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getuserinfo"); OapiUserGetuserinfoRequest req2 = new OapiUserGetuserinfoRequest(); req2.setCode(code);// req2.setHttpMethod("GET"); OapiUserGetuserinfoResponse rsp2 = client2.execute(req2, accessToken);// System.out.println(rsp2.getBody()); userId = rsp2.getUserid(); System.out.println("userId:" + userId); System.out.println("------------------------------------------------------"); } catch (ApiException e) { e.printStackTrace(); } // 釘釘 /user/get 獲取用戶詳情 try { DingTalkClient client3 = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get"); OapiUserGetRequest req3 = new OapiUserGetRequest(); req3.setUserid(userId);// req3.setHttpMethod("GET"); OapiUserGetResponse rsp3 = client3.execute(req3, accessToken);// System.out.println(rsp3.getBody()); } catch (ApiException e) { e.printStackTrace(); } // 釘釘 獲取所有部門列表 try { DingTalkClient client4 = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/list"); OapiDepartmentListRequest req4 = new OapiDepartmentListRequest(); req4.setHttpMethod("GET"); req4.setId("1"); OapiDepartmentListResponse rsp4 = client4.execute(req4, accessToken); System.out.println("-----------------獲取所有部門列表-----------------"); System.out.println(rsp4.getBody()); List<Department> departmentList = rsp4.getDepartment(); System.out.println("-----------------------------------------------------"); // [{id: xxx, parentid: xxx, ......},{id: xxx, parentid: xxx, ......},{id: xxx, parentid: xxx, ......},{id: xxx, parentid: xxx, ......}] System.out.println(departmentList.get(0).getId(); Long parentid = departmentList.get(0).getParentid(); } catch (ApiException e) { e.printStackTrace(); } }
到此這篇關(guān)于JAVA maven項(xiàng)目使用釘釘SDK獲取token、用戶的文章就介紹到這了,更多相關(guān)maven 釘釘SDK獲取token、用戶內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java高效提取PDF文件指定坐標(biāo)的文本內(nèi)容實(shí)戰(zhàn)代碼
在日常工作中,有時(shí)可能會(huì)需要從龐大的PDF文檔中提取其中所包含的文本內(nèi)容,下面這篇文章主要給大家介紹了關(guān)于如何利用Java高效提取PDF文件指定坐標(biāo)的文本內(nèi)容,需要的朋友可以參考下2024-01-01Java獲取漢字對(duì)應(yīng)的拼音(全拼或首字母)
這篇文章主要介紹了Java如何獲取漢字對(duì)應(yīng)的拼音(全拼或首字母),文中實(shí)現(xiàn)的方法是引用了pinyin4j-2.5.0.jar,然后給出了完整的示例代碼,有需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-01-01Java獲取Cookie里的指定值的實(shí)現(xiàn)方法
在Java中,我們經(jīng)常需要從HTTP請(qǐng)求中獲取Cookie,并從中提取特定的值,下面我們將介紹如何通過(guò)Java代碼獲取Cookie中的指定值,文章通過(guò)代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09java數(shù)據(jù)庫(kù)連接池新手入門一篇就夠了,太簡(jiǎn)單了!
數(shù)據(jù)庫(kù)連接池負(fù)責(zé)分配、管理和釋放數(shù)據(jù)庫(kù)連接,釋放空閑時(shí)間超過(guò)最大空閑時(shí)間的數(shù)據(jù)庫(kù)連接來(lái)避免因?yàn)闆](méi)有釋放數(shù)據(jù)庫(kù)連接而引起的數(shù)據(jù)庫(kù)連接遺漏,這項(xiàng)技術(shù)能明顯提高對(duì)數(shù)據(jù)庫(kù)操作的性能2021-06-06Spring MVC配置雙數(shù)據(jù)源實(shí)現(xiàn)一個(gè)java項(xiàng)目同時(shí)連接兩個(gè)數(shù)據(jù)庫(kù)的方法
這篇文章主要給大家介紹了關(guān)于Spring MVC如何配置雙數(shù)據(jù)源實(shí)現(xiàn)一個(gè)java項(xiàng)目同時(shí)連接兩個(gè)數(shù)據(jù)庫(kù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-05-05Spring Cloud Ubuntu環(huán)境部署的步驟與注意事項(xiàng)
這篇文章主要給大家介紹了關(guān)于Spring Cloud Ubuntu環(huán)境部署的步驟與注意事項(xiàng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Cloud具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12SpringBoot 如何優(yōu)雅的實(shí)現(xiàn)跨服務(wù)器上傳文件的示例
這篇文章主要介紹了SpringBoot 如何優(yōu)雅的實(shí)現(xiàn)跨服務(wù)器上傳文件的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2006-11-11