Просмотр исходного кода

HttpClient 设置超时后,若在设定的时间内没有返回数据,httpClient底层会重复请求

zhengqiang 5 лет назад
Родитель
Сommit
41a276ef5b

+ 21 - 12
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 = 5000;
+	private static int readTimeoutMs = 5000;
+	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 请求地址
@@ -242,20 +244,27 @@ 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");

+ 305 - 322
common/src/main/java/com/jpsoft/smart/modules/common/utils/WechatMessageUtil.java

@@ -2,6 +2,7 @@ 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;
 
@@ -11,410 +12,394 @@ 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");
-
-		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 keyword3 = new JSONObject();
-		keyword3.put("value", detailAmount);
-		keyword3.put("color", "#173177");
-
-
-
-		String remarkStr = "账单来源:" + propertyName;
-
-		if(StringUtils.isNotBlank(billRemark)){
-			remarkStr = remarkStr + "\n备注:"+ billRemark +"";
-		}
-
-		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);
+    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();
 
-		//w8Zk_VQMFIEVSIBPZid7zSrvHmBdrgnqF76u8PLCZEs cs
-		boolean ret = sendTemplate(sendData, appId,appSecret,billTemplateId,openId, TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + billDetailId +"payTime=0&payType=bill");
+        JSONObject first = new JSONObject();
+        first.put("value", "您有一个新的账单,点击查看详情!");
+        first.put("color", "#FF0000");
 
-		return ret;
-	}
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", fullName);
+        keyword1.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 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", feeName);
-		keyword2.put("color", "#173177");
+        if (StringUtils.isNotBlank(billRemark)) {
+            remarkStr = remarkStr + "\n备注:" + billRemark + "";
+        }
 
+        JSONObject remark = new JSONObject();
+        remark.put("value", remarkStr);
+        remark.put("color", "#173177");
 
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        sendData.put("first", first);
+        sendData.put("keyword1", keyword1);
+        sendData.put("keyword2", keyword2);
+        sendData.put("keyword3", keyword3);
+        sendData.put("remark", remark);
 
-		JSONObject keyword3 = new JSONObject();
-		keyword3.put("value", sdf.format(createTime));
-		keyword3.put("color", "#173177");
+        //w8Zk_VQMFIEVSIBPZid7zSrvHmBdrgnqF76u8PLCZEs cs
+        boolean ret = sendTemplate(sendData, appId, appSecret, billTemplateId, openId, TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + billDetailId + "payTime=0&payType=bill");
 
-		JSONObject keyword4 = new JSONObject();
+        return ret;
+    }
 
-		keyword4.put("value", "¥" + amount.setScale(2) + "元");
-		keyword4.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();
 
+        JSONObject first = new JSONObject();
+        first.put("value", "账单支付成功!");
+        first.put("color", "#FF0000");
 
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", fullName);
+        keyword1.put("color", "#173177");
 
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", feeName);
+        keyword2.put("color", "#173177");
 
-		String remarkStr = "感谢您的支持,点击查看缴费详情";
 
-		JSONObject remark = new JSONObject();
-		remark.put("value", remarkStr);
-		remark.put("color", "#173177");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 
-		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 keyword3 = new JSONObject();
+        keyword3.put("value", sdf.format(createTime));
+        keyword3.put("color", "#173177");
 
-		//w8Zk_VQMFIEVSIBPZid7zSrvHmBdrgnqF76u8PLCZEs cs
-		boolean ret = sendTemplate(sendData,appId,appSecret,payedTemplateId ,openId,TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + billDetailId +"payTime=1&payType=bill");
+        JSONObject keyword4 = new JSONObject();
 
-		return ret;
-	}
+        keyword4.put("value", "¥" + amount.setScale(2) + "元");
+        keyword4.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 sendData = new JSONObject();
+        String remarkStr = "感谢您的支持,点击查看缴费详情";
 
-		JSONObject first = new JSONObject();
-		first.put("value", "账单支付成功!");
-		first.put("color", "#FF0000");
+        JSONObject remark = new JSONObject();
+        remark.put("value", remarkStr);
+        remark.put("color", "#173177");
 
