保存进度!

This commit is contained in:
Kane Wang 2022-04-22 11:51:33 +08:00
parent 9857451f05
commit 16c54998de
2 changed files with 52 additions and 7 deletions

View File

@ -2,7 +2,7 @@
* @Author: Kane * @Author: Kane
* @Date: 2022-04-22 09:54:05 * @Date: 2022-04-22 09:54:05
* @LastEditors: Kane * @LastEditors: Kane
* @LastEditTime: 2022-04-22 10:46:26 * @LastEditTime: 2022-04-22 11:51:02
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\httpUtil\HttpUtils.java * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\httpUtil\HttpUtils.java
* @Description: http相关的工具类 * @Description: http相关的工具类
* Copyright (c) ${2022} by Kane, All Rights Reserved. * Copyright (c) ${2022} by Kane, All Rights Reserved.
@ -10,8 +10,10 @@
package com.cpic.xim.httpUtil; package com.cpic.xim.httpUtil;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.net.URL; import java.net.URL;
import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -23,23 +25,45 @@ public class HttpUtils
{ {
/** /**
* *
* @param url * @param url 访问的链接字符串
* @param headers * @param headers 请求头部参数集合
* @param params * @param params 请求体字符串
*/ */
public void postHttpRequest( String url, Map<String, String> headers, public static void postHttpRequest( String url, HashMap<String, String> headers, String param )
Map<String, String> params ) throws MalformedURLException throws MalformedURLException
{ {
URL httpURL = null; URL httpURL = null;
HttpURLConnection conn = null;
try try
{ {
// 获取connection
httpURL = new URL( url ); httpURL = new URL( url );
conn = (HttpURLConnection) httpURL.openConnection();
// 设置请求方式
conn.setRequestMethod( "POST" );
// 设置请求头参数
for ( HashMap.Entry<String, String> head : headers.entrySet())
{
String key = head.getKey();
conn.setRequestProperty( head.getKey(), head.getValue() );
}
// 设置请求体
} }
catch (MalformedURLException error) catch (MalformedURLException error)
{ {
} }
catch (IOException error)
{
}
} }
} }

View File

@ -1,8 +1,20 @@
/*
* @Author: Kane
* @Date: 2022-04-22 10:53:49
* @LastEditors: Kane
* @LastEditTime: 2022-04-22 11:41:52
* @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
package com.cpic.xim.wechat.officalAccount; package com.cpic.xim.wechat.officalAccount;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import com.cpic.xim.httpUtil.*;
import java.util.*;
public class sendMessageTest public class sendMessageTest
{ {
@ -14,7 +26,7 @@ public class sendMessageTest
{ {
try try
{ {
sendMessage.postNotifyMessageJSON( url, "警报", "警报标题", "警报内容!" ); // sendMessage.postNotifyMessageJSON( url, "警报", "警报标题", "警报内容!" );
} }
catch (Exception error) catch (Exception error)
{ {
@ -25,8 +37,17 @@ public class sendMessageTest
@Test @Test
public void postNotifyMessage() public void postNotifyMessage()
{ {
HashMap<String, String> headers = new HashMap<String, String>();
String param = "tplid : 57," + "groupid : 1," + "first : \"亲爱的#realname#,您好!\","
+ "keyword1 : \"厦门发布暴雨红色预警\"," + "keyword1color : \"#ff0000\","
+ "keyword2 : \"厦门市气象台**年**月**日发布暴雨红色预警信号\"";
headers.put( "accept", "*/*" );
headers.put( "Connection", "Keep-Alive" );
try try
{ {
HttpUtils.postHttpRequest( url, headers, param );
} }
catch (Exception error) catch (Exception error)
{ {