This commit is contained in:
Kane Wang 2022-12-16 15:51:44 +08:00
parent c988bf4c91
commit cba061e177
1 changed files with 37 additions and 36 deletions

View File

@ -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-05-12 09:51:13 * @LastEditTime: 2022-12-16 15:51:36
* @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: 用来推送公众号消息的程序库
* *
@ -37,15 +37,15 @@ public class sendMessage
{ {
private static HashMap<String, String> warningLevel; private static HashMap<String, String> warningLevel;
/** /*****************************************************
* 推送天气灾害预警接口文档参考 彭奕洁 编写消息发送接口调用文档 * 推送天气灾害预警接口文档参考 彭奕洁 编写消息发送接口调用文档
* 使用 post 方式请求体内容以最基础的 post 格式 * 使用 post 方式请求体内容以最基础的 post 格式
* *
* @param officalAccountURL 产险厦门分公司公众号接口网址 * @param officalAccountURL 产险厦门分公司公众号接口网址
* @param warningItem 灾害预警对象 * @param warningItem 灾害预警对象
*/ *****************************************************/
public static void sendWeatherDisasterWarning( String officalAccountURL, public static void sendWeatherDisasterWarning( String officalAccountURL,
QWeatherDisasterWarningItem warningItem ) QWeatherDisasterWarningItem warningItem )
{ {
// Vector<QWeatherDisasterWarningItem> warningItems = warningItem.getWarning(); // Vector<QWeatherDisasterWarningItem> warningItems = warningItem.getWarning();
StringBuilder requestBody = null; StringBuilder requestBody = null;
@ -61,7 +61,7 @@ public class sendMessage
// 拼接消息内容 // 拼接消息内容
String title = warningItem.getTitle(); String title = warningItem.getTitle();
String text = warningItem.getText(); String text = warningItem.getText();
String color = warningLevel.containsKey( warningItem.getLevel() ) String color = warningLevel.containsKey( warningItem.getLevel() )
? warningLevel.get( warningItem.getLevel() ) ? warningLevel.get( warningItem.getLevel() )
: "#000000"; : "#000000";
@ -98,14 +98,14 @@ public class sendMessage
OracleConfig dbConfig = OracleConfigManager.getOracleConfig(); OracleConfig dbConfig = OracleConfigManager.getOracleConfig();
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String jdbcURL = dbConfig.getJdbcURL(); String jdbcURL = dbConfig.getJdbcURL();
String userName = dbConfig.getUserName(); String userName = dbConfig.getUserName();
String password = dbConfig.getPassword(); String password = dbConfig.getPassword();
String sql = "select count(*) from weather_disaster_notify where notify_id = ?"; String sql = "select count(*) from weather_disaster_notify where notify_id = ?";
// Logger logger = Logger.getLogger( "com.cpicxim.wechat.officalAccount.sendMessage" ); // Logger logger = Logger.getLogger( "com.cpicxim.wechat.officalAccount.sendMessage" );
@ -119,7 +119,7 @@ public class sendMessage
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if ( rs.next() && rs.getInt( 1 ) == 0 ) if ( rs.next() && rs.getInt( 1 ) == 0)
{ {
result = true; result = true;
} }
@ -128,7 +128,7 @@ public class sendMessage
{ {
try try
{ {
if ( rs != null ) if ( rs != null)
{ {
rs.close(); rs.close();
} }
@ -140,7 +140,7 @@ public class sendMessage
try try
{ {
if ( stmt != null ) if ( stmt != null)
{ {
stmt.close(); stmt.close();
} }
@ -152,7 +152,7 @@ public class sendMessage
try try
{ {
if ( conn != null ) if ( conn != null)
{ {
conn.close(); conn.close();
} }
@ -178,20 +178,20 @@ public class sendMessage
* @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常 * @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常
*/ */
public static void saveWeatherDisasterWarning( String city, public static void saveWeatherDisasterWarning( String city,
QWeatherDisasterWarningItem warning ) QWeatherDisasterWarningItem warning )
throws SQLException, IOException, ClassNotFoundException throws SQLException, IOException, ClassNotFoundException
{ {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
String sql = new StringBuilder().append( "insert into weather_disaster_notify(notify_id, sender, city," ) String sql = new StringBuilder()
.append( "warning_level, warning_type_code, warning_type_name, title," ) .append( "insert into weather_disaster_notify(notify_id, sender, city," )
.append( "text, pub_time) values( ?,?,?,?,?,?,?,?,?)" ) .append( "warning_level, warning_type_code, warning_type_name, title," )
.toString(); .append( "text, pub_time) values( ?,?,?,?,?,?,?,?,?)" ).toString();
OracleConfig dbConfig = OracleConfigManager.getOracleConfig(); OracleConfig dbConfig = OracleConfigManager.getOracleConfig();
String jdbcURL = dbConfig.getJdbcURL(); String jdbcURL = dbConfig.getJdbcURL();
String userName = dbConfig.getUserName(); String userName = dbConfig.getUserName();
String password = dbConfig.getPassword(); String password = dbConfig.getPassword();
@ -224,7 +224,7 @@ public class sendMessage
catch ( SQLException error ) catch ( SQLException error )
{ {
// 出现sql错误就回滚 // 出现sql错误就回滚
if ( conn != null ) if ( conn != null)
{ {
conn.rollback(); conn.rollback();
} }
@ -235,7 +235,7 @@ public class sendMessage
{ {
try try
{ {
if ( stmt != null ) if ( stmt != null)
{ {
stmt.close(); stmt.close();
} }
@ -247,7 +247,7 @@ public class sendMessage
try try
{ {
if ( conn != null ) if ( conn != null)
{ {
conn.close(); conn.close();
} }
@ -271,49 +271,50 @@ public class sendMessage
} }
} }
class WechatOfficalAccountMessageParameter class WechatOfficalAccountMessageParameter
{ {
WechatOfficalAccountMessageParameter() WechatOfficalAccountMessageParameter()
{ {
tplID = 57; tplID = 57;
groupID = 1; groupID = 1;
} }
@JsonProperty("tplid") @JsonProperty( "tplid")
private int tplID; private int tplID;
@JsonProperty("groupid") @JsonProperty( "groupid")
private int groupID; private int groupID;
@JsonProperty("first") @JsonProperty( "first")
private String first; private String first;
@JsonProperty("keyword1") @JsonProperty( "keyword1")
private String keyword1; private String keyword1;
@JsonProperty("keyword1color") @JsonProperty( "keyword1color")
private String keyword1Color; private String keyword1Color;
@JsonProperty("keyword2") @JsonProperty( "keyword2")
private String keyword2; private String keyword2;
@JsonProperty("keyword2color") @JsonProperty( "keyword2color")
private String keyword2Color; private String keyword2Color;
@JsonProperty("remark") @JsonProperty( "remark")
private String remark; private String remark;
@JsonProperty("remarkcolor") @JsonProperty( "remarkcolor")
private String remarkColor; private String remarkColor;
@JsonProperty("url") @JsonProperty( "url")
private String url; private String url;
@JsonProperty("appid") @JsonProperty( "appid")
private String appid; private String appid;
@JsonProperty("pagepath") @JsonProperty( "pagepath")
private String pagePath; private String pagePath;
public int getTplID() public int getTplID()