完成基本功能,准备加入log4j。
This commit is contained in:
		@@ -7,6 +7,10 @@
 | 
			
		||||
        {
 | 
			
		||||
            "city_name": "厦门",
 | 
			
		||||
            "city_code": "101230201"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "city_name": "东山",
 | 
			
		||||
            "city_code": "101230608"
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "notify_stuffs": [
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,13 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-04-22 16:18:48
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\AppMain.java
 | 
			
		||||
 * @Description: 和风天气预警推送厦门太保公众号主程序!
 | 
			
		||||
 * 
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
			
		||||
 */
 | 
			
		||||
import com.cpic.xim.config.City;
 | 
			
		||||
import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
 | 
			
		||||
import com.cpic.xim.notify.disaster.WeatherDisasterWarningGrabber;
 | 
			
		||||
@@ -47,7 +55,7 @@ public class AppMain
 | 
			
		||||
                // 判断是否有警报
 | 
			
		||||
                if ( warning.getWarning().isEmpty() == true)
 | 
			
		||||
                {
 | 
			
		||||
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (IOException error)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,18 +2,19 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 09:54:05
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-04-22 11:51:02
 | 
			
		||||
 * @LastEditTime: 2022-04-22 16:18:17
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\httpUtil\HttpUtils.java
 | 
			
		||||
 * @Description: http相关的工具类。
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.cpic.xim.httpUtil;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStreamReader;
 | 
			
		||||
import java.io.OutputStreamWriter;
 | 
			
		||||
import java.net.HttpURLConnection;
 | 
			
		||||
import java.net.MalformedURLException;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
@@ -24,16 +25,19 @@ import java.nio.charset.StandardCharsets;
 | 
			
		||||
public class HttpUtils
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * 以POST方式发送http请求!
 | 
			
		||||
     * @param url 访问的链接字符串
 | 
			
		||||
     * @param headers 请求头部参数集合
 | 
			
		||||
     * @param params 请求体字符串
 | 
			
		||||
     */
 | 
			
		||||
    public static void postHttpRequest( String url, HashMap<String, String> headers, String param )
 | 
			
		||||
            throws MalformedURLException
 | 
			
		||||
    public static String postHttpRequest( String url, HashMap<String, String> headers,
 | 
			
		||||
            String param ) throws MalformedURLException
 | 
			
		||||
    {
 | 
			
		||||
        URL httpURL = null;
 | 
			
		||||
        HttpURLConnection conn = null;
 | 
			
		||||
        OutputStreamWriter out = null;
 | 
			
		||||
        BufferedReader in = null;
 | 
			
		||||
        StringBuilder result = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
@@ -52,18 +56,57 @@ public class HttpUtils
 | 
			
		||||
                conn.setRequestProperty( head.getKey(), head.getValue() );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 设置请求体
 | 
			
		||||
            // 连接
 | 
			
		||||
            conn.setDoInput( true );
 | 
			
		||||
            conn.setDoOutput( true );
 | 
			
		||||
            conn.connect();
 | 
			
		||||
 | 
			
		||||
            // 输出请求
 | 
			
		||||
            out = new OutputStreamWriter( conn.getOutputStream(), StandardCharsets.UTF_8 );
 | 
			
		||||
            out.write( param );
 | 
			
		||||
            out.flush();
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        catch (MalformedURLException error)
 | 
			
		||||
        {
 | 
			
		||||
            // 读取返回值。
 | 
			
		||||
            in = new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
 | 
			
		||||
 | 
			
		||||
            String line = in.readLine();
 | 
			
		||||
 | 
			
		||||
            while (line != null)
 | 
			
		||||
            {
 | 
			
		||||
                result.append( line );
 | 
			
		||||
 | 
			
		||||
                line = in.readLine();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (IOException error)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        finally
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                if ( out != null)
 | 
			
		||||
                {
 | 
			
		||||
                    out.close();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if ( in != null)
 | 
			
		||||
                {
 | 
			
		||||
                    in.close();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if ( conn != null)
 | 
			
		||||
                {
 | 
			
		||||
                    conn.disconnect();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception error)
 | 
			
		||||
            {
 | 
			
		||||
                error.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return result.toString();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,13 @@
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-04-22 16:22:12
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
 | 
			
		||||
 * @Description: 用来推送公众号消息的程序库。
 | 
			
		||||
 * 
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
			
		||||
 */
 | 
			
		||||
package com.cpic.xim.wechat.officalAccount;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonInclude;
 | 
			
		||||
@@ -20,7 +29,6 @@ import java.util.Map;
 | 
			
		||||
 */
 | 
			
		||||
public class sendMessage
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 向公众号推送通知消息。接口文档参考 彭奕洁 编写《消息发送接口调用文档》
 | 
			
		||||
     *
 | 
			
		||||
@@ -31,7 +39,6 @@ public class sendMessage
 | 
			
		||||
     */
 | 
			
		||||
    public static void postNotifyMessageJSON( String wechatOfficalAccountURL, String title,
 | 
			
		||||
            String notifyType, String notifyMessage )
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
        // 设置推送内容
 | 
			
		||||
        WechatOfficalAccountMessageParameter param = new WechatOfficalAccountMessageParameter();
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-04-22 11:41:52
 | 
			
		||||
 * @LastEditTime: 2022-04-22 16:02:05
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
 | 
			
		||||
 * @Description: 
 | 
			
		||||
 * 
 | 
			
		||||
@@ -38,12 +38,13 @@ public class sendMessageTest
 | 
			
		||||
    public void postNotifyMessage()
 | 
			
		||||
    {
 | 
			
		||||
        HashMap<String, String> headers = new HashMap<String, String>();
 | 
			
		||||
        String param = "tplid : 57," + "groupid : 1," + "first : \"亲爱的#realname#,您好!\","
 | 
			
		||||
                + "keyword1 : \"厦门发布暴雨红色预警\"," + "keyword1color : \"#ff0000\","
 | 
			
		||||
                + "keyword2 : \"厦门市气象台**年**月**日发布暴雨红色预警信号\"";
 | 
			
		||||
        String param = "tplid=57&" + "groupid=1&" + "first=亲爱的#realname#,您好!&"
 | 
			
		||||
                + "keyword1=东山县气象台发布大雾黄色预警[Ⅲ级/较重]&" + "keyword1color=#ffff00&"
 | 
			
		||||
                + "keyword2=东山县气象台2022年04月22日06时12分发布大雾黄色预警信号:预计未来12小时内,我县、闽南渔场和台湾浅滩渔场将出现能见度小于500米的雾。请注意防范!";
 | 
			
		||||
 | 
			
		||||
        headers.put( "accept", "*/*" );
 | 
			
		||||
        headers.put( "Connection", "Keep-Alive" );
 | 
			
		||||
        // headers.put( "accept", "*/*" );
 | 
			
		||||
        // headers.put( "Connection", "Keep-Alive" );
 | 
			
		||||
        headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
@@ -52,5 +53,6 @@ public class sendMessageTest
 | 
			
		||||
        catch (Exception error)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user