Explorar el Código

Merge remote-tracking branch 'origin/V1' into V1

xiao547607 hace 5 años
padre
commit
f5c0f7cb3c

+ 22 - 14
common/src/main/java/com/jpsoft/smart/modules/common/utils/HttpConnectionUtil.java

@@ -12,6 +12,9 @@ import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.conn.socket.PlainConnectionSocketFactory;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
 import org.apache.http.util.EntityUtils;
@@ -28,9 +31,12 @@ import java.net.URL;
 import java.util.Iterator;
 import java.util.Map;
 
-
 public class HttpConnectionUtil {
-    public static String getHttpContent(String url) {
+	private static int connectTimeoutMs = 10000;
+	private static int readTimeoutMs = 10000;
+	private static String charSet = "UTF-8";
+
+	public static String getHttpContent(String url) {
         return getHttpContent(url, "UTF-8");
     }
 
@@ -196,11 +202,7 @@ public class HttpConnectionUtil {
         }
         return "";
     }
-    
-    private static int connectTimeoutMs = 3000;
-	private static int readTimeoutMs = 3000;
-	private static String charSet = "UTF-8";
-	
+
 	/**
 	 * 以http post方式请求
 	 * @param url 请求地址
@@ -232,7 +234,7 @@ public class HttpConnectionUtil {
     public static String requestByPost(String url,String charSet,String data, int connectTimeoutMs, int readTimeoutMs){
     	try{
 	        BasicHttpClientConnectionManager connManager;
-	        
+
 	        connManager = new BasicHttpClientConnectionManager(
 	                RegistryBuilder.<ConnectionSocketFactory>create()
 	                        .register("http", PlainConnectionSocketFactory.getSocketFactory())
@@ -242,20 +244,26 @@ public class HttpConnectionUtil {
 	                null,
 	                null
 	        );
-	
+
 	        HttpClient httpClient = HttpClientBuilder.create()
+					//取消HttpClient 设置超时后,若在设定的时间内没有返回数据,httpClient底层会重复请求
+					.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false))
 	                .setConnectionManager(connManager)
 	                .build();
-	        
+
 	        HttpPost httpPost = new HttpPost(url);
-	        
-	        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(readTimeoutMs).setConnectTimeout(connectTimeoutMs).build();
+
+	        RequestConfig requestConfig = RequestConfig.custom()
+					.setSocketTimeout(readTimeoutMs)
+					.setConnectTimeout(connectTimeoutMs)
+					.build();
+
 	        httpPost.setConfig(requestConfig);
-	
+
 	        StringEntity postEntity = new StringEntity(data, charSet);
 	        httpPost.addHeader("Content-Type", "text/xml");
 	        httpPost.setEntity(postEntity);
-	
+
 	        HttpResponse httpResponse = httpClient.execute(httpPost);
 	        HttpEntity httpEntity = httpResponse.getEntity();
 	        return EntityUtils.toString(httpEntity, "UTF-8");

+ 357 - 295
common/src/main/java/com/jpsoft/smart/modules/common/utils/WechatMessageUtil.java

@@ -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>");
 
+    }
 
 
 }

+ 0 - 13
common/src/main/java/com/jpsoft/smart/modules/common/utils/WeixinUtil.java

@@ -297,9 +297,6 @@ public class WeixinUtil {
 		button3.put("key","文章");
 		buttonArray.add(button3);
 
-
-
-
 		data.put("button", buttonArray);
 		data.put("action_name", "QR_LIMIT_STR_SCENE");
 
@@ -315,18 +312,8 @@ public class WeixinUtil {
 		//创建菜单
 		String result = HttpConnectionUtil.getHttpContentByPost(" https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + token.getToken(), "utf-8", data.toString());
 
-
-
 		return result;
-
 	}
 
-	public static void main(String[] args){
-
-		//String result = createMenu("wx0b3c41a903053808","43557bd62f77b0c3d6670e991872f0e7");
-		System.out.println("//");
-	}
-
-
 
 }

+ 1 - 6
web/src/main/java/com/jpsoft/smart/modules/wechat/controller/WxController.java

@@ -865,7 +865,6 @@ public class WxController {
             //扫码用户openID
             String openId = requestJson.getStr("FromUserName");
 
-
             boolean processed = false;
 
             if (StringUtils.isNotEmpty(eventKey) && eventKey.indexOf(",") != -1) {
@@ -873,7 +872,6 @@ public class WxController {
                 String eventCode = keys[0];
                 String id = keys[1];
 
-
                 ReplyMessage replyMessage = replyMessageService.findByEvent(eventCode);
 
                 if (replyMessage != null) {
@@ -889,7 +887,6 @@ public class WxController {
                             warningPusherService.update(warningPusher);
                             WeixinUtil.replyTextMessage(response, wechatId, openId, replyMessage.getMessage());
                         }
-
                     }
                     if ("4000".equals(eventCode)) {
                         CompanyInfo companyInfo = companyInfoService.get(id);
@@ -900,11 +897,9 @@ public class WxController {
                         }
                     }
 
-
                     processed = true;
                 }
             } else if ("文章".equals(eventKey)) {
-
                 WeixinUtil.replyArticlesMessage(response, wechatId, openId, "复工复学疫情防控监管平台", "即日起接受预定,货源紧张,先订先得。\n预定电话:13972127999 市企业联合会蔡秘书长;\n19971390396 刘经理;15607217777 付经理。", "http://wisdomhousewechat.sudaonline.net/1111.jpg", "https://mp.weixin.qq.com/s/nXYp0m8OOYdWBRu-80SnmQ");
             } else {
                 WeixinUtil.replyTextMessage(response, wechatId, openId, "您好,欢迎关注荆鹏云管家。\n" +
@@ -912,7 +907,6 @@ public class WxController {
                         "疫情监管产品介绍:<a href=\"https://mp.weixin.qq.com/s/nXYp0m8OOYdWBRu-80SnmQ\">点击查看详情</a>");
             }
 
-
             if (!processed) {
                 String responseText = "success";
 
@@ -926,6 +920,7 @@ public class WxController {
                         log.warn(openId + ",事件:" + event + "未设置自动回复!");
                         response.getWriter().print(responseText);
                     }*/
+                    response.getWriter().print(responseText);
                 } else {
                     response.getWriter().print(responseText);
                 }

