问题已修正!
This commit is contained in:
		@@ -8,9 +8,7 @@
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.oracle</groupId>
 | 
			
		||||
            <artifactId>ojdbc8</artifactId>
 | 
			
		||||
            <version>1.0</version>
 | 
			
		||||
            <scope>system</scope>
 | 
			
		||||
            <systemPath>${project.basedir}/lib/ojdbc8.jar</systemPath>
 | 
			
		||||
            <version>19.3.0.0.0</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.apache.httpcomponents</groupId>
 | 
			
		||||
@@ -23,37 +21,6 @@
 | 
			
		||||
            <version>4.13.2</version>
 | 
			
		||||
            <scope>test</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <!-- <dependency>
 | 
			
		||||
            <groupId>commons-beanutils</groupId>
 | 
			
		||||
            <artifactId>commons-beanutils</artifactId>
 | 
			
		||||
            <version>1.9.4</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>commons-collections</groupId>
 | 
			
		||||
            <artifactId>commons-collections</artifactId>
 | 
			
		||||
            <version>20040616</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>commons-lang</groupId>
 | 
			
		||||
            <artifactId>commons-lang</artifactId>
 | 
			
		||||
            <version>2.6</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>commons-logging</groupId>
 | 
			
		||||
            <artifactId>commons-logging</artifactId>
 | 
			
		||||
            <version>1.1.1</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>net.sf.ezmorph</groupId>
 | 
			
		||||
            <artifactId>ezmorph</artifactId>
 | 
			
		||||
            <version>1.0.6</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>net.sf.json-lib</groupId>
 | 
			
		||||
            <artifactId>json-lib</artifactId>
 | 
			
		||||
            <version>2.4</version>
 | 
			
		||||
            <classifier>jdk15</classifier>
 | 
			
		||||
        </dependency> -->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.fasterxml.jackson.core</groupId>
 | 
			
		||||
            <artifactId>jackson-core</artifactId>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-05-10 16:28:07
 | 
			
		||||
 * @LastEditTime: 2022-05-10 19:03:56
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\AppMain.java
 | 
			
		||||
 * @Description: 和风天气预警推送厦门太保公众号主程序!
 | 
			
		||||
 * 
 | 
			
		||||
@@ -11,6 +11,7 @@
 | 
			
		||||
import com.cpic.xim.config.AppConfigManager;
 | 
			
		||||
import com.cpic.xim.config.City;
 | 
			
		||||
import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
 | 
			
		||||
import com.cpic.xim.notify.disaster.QWeatherDisasterWarningItem;
 | 
			
		||||
import com.cpic.xim.notify.disaster.WeatherDisasterWarningGrabber;
 | 
			
		||||
import com.cpic.xim.wechat.officalAccount.sendMessage;
 | 
			
		||||
import com.cpic.xim.config.WeatherDisasterNotifyConfig;
 | 
			
		||||
@@ -79,23 +80,40 @@ public class AppMain
 | 
			
		||||
                    logger.log( Level.INFO, "查询{0}天气预警,结果:{1}。", new Object[]
 | 
			
		||||
                    { city.getCityName(), json} );
 | 
			
		||||
 | 
			
		||||
                    // 判断是否有警报
 | 
			
		||||
                    if ( warning.getWarning().isEmpty() == true)
 | 
			
		||||
                    Vector<QWeatherDisasterWarningItem> warningItems = warning.getWarning();
 | 
			
		||||
 | 
			
		||||
                    // 判断是否有警报,没有警报就结束当前城市的处理
 | 
			
		||||
                    if ( warningItems.isEmpty() == true)
 | 
			
		||||
                    {
 | 
			
		||||
                        logger.log( Level.INFO, "查询{0}天气预警,无警报!。", new Object[]
 | 
			
		||||
                        { city.getCityName()} );
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    logger.log( Level.INFO, "查询{0}天气预警,发送日志。", new Object[]
 | 
			
		||||
                    { city.getCityName()} );
 | 
			
		||||
                    // 有警报,就遍历警报数组
 | 
			
		||||
                    for ( QWeatherDisasterWarningItem item : warningItems )
 | 
			
		||||
                    {
 | 
			
		||||
                        // 先检查是否已经发送过
 | 
			
		||||
                        if ( sendMessage.checkWarningHasSended( item.getId() ) == false)
 | 
			
		||||
                        {
 | 
			
		||||
                            logger.log( Level.INFO, "查询{0}天气预警,ID:{1},已有发送记录,跳过。", new Object[]
 | 
			
		||||
                            { city.getCityName(), item.getId()} );
 | 
			
		||||
 | 
			
		||||
                    sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(),
 | 
			
		||||
                            warning );
 | 
			
		||||
                            continue;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                    logger.log( Level.INFO, "{0}天气预警,日志发送成功。", new Object[]
 | 
			
		||||
                    { city.getCityName()} );
 | 
			
		||||
                        // 没有发送过
 | 
			
		||||
                        logger.log( Level.INFO, "查询{0}天气预警,发送日志。", new Object[]
 | 
			
		||||
                        { city.getCityName()} );
 | 
			
		||||
 | 
			
		||||
                        sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(),
 | 
			
		||||
                                item );
 | 
			
		||||
 | 
			
		||||
                        logger.log( Level.INFO, "{0}天气预警,日志发送成功。", new Object[]
 | 
			
		||||
                        { city.getCityName()} );
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // 将发送的警报,保存起来
 | 
			
		||||
                    sendMessage.saveWeatherDisasterWarning( city.getCityName(), warning );
 | 
			
		||||
                }
 | 
			
		||||
                catch ( IOException error )
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-05-06 11:14:32
 | 
			
		||||
 * @LastEditTime: 2022-05-10 19:02:32
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
 | 
			
		||||
 * @Description: 用来推送公众号消息的程序库。
 | 
			
		||||
 *
 | 
			
		||||
