Environment : java language, service number,
Function : There is a customer service number function, I need to get the current record all chat customer service.
Environment Introduction:
1. First you need to configure some parameters in the micro-channel public platform developer configuration
Which developers id and password used to get developers AccessToken, to configure the IP whitelist, or call the customer chats fail.
2. Log service number, find the customer service function. Currently this service I have both a customer service number, I now need to get maybe a chat customer service.
2. Locate the development documentation customer service functions.
Address: https://developers.weixin.qq.com/doc/offiaccount/Customer_Service/Obtain_chat_transcript.html
post request, parameter passing as follows, note: each query period can not exceed 24 hours.
3. Code combat:
@GetMapping(value = "/sendCondition")
public void sendCondition() throws ParseException {
//1.获取AccessToken
String accessToken = WeiXinParamesUtil.getAccessToken("customerService");
String url = "https://api.weixin.qq.com/customservice/msgrecord/getmsglist?access_token=ACCESS_TOKEN";
url = url.replace("ACCESS_TOKEN", accessToken);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse("2020-02-11 8:45:25");
long startTime = date.getTime()/1000;
Date date1 = simpleDateFormat.parse("2020-02-11 21:45:26");
long endTime = date1.getTime()/1000;
String jsonStr = " {\n" +
" \"starttime\" : "+String.valueOf(startTime)+",\n" +
" \"endtime\" : "+String.valueOf(endTime)+",\n" +
" \"msgid\" : 1,\n" +
" \"number\" : 10000 \n" +
"}";
JSONObject jsonObject = SendRequest.sendPost(url, jsonStr);
System.out.println("1111-----" + jsonObject);
}
public static String getWeiAccessToken ="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
/**
* 获取微信公众平台的access_token
* @param type
* @return
*/
public static String getAccessToken(String type) {
String url = "";
if ("users".equals(type)) {
url = getWeiAccessToken.replace("APPID", WeiXinParamesUtil.APPID).replace("APPSECRET", WeiXinParamesUtil.SECRET);
}else if("customerService".equals(type)){
url = getWeiAccessToken.replace("APPID", WeiXinParamesUtil.APPID).replace("APPSECRET", WeiXinParamesUtil.SECRET);
}
JSONObject departmentJson = SendRequest.sendGet2(url);
return departmentJson.getString("access_token");
}
4. Test results were as follows:
Displayed on the web page:
5. Return Parameters Results: