完成判断消息是否已发送功能!
This commit is contained in:
parent
0587001de0
commit
5da53f02ea
@ -2,8 +2,8 @@
|
|||||||
"tns_name": "xmcx1",
|
"tns_name": "xmcx1",
|
||||||
"ip_addr": "10.39.0.86",
|
"ip_addr": "10.39.0.86",
|
||||||
"jdbc_url": "",
|
"jdbc_url": "",
|
||||||
"user_name": "xim_offical_account",
|
"user_name": "wechat",
|
||||||
"password": "Cpic#1234",
|
"password": "@rn7Q+t5zeyKIZ~s",
|
||||||
"tables": [
|
"tables": [
|
||||||
{
|
{
|
||||||
"table_name": "",
|
"table_name": "",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-22 10:53:49
|
* @Date: 2022-04-22 10:53:49
|
||||||
* @LastEditors: Kane
|
* @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
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
|
||||||
* @Description: 用来推送公众号消息的程序库。
|
* @Description: 用来推送公众号消息的程序库。
|
||||||
*
|
*
|
||||||
@ -16,7 +16,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Vector;
|
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.notify.disaster.*;
|
||||||
import com.cpic.xim.httpUtil.HttpUtils;
|
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" );
|
headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );
|
||||||
|
|
||||||
// 遍历消息,将消息推送出去。
|
// 遍历消息,将消息推送出去。
|
||||||
for ( QWeatherDisasterWarningItem item : warningItems)
|
for ( QWeatherDisasterWarningItem item : warningItems )
|
||||||
{
|
{
|
||||||
// 拼接消息内容
|
// 拼接消息内容
|
||||||
String title = item.getTitle();
|
String title = item.getTitle();
|
||||||
@ -68,7 +74,7 @@ public class sendMessage
|
|||||||
{
|
{
|
||||||
HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() );
|
HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() );
|
||||||
}
|
}
|
||||||
catch (MalformedURLException error)
|
catch ( MalformedURLException error )
|
||||||
{
|
{
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -80,11 +86,55 @@ public class sendMessage
|
|||||||
* @param warningID
|
* @param warningID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean checkWarningHasSended( String warningID )
|
public boolean checkWarningHasSended( String warningID )
|
||||||
|
throws ClassNotFoundException, SQLException
|
||||||
{
|
{
|
||||||
boolean result = false;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user