狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

[點晴永久免費OA]釘釘接口:獲取accessToken和打卡記錄

admin
2020年4月27日 18:7 本文熱度 3489
post和get方法工具類:HttpUtils

package weaver.dingtalk.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import weaver.interfaces.email.SSLClient;

import java.util.ArrayList;
import java.util.List;

/**
* http請求工具類
* @author lcs
*/
public class HttpUtils {


public static String doPost(String url, JSONObject jsonObject, String charset){
HttpClient httpClient = null;
HttpPost httpPost = null;
String result = null;
try{
httpClient = new SSLClient();
httpPost = new HttpPost(url);
//設置參數
List list = new ArrayList();
StringEntity entity = new StringEntity(jsonObject.toString(),charset);
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);


HttpResponse response = httpClient.execute(httpPost);
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity resEntity = response.getEntity();
if(resEntity != null){
result = EntityUtils.toString(resEntity,charset);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}

public static String doGet(String url){
String result = null;
HttpGet request = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = httpClient.execute(request);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result= EntityUtils.toString(response.getEntity(),"utf-8");
}
}catch (Exception e){
e.printStackTrace();
}
return result;
}
}

釘釘接口方法:DingTalkService
package weaver.dingtalk.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import weaver.dingtalk.utils.HttpUtils;

import java.util.HashMap;
import java.util.Map;

/**
* DingTalk相關方法
* @author 劉春生
*/
public class DingTalkService {

/**
* 獲取釘釘的accessToken
* @param url
* @param corpid
* @param secret
* @return
*/
public static String getAccessToken(String url,String corpid,String secret){
String requestUrl = url + "?corpid="+corpid+"&corpsecret="+secret;
String result = HttpUtils.doGet(requestUrl);
String accessToken = null;
JSONObject jsonObject = new JSONObject();
jsonObject = JSON.parseObject(result);
String msg = (String)jsonObject.get("errmsg");
if("ok".equals(msg)){
accessToken = (String)jsonObject.get("access_token");
}
return accessToken;
}

public static JSONArray getCardList(String accessToken, String workDateFrom, String workDateTo, String offset, String limit){
String recordUrl = "https://oapi.dingtalk.com/attendance/list?access_token="+accessToken;
JSONObject jsonObject = new JSONObject();
jsonObject.put("workDateFrom",workDateFrom);
jsonObject.put("workDateTo",workDateTo);
jsonObject.put("offset",offset);
jsonObject.put("limit",limit);
String result = HttpUtils.doPost(recordUrl,jsonObject,"utf-8");
JSONObject resutJSON = JSONObject.parseObject(result);
String msg = (String)resutJSON.get("errmsg");
JSONArray jsonArray = null;
if("ok".equals(msg)){
jsonArray = (JSONArray) resutJSON.get("recordresult");
}
return jsonArray;
}
}

測試方法:TestDingTalk
package weaver.dingtalk.service;

import com.alibaba.fastjson.JSONArray;

public class TestDingTalk {
public static void main(String[] args) {
String workDateFrom = "2017-11-03 08:00:00";
String workDateTo = "2017-11-03 18:00:00";
String offset = "0";//分頁獲取數據,0表示第一頁
String limit = "10";//每頁10條數據
String accessTokenUrl = "https://oapi.dingtalk.com/gettoken";
String corpid = "##############";//替換成自己的corpid
String secret = "##############";//替換成自己的corpsecret
String accessToken = DingTalkService.getAccessToken(accessTokenUrl,corpid,secret);
if(accessToken!=null){
JSONArray jsonArray = DingTalkService.getCardList(accessToken,workDateFrom,workDateTo,offset,limit);
System.out.println(jsonArray);
}
}
}

該文章在 2020/4/27 18:09:14 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved