|
@@ -32,10 +32,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
@@ -451,7 +448,7 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
|
|
|
@Override
|
|
|
public String getArticleSummary(String accountId, String startDate, String endDate) {
|
|
|
- String requestUrl = "https://api.weixin.qq.com/datacube/getarticlesummary?access_token=ACCESS_TOKEN";
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/datacube/getarticlesummary?access_token=%s";
|
|
|
String accessToken = getAuthorizerAccessToken(accountId);
|
|
|
requestUrl = String.format(requestUrl,accessToken);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -467,4 +464,50 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
LocalDateTime.now().toString(),jsonStr);
|
|
|
return jsonStr;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateRemark(String accountId, String openId, String remark) {
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=%s";
|
|
|
+ String accessToken = getAuthorizerAccessToken(accountId);
|
|
|
+ requestUrl = String.format(requestUrl,accessToken);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ logger.info("微信设置备注,accountId:{}----start,时间:{}",accountId, LocalDateTime.now().toString());
|
|
|
+ MultiValueMap<String,String> params = new LinkedMultiValueMap<>(2);
|
|
|
+ params.add("openid",openId);
|
|
|
+ params.add("remark",remark);
|
|
|
+ HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<> (params,headers);
|
|
|
+ ResponseEntity<String> respStr = restTemplate.exchange(requestUrl,HttpMethod.POST,entity,String.class);
|
|
|
+ String jsonStr = respStr.getBody();
|
|
|
+ logger.info("微信设置备注,accountId:{}----end,时间:{},微信返回{}",accountId,LocalDateTime.now().toString(),jsonStr);
|
|
|
+ if (0 ==JSONObject.parseObject(jsonStr).getInteger("errcode")) {
|
|
|
+ return fansService.updateFansRemark(accountId,openId,remark);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean createTag(String accountId, String tagLabel) {
|
|
|
+
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=%s";
|
|
|
+ String accessToken = getAuthorizerAccessToken(accountId);
|
|
|
+ requestUrl = String.format(requestUrl,accessToken);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ MultiValueMap<String,Object> params = new LinkedMultiValueMap<>(2);
|
|
|
+ HashMap<String,String> map = new HashMap<>(2);
|
|
|
+ map.put("name",tagLabel);
|
|
|
+ params.add("tag",map);
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<> (params,headers);
|
|
|
+ logger.info("微信创建标签,accountId:{}----start,时间:{}",accountId, LocalDateTime.now().toString());
|
|
|
+ ResponseEntity<String> respStr = restTemplate.exchange(requestUrl,HttpMethod.POST,entity,String.class);
|
|
|
+ String jsonStr = respStr.getBody();
|
|
|
+ logger.info("微信创建标签,accountId:{}----end,时间:{},微信返回{}",accountId,LocalDateTime.now().toString(),jsonStr);
|
|
|
+ JSONObject temp = JSONObject.parseObject(jsonStr).getJSONObject("tag");
|
|
|
+ if (null != temp) {
|
|
|
+ Integer wxId = temp.getInteger("id");
|
|
|
+ return tagService.addTag(tagLabel,accountId,wxId);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|