|
@@ -2,419 +2,483 @@ package com.jpsoft.smart.modules.common.utils;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.jpsoft.smart.modules.wechat.entity.AccessToken;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
-
|
|
|
+@Slf4j
|
|
|
public class WechatMessageUtil {
|
|
|
+ public static final String send_template = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
|
|
|
|
|
|
+ private static final String TEMPLATE_REDIRECT_PRE_URL = "http://wuyeopenlocktest-wecat.sudaonline.net";
|
|
|
|
|
|
+ private static final String TEMPERATURE_ALARM_PRE_URL = "http://wisdomhousewechat.sudaonline.net/prevention/addetail_fll.html?id=";
|
|
|
|
|
|
- public static final String send_template = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
|
|
|
-
|
|
|
- private static final String TEMPLATE_REDIRECT_PRE_URL = "http://wuyeopenlocktest-wecat.sudaonline.net";
|
|
|
-
|
|
|
- private static final String TEMPERATURE_ALARM_PRE_URL = "http://wisdomhousewechat.sudaonline.net/prevention/addetail_fll.html?id=";
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ public static boolean sendBillInfo(String fullName, BigDecimal amount, String openId,
|
|
|
+ String detailAmount, String propertyName, String billRemark, String billDetailId, String billTemplateId, String appId, String appSecret) {
|
|
|
+ JSONObject sendData = new JSONObject();
|
|
|
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "您有一个新的账单,点击查看详情!");
|
|
|
+ first.put("color", "#FF0000");
|
|
|
|
|
|
- public static boolean sendBillInfo(String fullName, BigDecimal amount, String openId,
|
|
|
- String detailAmount, String propertyName, String billRemark, String billDetailId,String billTemplateId,String appId,String appSecret) {
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", fullName);
|
|
|
+ keyword1.put("color", "#173177");
|
|
|
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", "¥" + amount.setScale(2) + "元");
|
|
|
+ keyword2.put("color", "#173177");
|
|
|
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", detailAmount);
|
|
|
+ keyword3.put("color", "#173177");
|
|
|
|
|
|
- JSONObject first = new JSONObject();
|
|
|
- first.put("value", "您有一个新的账单,点击查看详情!");
|
|
|
- first.put("color", "#FF0000");
|
|
|
|
|
|
- JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", fullName);
|
|
|
- keyword1.put("color", "#173177");
|
|
|
+ String remarkStr = "账单来源:" + propertyName;
|
|
|
|
|
|
- JSONObject keyword2 = new JSONObject();
|
|
|
- keyword2.put("value", "¥" + amount.setScale(2) + "元");
|
|
|
- keyword2.put("color", "#173177");
|
|
|
+ if (StringUtils.isNotBlank(billRemark)) {
|
|
|
+ remarkStr = remarkStr + "\n备注:" + billRemark + "";
|
|
|
+ }
|
|
|
|
|
|
- JSONObject keyword3 = new JSONObject();
|
|
|
- keyword3.put("value", detailAmount);
|
|
|
- keyword3.put("color", "#173177");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkStr);
|
|
|
+ remark.put("color", "#173177");
|
|
|
|
|
|
+ sendData.put("first", first);
|
|
|
+ sendData.put("keyword1", keyword1);
|
|
|
+ sendData.put("keyword2", keyword2);
|
|
|
+ sendData.put("keyword3", keyword3);
|
|
|
+ sendData.put("remark", remark);
|
|
|
|
|
|
+ //w8Zk_VQMFIEVSIBPZid7zSrvHmBdrgnqF76u8PLCZEs cs
|
|
|
+ boolean ret = sendTemplate(sendData, appId, appSecret, billTemplateId, openId, TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + billDetailId + "payTime=0&payType=bill");
|
|
|
|
|
|
- String remarkStr = "账单来源:" + propertyName;
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
- if(StringUtils.isNotBlank(billRemark)){
|
|
|
- remarkStr = remarkStr + "\n备注:"+ billRemark +"";
|
|
|
- }
|
|
|
+ //
|
|
|
+ public static boolean sendBillPayedMessage(String fullName, String feeName, Date createTime, BigDecimal amount, String openId, String billDetailId, String payedTemplateId, String appId, String appSecret) {
|
|
|
|
|
|
- JSONObject remark = new JSONObject();
|
|
|
- remark.put("value", remarkStr);
|
|
|
- remark.put("color", "#173177");
|
|
|
+ JSONObject sendData = new JSONObject();
|
|
|
|
|
|
- sendData.put("first", first);
|
|
|
- sendData.put("keyword1", keyword1);
|
|
|
- sendData.put("keyword2", keyword2);
|
|
|
- sendData.put("keyword3", keyword3);
|
|
|
- sendData.put("remark", remark);
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "账单支付成功!");
|
|
|
+ first.put("color", "#FF0000");
|
|
|
|
|
|
- //w8Zk_VQMFIEVSIBPZid7zSrvHmBdrgnqF76u8PLCZEs cs
|
|
|
- boolean ret = sendTemplate(sendData, appId,appSecret,billTemplateId,openId, TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + billDetailId +"payTime=0&payType=bill");
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", fullName);
|
|
|
+ keyword1.put("color", "#173177");
|
|
|
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", feeName);
|
|
|
+ keyword2.put("color", "#173177");
|
|
|
|
|
|
- //
|
|
|
- public static boolean sendBillPayedMessage(String fullName,String feeName,Date createTime,BigDecimal amount,String openId,String billDetailId,String payedTemplateId,String appId,String appSecret) {
|
|
|
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
- JSONObject first = new JSONObject();
|
|
|
- first.put("value", "账单支付成功!");
|
|
|
- first.put("color", "#FF0000");
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", sdf.format(createTime));
|
|
|
+ keyword3.put("color", "#173177");
|
|
|
|
|
|
- JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", fullName);
|
|
|
- keyword1.put("color", "#173177");
|
|
|
+ JSONObject keyword4 = new JSONObject();
|
|
|
|
|
|
- JSONObject keyword2 = new JSONObject();
|
|
|
- keyword2.put("value", feeName);
|
|
|
- keyword2.put("color", "#173177");
|
|
|
+ keyword4.put("value", "¥" + amount.setScale(2) + "元");
|
|
|
+ keyword4.put("color", "#173177");
|
|
|
|
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String remarkStr = "感谢您的支持,点击查看缴费详情";
|
|
|
|
|
|
- JSONObject keyword3 = new JSONObject();
|
|
|
- keyword3.put("value", sdf.format(createTime));
|
|
|
- keyword3.put("color", "#173177");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkStr);
|
|
|
+ remark.put("color", "#173177");
|
|
|
|
|
|
- JSONObject keyword4 = new JSONObject();
|
|
|
+ sendData.put("first", first);
|
|
|
+ sendData.put("keyword1", keyword1);
|
|
|
+ sendData.put("keyword2", keyword2);
|
|
|
+ sendData.put("keyword3", keyword3);
|
|
|
+ sendData.put("keyword4", keyword4);
|
|
|
+ sendData.put("remark", remark);
|
|
|
|
|
|
- keyword4.put("value", "¥" + amount.setScale(2) + "元");
|
|
|
- keyword4.put("color", "#173177");
|
|
|
+ //w8Zk_VQMFIEVSIBPZid7zSrvHmBdrgnqF76u8PLCZEs cs
|
|
|
+ boolean ret = sendTemplate(sendData, appId, appSecret, payedTemplateId, openId, TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + billDetailId + "payTime=1&payType=bill");
|
|
|
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
+ //
|
|
|
+ public static boolean sendScanPayedMessage(String fullName, String feeName, Date createTime, BigDecimal amount, String openId, String independentPayId, String payedTemplateId, String appId, String appSecret) {
|
|
|
|
|
|
+ JSONObject sendData = new JSONObject();
|
|
|
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "账单支付成功!");
|
|
|
+ first.put("color", "#FF0000");
|
|
|
|
|
|
- String remarkStr = "感谢您的支持,点击查看缴费详情";
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", fullName);
|
|
|
+ keyword1.put("color", "#173177");
|
|
|
|
|
|
- JSONObject remark = new JSONObject();
|
|
|
- remark.put("value", remarkStr);
|
|
|
- remark.put("color", "#173177");
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", feeName);
|
|
|
+ keyword2.put("color", "#173177");
|
|
|
|
|
|
- sendData.put("first", first);
|
|
|
- sendData.put("keyword1", keyword1);
|
|
|
- sendData.put("keyword2", keyword2);
|
|
|
- sendData.put("keyword3", keyword3);
|
|
|
- sendData.put("keyword4", keyword4);
|
|
|
- sendData.put("remark", remark);
|
|
|
|
|
|
- //w8Zk_VQMFIEVSIBPZid7zSrvHmBdrgnqF76u8PLCZEs cs
|
|
|
- boolean ret = sendTemplate(sendData,appId,appSecret,payedTemplateId ,openId,TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + billDetailId +"payTime=1&payType=bill");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", sdf.format(createTime));
|
|
|
+ keyword3.put("color", "#173177");
|
|
|
|
|
|
- //
|
|
|
- public static boolean sendScanPayedMessage(String fullName,String feeName,Date createTime,BigDecimal amount,String openId,String independentPayId,String payedTemplateId,String appId,String appSecret) {
|
|
|
+ JSONObject keyword4 = new JSONObject();
|
|
|
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
+ keyword4.put("value", "¥" + amount.setScale(2) + "元");
|
|
|
+ keyword4.put("color", "#173177");
|
|
|
|
|
|
- JSONObject first = new JSONObject();
|
|
|
- first.put("value", "账单支付成功!");
|
|
|
- first.put("color", "#FF0000");
|
|
|
|
|
|
- JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", fullName);
|
|
|
- keyword1.put("color", "#173177");
|
|
|
+ String remarkStr = "感谢您的支持,点击查看缴费详情";
|
|
|
|
|
|
- JSONObject keyword2 = new JSONObject();
|
|
|
- keyword2.put("value", feeName);
|
|
|
- keyword2.put("color", "#173177");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkStr);
|
|
|
+ remark.put("color", "#173177");
|
|
|
|
|
|
+ sendData.put("first", first);
|
|
|
+ sendData.put("keyword1", keyword1);
|
|
|
+ sendData.put("keyword2", keyword2);
|
|
|
+ sendData.put("keyword3", keyword3);
|
|
|
+ sendData.put("keyword4", keyword4);
|
|
|
+ sendData.put("remark", remark);
|
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ boolean ret = sendTemplate(sendData, appId, appSecret, payedTemplateId, openId, TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + independentPayId + "payTime=1&payType=wechat");
|
|
|
|
|
|
- JSONObject keyword3 = new JSONObject();
|
|
|
- keyword3.put("value", sdf.format(createTime));
|
|
|
- keyword3.put("color", "#173177");
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
- JSONObject keyword4 = new JSONObject();
|
|
|
+ /**
|
|
|
+ * 发送通知信息
|
|
|
+ *
|
|
|
+ * @param noticeName 通知名称名称
|
|
|
+ * @param noticeDetailId 通知详情ID
|
|
|
+ * @param openId 发送人
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean sendNoticeMessage(String noticeName, String content, String openId, String noticeDetailId, String noticeTemplateId, String appId, String appSecret) {
|
|
|
|
|
|
- keyword4.put("value", "¥" + amount.setScale(2) + "元");
|
|
|
- keyword4.put("color", "#173177");
|
|
|
|
|
|
+ JSONObject sendData = new JSONObject();
|
|
|
+ String finallyContent = getContent(content);
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "您好,园区通知如下:");
|
|
|
+ first.put("color", "#173177");
|
|
|
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", noticeName);
|
|
|
+ keyword1.put("color", "#173177");
|
|
|
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
- String remarkStr = "感谢您的支持,点击查看缴费详情";
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", sdf.format(new Date()));
|
|
|
+ keyword2.put("color", "#173177");
|
|
|
|
|
|
- JSONObject remark = new JSONObject();
|
|
|
- remark.put("value", remarkStr);
|
|
|
- remark.put("color", "#173177");
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", finallyContent);
|
|
|
+ keyword3.put("color", "#173177");
|
|
|
|
|
|
- sendData.put("first", first);
|
|
|
- sendData.put("keyword1", keyword1);
|
|
|
- sendData.put("keyword2", keyword2);
|
|
|
- sendData.put("keyword3", keyword3);
|
|
|
- sendData.put("keyword4", keyword4);
|
|
|
- sendData.put("remark", remark);
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", "点击查看详情");
|
|
|
+ remark.put("color", "#173177");
|
|
|
|
|
|
- boolean ret = sendTemplate(sendData,appId,appSecret,payedTemplateId ,openId,TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + independentPayId +"payTime=1&payType=wechat");
|
|
|
+ sendData.put("first", first);
|
|
|
+ sendData.put("keyword1", keyword1);
|
|
|
+ sendData.put("keyword2", keyword2);
|
|
|
+ sendData.put("keyword3", keyword3);
|
|
|
+ sendData.put("remark", remark);
|
|
|
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ //noticeDetailId
|
|
|
+ boolean ret = sendTemplate(sendData, appId, appSecret, noticeTemplateId, openId, TEMPLATE_REDIRECT_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
|
|
|
|
|
|
- /**
|
|
|
- * 发送通知信息
|
|
|
- * @param noticeName 通知名称名称
|
|
|
- * @param noticeDetailId 通知详情ID
|
|
|
- * @param openId 发送人
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static boolean sendNoticeMessage(String noticeName,String content,String openId,String noticeDetailId,String noticeTemplateId,String appId,String appSecret) {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送物业管理通知信息
|
|
|
+ *
|
|
|
+ * @param noticeName 通知名称
|
|
|
+ * @param noticeDetailId 通知详情ID
|
|
|
+ * @param openId 发送人
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean sendPropertyNoticeMessage(String noticeName, String content, String openId, String noticeDetailId, String noticeTemplateId, String appId, String appSecret) {
|
|
|
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
- String finallyContent = getContent(content);
|
|
|
- JSONObject first = new JSONObject();
|
|
|
- first.put("value", "您好,园区通知如下:");
|
|
|
- first.put("color", "#173177");
|
|
|
|
|
|
- JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", noticeName);
|
|
|
- keyword1.put("color", "#173177");
|
|
|
+ JSONObject sendData = new JSONObject();
|
|
|
+ String finallyContent = getContent(content);
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "您好,物业管理通知如下:");
|
|
|
+ first.put("color", "#173177");
|
|
|
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", noticeName);
|
|
|
+ keyword1.put("color", "#173177");
|
|
|
|
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
- JSONObject keyword2 = new JSONObject();
|
|
|
- keyword2.put("value", sdf.format(new Date()));
|
|
|
- keyword2.put("color", "#173177");
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", sdf.format(new Date()));
|
|
|
+ keyword2.put("color", "#173177");
|
|
|
|
|
|
- JSONObject keyword3 = new JSONObject();
|
|
|
- keyword3.put("value", finallyContent);
|
|
|
- keyword3.put("color", "#173177");
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", finallyContent);
|
|
|
+ keyword3.put("color", "#173177");
|
|
|
|
|
|
- JSONObject remark = new JSONObject();
|
|
|
- remark.put("value", "点击查看详情");
|
|
|
- remark.put("color", "#173177");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", "点击查看详情");
|
|
|
+ remark.put("color", "#173177");
|
|
|
|
|
|
- sendData.put("first", first);
|
|
|
- sendData.put("keyword1", keyword1);
|
|
|
- sendData.put("keyword2", keyword2);
|
|
|
- sendData.put("keyword3", keyword3);
|
|
|
- sendData.put("remark", remark);
|
|
|
+ sendData.put("first", first);
|
|
|
+ sendData.put("keyword1", keyword1);
|
|
|
+ sendData.put("keyword2", keyword2);
|
|
|
+ sendData.put("keyword3", keyword3);
|
|
|
+ sendData.put("remark", remark);
|
|
|
|
|
|
- //noticeDetailId
|
|
|
- boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, TEMPLATE_REDIRECT_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
|
|
|
+ //noticeDetailId
|
|
|
+ boolean ret = sendTemplate(sendData, appId, appSecret, noticeTemplateId, openId, TEMPERATURE_ALARM_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
|
|
|
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 发送物业管理通知信息
|
|
|
- * @param noticeName 通知名称
|
|
|
- * @param noticeDetailId 通知详情ID
|
|
|
- * @param openId 发送人
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static boolean sendPropertyNoticeMessage(String noticeName,String content,String openId,String noticeDetailId,String noticeTemplateId,String appId,String appSecret) {
|
|
|
+ /**
|
|
|
+ * 发送警告通知信息
|
|
|
+ *
|
|
|
+ * @param noticeName 通知名称
|
|
|
+ * @param noticeDetailId 通知详情ID
|
|
|
+ * @param openId 发送人
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean sendAlarmNoticeMessage(String noticeName, String content, Date createTime, String openId, String noticeDetailId, String noticeTemplateId, String appId, String appSecret) {
|
|
|
|
|
|
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
- String finallyContent = getContent(content);
|
|
|
- JSONObject first = new JSONObject();
|
|
|
- first.put("value", "您好,物业管理通知如下:");
|
|
|
- first.put("color", "#173177");
|
|
|
+ JSONObject sendData = new JSONObject();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String finallyContent = getContent(content);
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "您好,入侵警告通知如下:");
|
|
|
+ first.put("color", "#173177");
|
|
|
|
|
|
- JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", noticeName);
|
|
|
- keyword1.put("color", "#173177");
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", sdf.format(createTime));
|
|
|
+ keyword1.put("color", "#173177");
|
|
|
|
|
|
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", finallyContent);
|
|
|
+ keyword2.put("color", "#173177");
|
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", "请尽快查看");
|
|
|
+ remark.put("color", "#173177");
|
|
|
|
|
|
- JSONObject keyword2 = new JSONObject();
|
|
|
- keyword2.put("value", sdf.format(new Date()));
|
|
|
- keyword2.put("color", "#173177");
|
|
|
+ sendData.put("first", first);
|
|
|
+ sendData.put("keyword1", keyword1);
|
|
|
+ sendData.put("keyword2", keyword2);
|
|
|
+ //sendData.put("remark", remark);
|
|
|
+
|
|
|
+ //noticeDetailId
|
|
|
+ boolean ret = sendTemplate(sendData, appId, appSecret, noticeTemplateId, openId, "");
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 微信发送模版
|
|
|
+ *
|
|
|
+ * @param sendData 发送数据
|
|
|
+ * @param templateId 模版Id
|
|
|
+ * @param openId 发送人
|
|
|
+ * @param url 详情跳转地址
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean sendTemplate(JSONObject sendData, String appId, String appSecret, String templateId, String openId, String url) {
|
|
|
+ boolean result = false;
|
|
|
|
|
|
- JSONObject keyword3 = new JSONObject();
|
|
|
- keyword3.put("value", finallyContent);
|
|
|
- keyword3.put("color", "#173177");
|
|
|
+ AccessToken accessToken = WeixinUtil.getAccessToken(appId, appSecret);
|
|
|
|
|
|
- JSONObject remark = new JSONObject();
|
|
|
- remark.put("value", "点击查看详情");
|
|
|
- remark.put("color", "#173177");
|
|
|
+ if (accessToken != null) {
|
|
|
+ //发送模版内容
|
|
|
+ String sendTemplateUrl = send_template.replace("ACCESS_TOKEN", accessToken.getToken());
|
|
|
|
|
|
- sendData.put("first", first);
|
|
|
- sendData.put("keyword1", keyword1);
|
|
|
- sendData.put("keyword2", keyword2);
|
|
|
- sendData.put("keyword3", keyword3);
|
|
|
- sendData.put("remark", remark);
|
|
|
+ JSONObject sendTemplateData = new JSONObject();
|
|
|
|
|
|
- //noticeDetailId
|
|
|
- boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, TEMPERATURE_ALARM_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
|
|
|
+ sendTemplateData.put("touser", openId);
|
|
|
+ sendTemplateData.put("template_id", templateId);
|
|
|
+ sendTemplateData.put("url", url);
|
|
|
+ sendTemplateData.put("data", sendData);
|
|
|
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ log.warn("模版发送Id>>>>" + templateId + ">>>模版发送数据>>>>>" + sendTemplateData.toString());
|
|
|
|
|
|
- /**
|
|
|
- * 发送警告通知信息
|
|
|
- * @param noticeName 通知名称
|
|
|
- * @param noticeDetailId 通知详情ID
|
|
|
- * @param openId 发送人
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static boolean sendAlarmNoticeMessage(String noticeName,String content,Date createTime,String openId,String noticeDetailId,String noticeTemplateId,String appId,String appSecret) {
|
|
|
+ String sendTemplateRet = HttpConnectionUtil.requestByPost(sendTemplateUrl, sendTemplateData.toString());
|
|
|
|
|
|
+ log.warn("模版发送返回数据>>>>>" + sendTemplateRet);
|
|
|
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String finallyContent = getContent(content);
|
|
|
- JSONObject first = new JSONObject();
|
|
|
- first.put("value", "您好,入侵警告通知如下:");
|
|
|
- first.put("color", "#173177");
|
|
|
+ if (StringUtils.isNotBlank(sendTemplateRet)) {
|
|
|
+ JSONObject sendTemplateJson = JSONObject.fromObject(sendTemplateRet);
|
|
|
|
|
|
- JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", sdf.format(createTime));
|
|
|
- keyword1.put("color", "#173177");
|
|
|
+ if ("0".equals(sendTemplateJson.getString("errcode"))) {
|
|
|
+ //发送成功
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String sendNativeTemplate(String appId,String appSecret,String templateId, String openId,JSONObject sendData,String urlPath) {
|
|
|
+ String result = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ AccessToken accessToken = WeixinUtil.getAccessToken(appId, appSecret);
|
|
|
|
|
|
+ if (accessToken == null) {
|
|
|
+ throw new Exception("token无法获取");
|
|
|
+ }
|
|
|
|
|
|
- JSONObject keyword2 = new JSONObject();
|
|
|
- keyword2.put("value", finallyContent);
|
|
|
- keyword2.put("color", "#173177");
|
|
|
+ //发送模版内容
|
|
|
+ String sendTemplateUrl = send_template.replace("ACCESS_TOKEN", accessToken.getToken());
|
|
|
|
|
|
- JSONObject remark = new JSONObject();
|
|
|
- remark.put("value", "请尽快查看");
|
|
|
- remark.put("color", "#173177");
|
|
|
+ JSONObject sendTemplateData = new JSONObject();
|
|
|
+
|
|
|
+ sendTemplateData.put("touser", openId);
|
|
|
+ sendTemplateData.put("template_id", templateId);
|
|
|
+ sendTemplateData.put("url", urlPath);
|
|
|
+ sendTemplateData.put("data", sendData);
|
|
|
|
|
|
- sendData.put("first", first);
|
|
|
- sendData.put("keyword1", keyword1);
|
|
|
- sendData.put("keyword2", keyword2);
|
|
|
- //sendData.put("remark", remark);
|
|
|
+ URL url = new URL(sendTemplateUrl);
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
+ conn.setRequestMethod("POST");
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ conn.setUseCaches(false);
|
|
|
+ conn.setRequestProperty("Connection", "Keep-Alive");
|
|
|
+ conn.setRequestProperty("Charset", "UTF-8");
|
|
|
|
|
|
- //noticeDetailId
|
|
|
- boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, "");
|
|
|
+ // 设置文件类型:
|
|
|
+ conn.setRequestProperty("Content-Type","application/json; charset=UTF-8");
|
|
|
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ // 设置接收类型否则返回415错误
|
|
|
+ //conn.setRequestProperty("accept","*/*")此处为暴力方法设置接受所有类型,以此来防范返回415;
|
|
|
+ conn.setRequestProperty("accept","application/json");
|
|
|
+ conn.setConnectTimeout(5000);
|
|
|
+ conn.setReadTimeout(5000);
|
|
|
|
|
|
- /**
|
|
|
- * 微信发送模版
|
|
|
- * @param sendData 发送数据
|
|
|
- * @param templateId 模版Id
|
|
|
- * @param openId 发送人
|
|
|
- * @param url 详情跳转地址
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static boolean sendTemplate(JSONObject sendData,String appId,String appSecret,String templateId,String openId,String url){
|
|
|
+ String dataStr = sendTemplateData.toString();
|
|
|
|
|
|
- boolean result = false;
|
|
|
+ log.warn("发送数据:" + dataStr);
|
|
|
+ // 往服务器里面发送数据
|
|
|
+ byte[] buffer = dataStr.getBytes("UTF-8");
|
|
|
|
|
|
+ // 设置文件长度
|
|
|
+ conn.setRequestProperty("Content-Length", String.valueOf(buffer.length));
|
|
|
+ OutputStream output = conn.getOutputStream();
|
|
|
+ output.write(buffer);
|
|
|
+ output.flush();
|
|
|
+ output.close();
|
|
|
|
|
|
- AccessToken accessToken = WeixinUtil.getAccessToken(appId, appSecret);
|
|
|
+ if (conn.getResponseCode() == 200) {
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
|
|
|
|
|
|
- if(accessToken != null){
|
|
|
- //发送模版内容
|
|
|
- String sendTemplateUrl = send_template.replace("ACCESS_TOKEN", accessToken.getToken());
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ String line = "";
|
|
|
|
|
|
- JSONObject sendTemplateData = new JSONObject();
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ sb.append(line);
|
|
|
+ }
|
|
|
|
|
|
- sendTemplateData.put("touser", openId);
|
|
|
- sendTemplateData.put("template_id", templateId);
|
|
|
- sendTemplateData.put("url", url);
|
|
|
- sendTemplateData.put("data", sendData);
|
|
|
+ result = sb.toString();
|
|
|
|
|
|
- System.out.println("模版发送Id>>>>" + templateId + ">>>模版发送数据>>>>>" + sendTemplateData.toString());
|
|
|
+ log.warn("接收数据:" + result);
|
|
|
|
|
|
- String sendTemplateRet = HttpConnectionUtil.requestByPost(sendTemplateUrl, sendTemplateData.toString());
|
|
|
+ reader.close();
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+ }
|
|
|
|
|
|
- System.out.println("模版发送返回数据>>>>>" + sendTemplateRet);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- if(StringUtils.isNotBlank(sendTemplateRet)){
|
|
|
- JSONObject sendTemplateJson = JSONObject.fromObject(sendTemplateRet);
|
|
|
+ public static String getContent(String content) {
|
|
|
+ String finallyContent = content;
|
|
|
+ String regex = "<p.*?>(.*?)</p>";
|
|
|
+ Pattern p = Pattern.compile(regex);
|
|
|
+ Matcher m = p.matcher(content);
|
|
|
+ while (m.find()) {
|
|
|
+ finallyContent = m.group(1);
|
|
|
+ }
|
|
|
|
|
|
- if("0".equals(sendTemplateJson.getString("errcode"))){
|
|
|
- //发送成功
|
|
|
- result = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- return result;
|
|
|
- }
|
|
|
+ return finallyContent;
|
|
|
+ }
|
|
|
|
|
|
- public static String getContent(String content){
|
|
|
- String finallyContent = content;
|
|
|
- String regex="<p.*?>(.*?)</p>";
|
|
|
- Pattern p =Pattern.compile(regex);
|
|
|
- Matcher m=p.matcher(content);
|
|
|
- while(m.find()){
|
|
|
- finallyContent = m.group(1);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return finallyContent;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送温度报警模板
|
|
|
- * @param openId
|
|
|
- * @param place
|
|
|
- * @param appId
|
|
|
- * @param appSecret
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static boolean sendTemperatureAlarmInfo( String openId,String place,String appId,String appSecret,String personDeviceLogId) {
|
|
|
+ /**
|
|
|
+ * 发送温度报警模板
|
|
|
+ *
|
|
|
+ * @param openId
|
|
|
+ * @param place
|
|
|
+ * @param appId
|
|
|
+ * @param appSecret
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean sendTemperatureAlarmInfo(String openId, String place, String appId, String appSecret, String personDeviceLogId) {
|
|
|
|
|
|
|
|
|
String templateId = "Mg9Ldk_kaoHAUwXFHEatrGugTlOz3yrMmMk7VoBca4M";
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
+ JSONObject sendData = new JSONObject();
|
|
|
|
|
|
- JSONObject first = new JSONObject();
|
|
|
- first.put("value", "疑似疫情报警!");
|
|
|
- first.put("color", "#FF0000");
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "疑似疫情报警!");
|
|
|
+ first.put("color", "#FF0000");
|
|
|
|
|
|
- JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
|
|
|
- keyword1.put("color", "#173177");
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
|
|
|
+ keyword1.put("color", "#173177");
|
|
|
|
|
|
- JSONObject keyword2 = new JSONObject();
|
|
|
- keyword2.put("value", place);
|
|
|
- keyword2.put("color", "#173177");
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", place);
|
|
|
+ keyword2.put("color", "#173177");
|
|
|
|
|
|
- String remarkStr = "发现有一例体温异常情况,点击查看详情";
|
|
|
+ String remarkStr = "发现有一例体温异常情况,点击查看详情";
|
|
|
|
|
|
- JSONObject remark = new JSONObject();
|
|
|
- remark.put("value", remarkStr);
|
|
|
- remark.put("color", "#173177");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkStr);
|
|
|
+ remark.put("color", "#173177");
|
|
|
|
|
|
- sendData.put("first", first);
|
|
|
- sendData.put("keyword1", keyword1);
|
|
|
- sendData.put("keyword2", keyword2);
|
|
|
- sendData.put("remark", remark);
|
|
|
+ sendData.put("first", first);
|
|
|
+ sendData.put("keyword1", keyword1);
|
|
|
+ sendData.put("keyword2", keyword2);
|
|
|
+ sendData.put("remark", remark);
|
|
|
|
|
|
|
|
|
- boolean ret = sendTemplate(sendData, appId,appSecret,templateId,openId, TEMPERATURE_ALARM_PRE_URL+personDeviceLogId);
|
|
|
+ boolean ret = sendTemplate(sendData, appId, appSecret, templateId, openId, TEMPERATURE_ALARM_PRE_URL + personDeviceLogId);
|
|
|
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) {
|
|
|
/*AccessToken at = WeixinUtil.getAccessToken(APP_ID, APP_SECRET,"061iw9gy1sZ1dg09dqhy1ae3gy1iw9gq");
|
|
|
|
|
|
System.out.println(at.getOpenid());*/
|
|
@@ -423,25 +487,23 @@ public class WechatMessageUtil {
|
|
|
doorMessage("1111", 2,"2018-09-22 09:00-12:00", 1, "2222222", "3333333", "oiFbN0p9jKphExeGIa3HtyL9HjqM");
|
|
|
}*/
|
|
|
|
|
|
- //orderConfirmMessage("12312321312", 1111, DEFAULT_OPEN_ID);
|
|
|
- //sendBillInfo("测试", "测sendNoticeMessage试", "荆鹏创业", "张三", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "1111", new Date());
|
|
|
- //sendBillPayedMessage("测试", "荆鹏创业", "张三", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "11111", new Date());
|
|
|
- //sendScanPayedMessage("测试", "荆鹏创业", "张三11111", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "11111", new Date());
|
|
|
+ //orderConfirmMessage("12312321312", 1111, DEFAULT_OPEN_ID);
|
|
|
+ //sendBillInfo("测试", "测sendNoticeMessage试", "荆鹏创业", "张三", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "1111", new Date());
|
|
|
+ //sendBillPayedMessage("测试", "荆鹏创业", "张三", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "11111", new Date());
|
|
|
+ //sendScanPayedMessage("测试", "荆鹏创业", "张三11111", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "11111", new Date());
|
|
|
//sendNoticeMessage("测试", "sdfsdfasfasdfafasdfasdf", "oHjCawgwCGen5k1-hAsimdEX5lZo", "2222","9JKu9t9uTPHL1siIm7WatOJ1KXGolzEPlnmqIbckTUM","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");
|
|
|
|
|
|
/* sendBillInfo("1栋-1单元-101",new BigDecimal("0.01"),"oOlFd1BUR6Fi2ayBWUeou81G8ZD4",
|
|
|
"物业费","小鹏物业","测试","9e52c923-2179-4526-a108-32becc9aa1d0","vVraOPl4OyNVWDGz6XYlJqRb7qGjjcyJdnVi5HWmFRI","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");*/
|
|
|
|
|
|
- /*sendBillPayedMessage("1栋-1单元-101","物业费",new Date(),new BigDecimal("0.01"),"oOlFd1BUR6Fi2ayBWUeou81G8ZD4","33e7e5e6-5b38-45f5-9ccf-c7ef21978a5b","kbx5u70nzo7PklTVl4B1xvRffksrUtXxnDll8ggEKlo","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");*/
|
|
|
-
|
|
|
- //sendAlarmNoticeMessage("周界入侵警报", "周界入侵,目标ID:1419,区域范围:(0.327,0.698)(0.674,0.936)(0.67,0.985)(0.352,0.973)", "oHjCawgwCGen5k1-hAsimdEX5lZo", "","8dpP8XM1XaiiIByXiuAeFIZeNjEow1AleG_h8O2xyVA","wx7e70eb62a8459869","909d17e353268da57c4f18cc09798049");
|
|
|
- //sendNoticeMessage("测试", "sdfsdfasfasdfafasdfasdf", "oHjCawgwCGen5k1-hAsimdEX5lZo", "2222","vsw6sb9lMA3bcsE8MdeaGENvI1HSUy2ht9B8hS3jEzA","wx7e70eb62a8459869","909d17e353268da57c4f18cc09798049");
|
|
|
- sendTemperatureAlarmInfo("oLowyuOQ9ULF3LUGt6h3fTrsnbVE","荆鹏软件_门房考勤机","wx0b3c41a903053808","43557bd62f77b0c3d6670e991872f0e7","Mg9Ldk_kaoHAUwXFHEatrGugTlOz3yrMmMk7VoBca4M");
|
|
|
- getContent("<p>内容</p>");
|
|
|
-
|
|
|
- }
|
|
|
+ /*sendBillPayedMessage("1栋-1单元-101","物业费",new Date(),new BigDecimal("0.01"),"oOlFd1BUR6Fi2ayBWUeou81G8ZD4","33e7e5e6-5b38-45f5-9ccf-c7ef21978a5b","kbx5u70nzo7PklTVl4B1xvRffksrUtXxnDll8ggEKlo","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");*/
|
|
|
|
|
|
+ //sendAlarmNoticeMessage("周界入侵警报", "周界入侵,目标ID:1419,区域范围:(0.327,0.698)(0.674,0.936)(0.67,0.985)(0.352,0.973)", "oHjCawgwCGen5k1-hAsimdEX5lZo", "","8dpP8XM1XaiiIByXiuAeFIZeNjEow1AleG_h8O2xyVA","wx7e70eb62a8459869","909d17e353268da57c4f18cc09798049");
|
|
|
+ //sendNoticeMessage("测试", "sdfsdfasfasdfafasdfasdf", "oHjCawgwCGen5k1-hAsimdEX5lZo", "2222","vsw6sb9lMA3bcsE8MdeaGENvI1HSUy2ht9B8hS3jEzA","wx7e70eb62a8459869","909d17e353268da57c4f18cc09798049");
|
|
|
+ sendTemperatureAlarmInfo("oLowyuOQ9ULF3LUGt6h3fTrsnbVE", "荆鹏软件_门房考勤机", "wx0b3c41a903053808", "43557bd62f77b0c3d6670e991872f0e7", "Mg9Ldk_kaoHAUwXFHEatrGugTlOz3yrMmMk7VoBca4M");
|
|
|
+ getContent("<p>内容</p>");
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|