@@ -17,7 +17,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.net.MalformedURLException;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
import java.sql.Connection;
 | 
			
		||||
import java.sql.DriverManager;
 | 
			
		||||
@@ -40,12 +39,12 @@ public class sendMessage
 | 
			
		||||
     * 推送天气灾害预警!接口文档参考 彭奕洁 编写《消息发送接口调用文档》
 | 
			
		||||
     * 使用 post 方式,请求体内容以最基础的 post 格式。
 | 
			
		||||
     * @param officalAccountURL 产险厦门分公司公众号接口网址
 | 
			
		||||
     * @param warning           灾害预警对象
 | 
			
		||||
     * @param warningItem           灾害预警对象
 | 
			
		||||
     */
 | 
			
		||||
    public static void sendWeatherDisasterWarning( String officalAccountURL,
 | 
			
		||||
            QWeatherDisasterWarning warning )
 | 
			
		||||
            QWeatherDisasterWarningItem warningItem )
 | 
			
		||||
    {
 | 
			
		||||
        Vector<QWeatherDisasterWarningItem> warningItems = warning.getWarning();
 | 
			
		||||
        // Vector<QWeatherDisasterWarningItem> warningItems = warningItem.getWarning();
 | 
			
		||||
        StringBuilder requestBody = null;
 | 
			
		||||
 | 
			
		||||
        // 设置请求头参数
 | 
			
		||||
@@ -56,30 +55,29 @@ public class sendMessage
 | 
			
		||||
        headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );
 | 
			
		||||
 | 
			
		||||
        // 遍历消息,将消息推送出去。
 | 
			
		||||
        for ( QWeatherDisasterWarningItem item : warningItems )
 | 
			
		||||
 | 
			
		||||
        // 拼接消息内容
 | 
			
		||||
        String title = warningItem.getTitle();
 | 
			
		||||
        String text = warningItem.getText();
 | 
			
		||||
        String color = warningLevel.keySet().contains( warningItem.getLevel() )
 | 
			
		||||
                ? warningLevel.get( warningItem.getLevel() )
 | 
			
		||||
                : "#000000";
 | 
			
		||||
        requestBody = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
        requestBody.append( "tplid=57&groupid=1&first=尊敬的#realname#,您好!&" );
 | 
			
		||||
        requestBody.append( "keyword1=" ).append( title ).append( "&" );
 | 
			
		||||
        requestBody.append( "keyword1color=" ).append( color ).append( "&" );
 | 
			
		||||
        requestBody.append( "keyword2=" ).append( text );
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 拼接消息内容
 | 
			
		||||
            String title = item.getTitle();
 | 
			
		||||
            String text = item.getText();
 | 
			
		||||
            String color = warningLevel.keySet().contains( item.getLevel() )
 | 
			
		||||
                    ? warningLevel.get( item.getLevel() )
 | 
			
		||||
                    : "#000000";
 | 
			
		||||
            requestBody = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
            requestBody.append( "tplid=57&groupid=1&first=尊敬的#realname#,您好!&" );
 | 
			
		||||
            requestBody.append( "keyword1=" ).append( title ).append( "&" );
 | 
			
		||||
            requestBody.append( "keyword1color=" ).append( color ).append( "&" );
 | 
			
		||||
            requestBody.append( "keyword2=" ).append( text );
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() );
 | 
			
		||||
            }
 | 
			
		||||
            catch ( MalformedURLException error )
 | 
			
		||||
            {
 | 
			
		||||
                error.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
            HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() );
 | 
			
		||||
        }
 | 
			
		||||
        catch ( MalformedURLException error )
 | 
			
		||||
        {
 | 
			
		||||
            error.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -197,6 +195,8 @@ public class sendMessage
 | 
			
		||||
            conn = DriverManager.getConnection( jdbcURL, userName, password );
 | 
			
		||||
            stmt = conn.prepareStatement( sql );
 | 
			
		||||
 | 
			
		||||
            conn.setAutoCommit( false );
 | 
			
		||||
 | 
			
		||||
            for ( QWeatherDisasterWarningItem warning : warnings.getWarning() )
 | 
			
		||||
            {
 | 
			
		||||
                java.sql.Timestamp pubTime =
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user