保存进度!
This commit is contained in:
		@@ -22,7 +22,7 @@
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
 | 
			
		||||
    <file url="file://$PROJECT_DIR$/src/main/java/test/com/cpic/xim/wechat/officalAccount/PushMessageTest.java" charset="GBK" />
 | 
			
		||||
    <file url="file://$PROJECT_DIR$/src/test/java/com/cpic/xim/wechat/officalAccount/PushMessageTest.java" charset="UTF-8" />
 | 
			
		||||
    <file url="file://$PROJECT_DIR$/src/test/java/com/cpic/xim/wechat/officalAccount/sendMessageTest.java" charset="UTF-8" />
 | 
			
		||||
    <file url="PROJECT" charset="UTF-8" />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="ExportToHTMLSettings">
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,6 @@ import java.util.zip.GZIPInputStream;
 | 
			
		||||
 */
 | 
			
		||||
public class WeatherDisasterWarningGrabber
 | 
			
		||||
{
 | 
			
		||||
    private final static String QUERY_URL = "https://devapi.qweather.com/v7/warning/now?";
 | 
			
		||||
    private final static String USER_KEY  = "fe9fa8eeeb6f4301a92541eed565dd15";
 | 
			
		||||
 | 
			
		||||
    /***
 | 
			
		||||
     * 从和风天气获取天气警报json字符串
 | 
			
		||||
     * @param cityCode 城市或区域代码
 | 
			
		||||
 
 | 
			
		||||
@@ -8,12 +8,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
import java.net.MalformedURLException;
 | 
			
		||||
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.net.HttpURLConnection;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public class PushMessage
 | 
			
		||||
public class sendMessage
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -24,7 +25,7 @@ public class PushMessage
 | 
			
		||||
     * @param notifyType              通知类型。
 | 
			
		||||
     * @param notifyMessage           通知文本内容。
 | 
			
		||||
     */
 | 
			
		||||
    public static void PushNotifyMessage( String wechatOfficalAccountURL,
 | 
			
		||||
    public static void sendNotifyMessage( String wechatOfficalAccountURL,
 | 
			
		||||
                                          String title,
 | 
			
		||||
                                          String notifyType,
 | 
			
		||||
                                          String notifyMessage )
 | 
			
		||||
@@ -39,8 +40,8 @@ public class PushMessage
 | 
			
		||||
        param.setKeyword2( notifyMessage );
 | 
			
		||||
 | 
			
		||||
        //转换成json
 | 
			
		||||
        ObjectMapper mapper = null;
 | 
			
		||||
        String       json   = null;
 | 
			
		||||
        ObjectMapper mapper;
 | 
			
		||||
        String       json = null;
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
@@ -49,18 +50,25 @@ public class PushMessage
 | 
			
		||||
 | 
			
		||||
            json = mapper.writeValueAsString( param );
 | 
			
		||||
 | 
			
		||||
            if ( json.isEmpty() )
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            System.out.println( json );
 | 
			
		||||
        }
 | 
			
		||||
        catch ( JsonProcessingException error )
 | 
			
		||||
        {
 | 
			
		||||
            error.printStackTrace();
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //推送数据
 | 
			
		||||
        URL               url        = null;
 | 
			
		||||
        URL               url;
 | 
			
		||||
        HttpURLConnection connection = null;
 | 
			
		||||
 | 
			
		||||
        StringBuffer       result = new StringBuffer();
 | 
			
		||||
        StringBuilder      result = new StringBuilder();
 | 
			
		||||
        OutputStreamWriter out    = null;
 | 
			
		||||
        BufferedReader     in     = null;
 | 
			
		||||
 | 
			
		||||
@@ -77,7 +85,7 @@ public class PushMessage
 | 
			
		||||
            connection.setDoOutput( true );
 | 
			
		||||
            connection.connect();
 | 
			
		||||
 | 
			
		||||
            out = new OutputStreamWriter( connection.getOutputStream(), "UTF-8" );
 | 
			
		||||
            out = new OutputStreamWriter( connection.getOutputStream(), StandardCharsets.UTF_8 );
 | 
			
		||||
            out.write( json );
 | 
			
		||||
            out.flush();
 | 
			
		||||
 | 
			
		||||
@@ -1,11 +1,10 @@
 | 
			
		||||
package com.cpic.xim.wechat.officalAccount;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.JsonProcessingException;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.*;
 | 
			
		||||
 | 
			
		||||
public class PushMessageTest
 | 
			
		||||
public class sendMessageTest
 | 
			
		||||
{
 | 
			
		||||
    @Test
 | 
			
		||||
    public void pushNotifyMessage()
 | 
			
		||||
@@ -14,7 +13,7 @@ public class PushMessageTest
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            PushMessage.PushNotifyMessage( url, "警报", "警报标题", "警报内容!" );
 | 
			
		||||
            sendMessage.sendNotifyMessage( url, "警报", "警报标题", "警报内容!" );
 | 
			
		||||
        }
 | 
			
		||||
        catch ( Exception error  )
 | 
			
		||||
        {
 | 
			
		||||
		Reference in New Issue
	
	Block a user