From 5da53f02ea84d3c112669627577a967f5693ba7b Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Wed, 27 Apr 2022 16:09:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=88=A4=E6=96=AD=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=98=AF=E5=90=A6=E5=B7=B2=E5=8F=91=E9=80=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/java/DisasterWarning/db.json | 4 +- .../wechat/officalAccount/sendMessage.java | 58 +++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/code/java/DisasterWarning/db.json b/code/java/DisasterWarning/db.json index 16c135f..6b84635 100644 --- a/code/java/DisasterWarning/db.json +++ b/code/java/DisasterWarning/db.json @@ -2,8 +2,8 @@ "tns_name": "xmcx1", "ip_addr": "10.39.0.86", "jdbc_url": "", - "user_name": "xim_offical_account", - "password": "Cpic#1234", + "user_name": "wechat", + "password": "@rn7Q+t5zeyKIZ~s", "tables": [ { "table_name": "", diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/wechat/officalAccount/sendMessage.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/wechat/officalAccount/sendMessage.java index 2853e65..767371c 100644 --- a/code/java/DisasterWarning/src/main/java/com/cpic/xim/wechat/officalAccount/sendMessage.java +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/wechat/officalAccount/sendMessage.java @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2022-04-22 10:53:49 * @LastEditors: Kane - * @LastEditTime: 2022-04-25 19:20:32 + * @LastEditTime: 2022-04-27 16:09:17 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java * @Description: 用来推送公众号消息的程序库。 * @@ -16,7 +16,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.net.MalformedURLException; import java.util.HashMap; import java.util.Vector; +import java.util.logging.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import com.cpic.xim.notify.disaster.*; import com.cpic.xim.httpUtil.HttpUtils; @@ -49,7 +55,7 @@ public class sendMessage headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" ); // 遍历消息,将消息推送出去。 - for ( QWeatherDisasterWarningItem item : warningItems) + for ( QWeatherDisasterWarningItem item : warningItems ) { // 拼接消息内容 String title = item.getTitle(); @@ -68,7 +74,7 @@ public class sendMessage { HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() ); } - catch (MalformedURLException error) + catch ( MalformedURLException error ) { error.printStackTrace(); } @@ -80,11 +86,55 @@ public class sendMessage * @param warningID * @return */ - private boolean checkWarningHasSended( String warningID ) + public boolean checkWarningHasSended( String warningID ) + throws ClassNotFoundException, SQLException { boolean result = false; + // 暂时写死,以后改成读取配置方式 + String jdbcURL = "jdbc:oracle:thin@10.39.0.86:1521:wechat"; + String userName = "wechat"; + String password = "@rn7Q+t5zeyKIZ~s"; + String sql = "select count(*) from weather_disaster_notify where notify_id = ?"; + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + + // Logger logger = Logger.getLogger( "com.cpicxim.wechat.officalAccount.sendMessage" ); + + try + { + Class.forName( "oracle.jdbc.driver.OracleDriver" ); + + conn = DriverManager.getConnection( jdbcURL, userName, password ); + stmt = conn.prepareStatement( sql ); + stmt.setString( 1, warningID ); + + rs = stmt.executeQuery( sql ); + + if ( rs.next() && rs.getInt( 0 ) == 0) + { + result = true; + } + } + finally + { + if ( rs != null) + { + rs.close(); + } + + if ( stmt != null) + { + stmt.close(); + } + + if ( conn != null) + { + conn.close(); + } + } return result; }