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