|
@@ -1,19 +1,27 @@
|
|
|
package com.tzld.piaoquan.wecom.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
|
+import com.tzld.piaoquan.wecom.model.po.User;
|
|
|
+import com.tzld.piaoquan.wecom.model.po.UserExample;
|
|
|
import com.tzld.piaoquan.wecom.service.AccessTokenService;
|
|
|
import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
|
import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
|
+import com.tzld.piaoquan.wecom.utils.page.Page;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -25,6 +33,9 @@ public class TestController {
|
|
|
@Autowired
|
|
|
private AccessTokenService accessTokenService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
|
|
|
@GetMapping("/staff")
|
|
|
public void staff() throws IOException {
|
|
@@ -67,6 +78,42 @@ public class TestController {
|
|
|
jsonObject.put("limit", 10);
|
|
|
String post = httpPoolClientDefault.post(url, jsonObject.toJSONString());
|
|
|
log.info("userListDetail={}", post);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/userDetail")
|
|
|
+ public void userDetail(@RequestParam String userId) throws IOException {
|
|
|
+ String weComAccessToken = accessTokenService.getWeComAccessToken();
|
|
|
+ log.info("weComAccessToken={}", weComAccessToken);
|
|
|
+ if (weComAccessToken == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=%s&external_userid=%s", weComAccessToken, userId);
|
|
|
+ String get = httpPoolClientDefault.get(url);
|
|
|
+ log.info("userDetail={}", get);
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ @GetMapping("/getUserId")
|
|
|
+ public void getUserId() throws IOException {
|
|
|
+ UserExample example = new UserExample();
|
|
|
+ Page page = new Page<>(1, 10);
|
|
|
+ example.setPage(page);
|
|
|
+ List<User> userList = userMapper.selectByExample(example);
|
|
|
+ if(CollectionUtils.isEmpty(userList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<String> collect = userList.stream().map(User::getExternalUserId3rdParty).collect(Collectors.toList());
|
|
|
+ String weComAccessToken = accessTokenService.getWeComAccessToken();
|
|
|
+ log.info("weComAccessToken={}", weComAccessToken);
|
|
|
+ if (weComAccessToken == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/batch/openuserid_to_userid?access_token=%s", weComAccessToken);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(collect));
|
|
|
+ jsonObject.put("open_userid_list", jsonArray);
|
|
|
+ jsonObject.put("source_agentid", 1000009);
|
|
|
+ String post = httpPoolClientDefault.post(url, jsonObject.toJSONString());
|
|
|
+ log.info("getUserId={}", post);
|
|
|
}
|
|
|
}
|