-		JSONObject keyword1 = new JSONObject();
-		keyword1.put("value", fullName);
-		keyword1.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 keyword2 = new JSONObject();
-		keyword2.put("value", feeName);
-		keyword2.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;
+    }
 
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+    //
+    public static boolean sendScanPayedMessage(String fullName, String feeName, Date createTime, BigDecimal amount, String openId, String independentPayId, String payedTemplateId, String appId, String appSecret) {
 
-		JSONObject keyword3 = new JSONObject();
-		keyword3.put("value", sdf.format(createTime));
-		keyword3.put("color", "#173177");
+        JSONObject sendData = new JSONObject();
 
-		JSONObject keyword4 = new JSONObject();
+        JSONObject first = new JSONObject();
+        first.put("value", "账单支付成功!");
+        first.put("color", "#FF0000");
 
-		keyword4.put("value", "¥" + amount.setScale(2) + "元");
-		keyword4.put("color", "#173177");
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", fullName);
+        keyword1.put("color", "#173177");
 
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", feeName);
+        keyword2.put("color", "#173177");
 
 
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 
+        JSONObject keyword3 = new JSONObject();
+        keyword3.put("value", sdf.format(createTime));
+        keyword3.put("color", "#173177");
 
-		String remarkStr = "感谢您的支持,点击查看缴费详情";
+        JSONObject keyword4 = new JSONObject();
 
-		JSONObject remark = new JSONObject();
-		remark.put("value", remarkStr);
-		remark.put("color", "#173177");
+        keyword4.put("value", "¥" + amount.setScale(2) + "元");
+        keyword4.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);
 
-		boolean ret = sendTemplate(sendData,appId,appSecret,payedTemplateId ,openId,TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + independentPayId +"payTime=1&payType=wechat");
+        String remarkStr = "感谢您的支持,点击查看缴费详情";
 
-		return ret;
-	}
+        JSONObject remark = new JSONObject();
+        remark.put("value", remarkStr);
+        remark.put("color", "#173177");
 
