|
|
@@ -94,6 +94,63 @@ public class Message2 {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 学生出入消息
|
|
|
+ * @param openid 公众号openId
|
|
|
+ * @param name 姓名
|
|
|
+ * @param dateTime 时间
|
|
|
+ * @param location 地点
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static String send2(String openid,String name,String dateTime,String location)
|
|
|
+ throws Exception {
|
|
|
+
|
|
|
+ String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret;
|
|
|
+
|
|
|
+ String s = HttpsClient.httpsRequestReturnString(url, "GET", "");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ String access_token = jsonObject.getString("access_token");
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject message = new JSONObject();
|
|
|
+ message.put("touser", openid);
|
|
|
+ message.put("template_id", "L624rcJY1EpFz5ikL-_2mBarfvsry1CH8C3FLOxwvl4");
|
|
|
+
|
|
|
+ JSONObject small = new JSONObject();
|
|
|
+ small.put("appid", "wx2fc3f45732fae5d3");
|
|
|
+ small.put("pagepath", "pages/msgWarn/msgWarn");
|
|
|
+ message.put("miniprogram", small);
|
|
|
+ // 名字
|
|
|
+ // 报警位置
|
|
|
+ JSONObject thing1 = new JSONObject();
|
|
|
+ thing1.put("value", name);
|
|
|
+ thing1.put("color", "#173177");
|
|
|
+
|
|
|
+ // 时间
|
|
|
+ JSONObject time2 = new JSONObject();
|
|
|
+ time2.put("value", dateTime);
|
|
|
+ time2.put("color", "#173177");
|
|
|
+
|
|
|
+ // 地点
|
|
|
+ JSONObject thing6 = new JSONObject();
|
|
|
+ thing6.put("value", location);
|
|
|
+ thing6.put("color", "#173177");
|
|
|
+
|
|
|
+ // 封装data
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("thing1",thing1);
|
|
|
+ data.put("time2",time2);
|
|
|
+ data.put("thing6",thing6);
|
|
|
+
|
|
|
+ message.put("data",data);
|
|
|
+
|
|
|
+ String s1 = HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, message);
|
|
|
+ logger.info("s1 = " + s1);
|
|
|
+ return s1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static String getToken() throws Exception {
|
|
|
String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret;
|
|
|
|
|
|
@@ -109,8 +166,6 @@ public class Message2 {
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
- String o9MsY67wqvQ__o_pOzF7oeN4MQPM = send("o9MsY67wqvQ__o_pOzF7oeN4MQPM","进入区域","IPCamera 01","2024-01-29 16:16:14");
|
|
|
-// String token = getToken();
|
|
|
-// logger.info("token = " + token);
|
|
|
+ String o9MsY67wqvQ__o_pOzF7oeN4MQPM = send2("o9MsY67wqvQ__o_pOzF7oeN4MQPM","张玉玲","2024-01-29 16:16:14","IPCamera 01");
|
|
|
}
|
|
|
}
|