+ 46 - 18
web/src/main/java/com/jpsoft/smart/schduled/UnmeasureTemperatureAlarmTask.java

@@ -7,12 +7,10 @@ import com.jpsoft.smart.modules.base.entity.*;
 import com.jpsoft.smart.modules.base.service.*;
 import com.jpsoft.smart.modules.business.entity.WorkAttendance;
 import com.jpsoft.smart.modules.business.service.WorkAttendanceService;
-import com.jpsoft.smart.modules.common.utils.JwtUtil;
-import com.jpsoft.smart.modules.common.utils.OSSUtil;
-import com.jpsoft.smart.modules.common.utils.POIUtils;
-import com.jpsoft.smart.modules.common.utils.WechatMessageUtil;
+import com.jpsoft.smart.modules.common.utils.*;
 import com.jpsoft.smart.modules.sys.entity.SysLog;
 import com.jpsoft.smart.modules.sys.service.SysLogService;
+import com.jpsoft.smart.modules.wechat.entity.AccessToken;
 import com.sun.corba.se.spi.orbutil.threadpool.Work;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.security.Keys;
@@ -33,9 +31,10 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import java.io.*;
+import java.net.HttpURLConnection;
 import java.net.SocketAddress;
+import java.net.URL;
 import java.net.URLEncoder;
 import java.security.Key;
 import java.text.ParseException;
@@ -464,9 +463,9 @@ public class UnmeasureTemperatureAlarmTask {
                 sendData.put("keyword3", keyword3);
                 sendData.put("remark", remark);
 
-                writeDbLog(String.format("向未测温人:%s 发送测温提醒通知",personInfo.getName()),alarmConfig.getCompanyId());
+                writeDbLog(String.format("向未测温人:%s,%s发送测温提醒通知",personInfo.getName(),personInfo.getOpenId()),alarmConfig.getCompanyId());
 
-                WechatMessageUtil.sendTemplate(sendData, wxConfig.getAppId(),wxConfig.getAppSecret(),remindTmplCode,personInfo.getOpenId(), null);
+                WechatMessageUtil.sendNativeTemplate(wxConfig.getAppId(),wxConfig.getAppSecret(),remindTmplCode,personInfo.getOpenId(),sendData,null);
             }
         }
     }
@@ -498,7 +497,7 @@ public class UnmeasureTemperatureAlarmTask {
             if (StringUtils.isNotEmpty(pusher.getOpenId())
             && pusher.getMissingNoticeEnabled()!=null && pusher.getMissingNoticeEnabled()) {
                 String message = "尊敬的" + pusher.getName()
-                        + ",当天时段" + startTime.toString("HH:mm") + "至" + endTime.toString("HH:mm")
+                        + "," + startTime.toString("yyyy-MM-dd") + "时段" + startTime.toString("HH:mm") + "至" + endTime.toString("HH:mm")
                         + ",有" + total + "人未测量体温,具体名单请点击下方【查看详情】查看";
 
                 //todo 生成未测量人员名单
@@ -510,7 +509,8 @@ public class UnmeasureTemperatureAlarmTask {
                 }
 
                 try {
-                    writeDbLog(String.format("查询单位:%s,测温统计信息接收人: %s,personId=%s",companyInfo.getName(),pusher.getName(),personId),companyInfo.getId());
+                    writeDbLog(String.format("查询单位:%s,测温统计信息接收人: %s,personId=%s,未测温人数:%s",
+                            companyInfo.getName(),pusher.getName(),personId,total),companyInfo.getId());
 
                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -637,13 +637,41 @@ public class UnmeasureTemperatureAlarmTask {
     }
 
     public static void main(String[] args) {
-        String str = String.format(
-                "查询考勤时段:%s~%s,未考勤人员数量:%s",
-                "2020-04-24 08:00",
-                "2020-04-24 09:00",
-                10
-        );
-
-        System.out.println(str);
+        String message ="请抓紧时间在单位内任意打卡点打卡和测温!";
+
+        JSONObject sendData = new JSONObject();
+
+        JSONObject first = new JSONObject();
+        first.put("value", "未测温提醒");
+        first.put("color", "#FF0000");
+
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", "当前用户");
+        keyword1.put("color", "#173177");
+
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
+        keyword2.put("color", "#173177");
+
+        JSONObject keyword3 = new JSONObject();
+        keyword3.put("value", "待测温");
+        keyword3.put("color", "#173177");
+
+        JSONObject remark = new JSONObject();
+        remark.put("value", message);
+        remark.put("color", "#173177");
+
+        sendData.put("first", first);
+        sendData.put("keyword1", keyword1);
+        sendData.put("keyword2", keyword2);
+        sendData.put("keyword3", keyword3);
+        sendData.put("remark", remark);
+
+        String appId = "wx0b3c41a903053808";
+        String appSecret = "43557bd62f77b0c3d6670e991872f0e7";
+        String remindTmplCode = "Nsn_8-M25Ef_KThmin8uDocXeh8XVQMC1rVzBAIaeig";
+        String openId = "oLowyuB1PliW0qAnJJ56axydeUOM";
+
+        WechatMessageUtil.sendNativeTemplate(appId,appSecret,remindTmplCode,openId,sendData ,null);
     }
 }