-	/**
-	 * 发送通知信息
-	 * @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) {
+        sendData.put("first", first);
+        sendData.put("keyword1", keyword1);
+        sendData.put("keyword2", keyword2);
+        sendData.put("keyword3", keyword3);
+        sendData.put("keyword4", keyword4);
+        sendData.put("remark", remark);
 
+        boolean ret = sendTemplate(sendData, appId, appSecret, payedTemplateId, openId, TEMPLATE_REDIRECT_PRE_URL + "/billDetail/" + independentPayId + "payTime=1&payType=wechat");
 
-		JSONObject sendData = new JSONObject();
-		String finallyContent = getContent(content);
-		JSONObject first = new JSONObject();
-		first.put("value", "您好,园区通知如下:");
-		first.put("color", "#173177");
+        return ret;
+    }
 
-		JSONObject keyword1 = new JSONObject();
-		keyword1.put("value", noticeName);
-		keyword1.put("color", "#173177");
+    /**
+     * 发送通知信息
+     *
+     * @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) {
 
 
+        JSONObject sendData = new JSONObject();
+        String finallyContent = getContent(content);
+        JSONObject first = new JSONObject();
+        first.put("value", "您好,园区通知如下:");
+        first.put("color", "#173177");
 
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", noticeName);
+        keyword1.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");
+        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("keyword3", keyword3);
-		sendData.put("remark", remark);
+        JSONObject keyword3 = new JSONObject();
+        keyword3.put("value", finallyContent);
+        keyword3.put("color", "#173177");
 
-		//noticeDetailId
-		boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, TEMPLATE_REDIRECT_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
+        JSONObject remark = new JSONObject();
+        remark.put("value", "点击查看详情");
+        remark.put("color", "#173177");
 
-		return ret;
-	}
+        sendData.put("first", first);
+        sendData.put("keyword1", keyword1);
+        sendData.put("keyword2", keyword2);
+        sendData.put("keyword3", keyword3);
+        sendData.put("remark", remark);
 
-	/**
-	 * 发送物业管理通知信息
-	 * @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) {
+        //noticeDetailId
+        boolean ret = sendTemplate(sendData, appId, appSecret, noticeTemplateId, openId, TEMPLATE_REDIRECT_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
 
+        return ret;
+    }
 
-		JSONObject sendData = new JSONObject();
-		String finallyContent = getContent(content);
-		JSONObject first = new JSONObject();
-		first.put("value", "您好,物业管理通知如下:");
-		first.put("color", "#173177");
+    /**
+     * 发送物业管理通知信息
+     *
+     * @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 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");
 
-		JSONObject keyword2 = new JSONObject();
-		keyword2.put("value", sdf.format(new Date()));
-		keyword2.put("color", "#173177");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 
-		JSONObject keyword3 = new JSONObject();
-		keyword3.put("value", finallyContent);
-		keyword3.put("color", "#173177");
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", sdf.format(new Date()));
+        keyword2.put("color", "#173177");
 
-		JSONObject remark = new JSONObject();
-		remark.put("value", "点击查看详情");
-		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("remark", remark);
+        JSONObject remark = new JSONObject();
+        remark.put("value", "点击查看详情");
+        remark.put("color", "#173177");
 
-		//noticeDetailId
-		boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, TEMPERATURE_ALARM_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
+        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, TEMPERATURE_ALARM_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
 
-		return ret;
-	}
+        return ret;
+    }
+
+    /**
+     * 发送警告通知信息
+     *
+     * @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) {
 
-	/**
-	 * 发送警告通知信息
-	 * @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();
+        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 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", sdf.format(createTime));
+        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");
+
+        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("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;
+
+        AccessToken accessToken = WeixinUtil.getAccessToken(appId, appSecret);
+
+        if (accessToken != null) {
+            //发送模版内容
+            String sendTemplateUrl = send_template.replace("ACCESS_TOKEN", accessToken.getToken());
 
-		JSONObject keyword2 = new JSONObject();
-		keyword2.put("value", finallyContent);
-		keyword2.put("color", "#173177");
+            JSONObject sendTemplateData = new JSONObject();
 
-		JSONObject remark = new JSONObject();
-		remark.put("value", "请尽快查看");
-		remark.put("color", "#173177");
+            sendTemplateData.put("touser", openId);
+            sendTemplateData.put("template_id", templateId);
+            sendTemplateData.put("url", url);
+            sendTemplateData.put("data", sendData);
 
-		sendData.put("first", first);
-		sendData.put("keyword1", keyword1);
-		sendData.put("keyword2", keyword2);
-		//sendData.put("remark", remark);
+            log.warn("模版发送Id>>>>" + templateId + ">>>模版发送数据>>>>>" + sendTemplateData.toString());
 
-		//noticeDetailId
-		boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, "");
+            String sendTemplateRet = HttpConnectionUtil.requestByPost(sendTemplateUrl, sendTemplateData.toString());
 
-		return ret;
-	}
+            log.warn("模版发送返回数据>>>>>" + sendTemplateRet);
 
-	/**
-	 * 微信发送模版
-	 * @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;
-
-
-		AccessToken accessToken = WeixinUtil.getAccessToken(appId, appSecret);
-
-		if(accessToken != null){
-			//发送模版内容
-			String sendTemplateUrl = send_template.replace("ACCESS_TOKEN", accessToken.getToken());
-
-			JSONObject sendTemplateData = new JSONObject();
-
-			sendTemplateData.put("touser", openId);
-			sendTemplateData.put("template_id", templateId);
-			sendTemplateData.put("url", url);
-			sendTemplateData.put("data", sendData);
-
-			System.out.println("模版发送Id>>>>" + templateId + ">>>模版发送数据>>>>>" + sendTemplateData.toString());
-
-			String sendTemplateRet =  HttpConnectionUtil.requestByPost(sendTemplateUrl, sendTemplateData.toString());
-
-			System.out.println("模版发送返回数据>>>>>" + sendTemplateRet);
-
-			if(StringUtils.isNotBlank(sendTemplateRet)){
-				JSONObject sendTemplateJson = JSONObject.fromObject(sendTemplateRet);
-
-				if("0".equals(sendTemplateJson.getString("errcode"))){
-					//发送成功
-					result = true;
-				}
-			}
-		}
-
-		return result;
-	}
-
-	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) {
+            if (StringUtils.isNotBlank(sendTemplateRet)) {
+                JSONObject sendTemplateJson = JSONObject.fromObject(sendTemplateRet);
+
+                if ("0".equals(sendTemplateJson.getString("errcode"))) {
+                    //发送成功
+                    result = true;
+                }
+            }
+        }
+
+        return result;
+    }
+
+    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) {
 
 
         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 +408,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>");
 
+    }
 
 
 }

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

+ 3 - 2
web/src/main/java/com/jpsoft/smart/schduled/UnmeasureTemperatureAlarmTask.java

@@ -498,7 +498,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 +510,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");