|
|
@@ -1,6 +1,7 @@
|
|
|
package com.template.component;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.template.common.exception.MyCustomException;
|
|
|
@@ -37,6 +38,7 @@ public class WeiXiaoComponent {
|
|
|
|
|
|
/**
|
|
|
* 获取token
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
public String getApplicationToken() {
|
|
|
@@ -44,21 +46,36 @@ public class WeiXiaoComponent {
|
|
|
// if (StringUtils.hasText(token)) {
|
|
|
// return token;
|
|
|
// } else {
|
|
|
- Map<String, Object> jsonMap = doGetApplicationToken();
|
|
|
- String accessToken = jsonMap.get("access_token").toString();
|
|
|
- String expiresIn = jsonMap.get("expires_in").toString();
|
|
|
+ Map<String, Object> jsonMap = doGetApplicationToken();
|
|
|
+ String accessToken = jsonMap.get("access_token").toString();
|
|
|
+ String expiresIn = jsonMap.get("expires_in").toString();
|
|
|
|
|
|
// stringRedisTemplate.opsForValue().set(RedisKey.WEI_XIAO_SERVICE_TOKEN, accessToken, Long.valueOf(expiresIn), TimeUnit.SECONDS);
|
|
|
|
|
|
- return accessToken;
|
|
|
+ return accessToken;
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
+// @Scheduled(cron = "0 0/1 * * * ? ")
|
|
|
+// public void test() {
|
|
|
+// ArrayList<String> strings = new ArrayList<>();
|
|
|
+// strings.add("362425200108210413");
|
|
|
+// String roomNumber="17-1-101";
|
|
|
+// String passWord="123456";
|
|
|
+// String reserveLeaveTime="2024-08-17 18:00:00";
|
|
|
+// String name="bug公寓";
|
|
|
+// String phoneNumber="123456";
|
|
|
+// sendNotice(strings, "公寓办理入住成功", "办理入住成功", "您的房间号为:" + roomNumber + ",密码是:" + passWord + "离店时间为:" + reserveLeaveTime + ",欢迎您入住" + name + ",我们全体员工很荣幸能为您服务,如有任何需要请致电:" + phoneNumber + ",期待为你服务。祝你生活愉快!", null);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 发送通知
|
|
|
- * @param cards 卡号集合
|
|
|
- * @param digest 摘要
|
|
|
- * @param title 通知标题
|
|
|
+ *
|
|
|
+ * @param cards 卡号集合
|
|
|
+ * @param digest 摘要
|
|
|
+ * @param title 通知标题
|
|
|
* @param content 通知内容
|
|
|
* @param customs 自定义参数,长度为2,分别为提示文案和通知跳转链接
|
|
|
*/
|
|
|
@@ -67,21 +84,32 @@ public class WeiXiaoComponent {
|
|
|
Map<String, String> params = new HashMap<>();
|
|
|
|
|
|
try {
|
|
|
+
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
- params.put("cards", mapper.writeValueAsString(cards));
|
|
|
+// params.put("cards", mapper.writeValueAsString(cards));
|
|
|
+ params.put("cards", JSON.toJSONString(cards));
|
|
|
params.put("title", title);
|
|
|
params.put("content", content);
|
|
|
params.put("sender", "智慧公寓");
|
|
|
params.put("digest", digest);
|
|
|
- if (customs != null && customs.size() == 2) {
|
|
|
- params.put("customs", mapper.writeValueAsString(customs));
|
|
|
-
|
|
|
- }
|
|
|
+// if (customs != null && customs.size() == 2) {
|
|
|
+// params.put("customs", mapper.writeValueAsString(customs));
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
RestTemplate client = new RestTemplate();
|
|
|
- ResponseEntity<String> tokenResponse = client.postForEntity(uri, params, String.class);
|
|
|
+ // wecode换取token
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ HttpEntity<Map<String, String>> request = new HttpEntity<>(params, headers);
|
|
|
+
|
|
|
+ ResponseEntity<String> tokenResponse = client.postForEntity(uri, request, String.class);
|
|
|
+// ResponseEntity<String> tokenResponse = client.postForEntity(uri, params, String.class);
|
|
|
String body = tokenResponse.getBody();
|
|
|
log.info("微校发送通知返回结果【{}】", body);
|
|
|
+ Map<String, Object> jsonMap = mapper.readValue(tokenResponse.getBody(), new TypeReference<Map<String, Object>>() {
|
|
|
+ });
|
|
|
+ System.out.println("jsonMap = " + jsonMap);
|
|
|
} catch (Exception e) {
|
|
|
log.error("微校发送通知错误【{}】", e.getMessage());
|
|
|
}
|
|
|
@@ -89,6 +117,7 @@ public class WeiXiaoComponent {
|
|
|
|
|
|
/**
|
|
|
* 获取token
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, Object> doGetApplicationToken() {
|
|
|
@@ -116,7 +145,8 @@ public class WeiXiaoComponent {
|
|
|
String body = tokenResponse.getBody();
|
|
|
log.info("微校请求token返回结果【{}】", body);
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
- Map<String, Object> jsonMap = mapper.readValue(body, new TypeReference<Map<String, Object>>() {});
|
|
|
+ Map<String, Object> jsonMap = mapper.readValue(body, new TypeReference<Map<String, Object>>() {
|
|
|
+ });
|
|
|
|
|
|
|
|
|
return jsonMap;
|