This commit is contained in:
2022-04-22 23:48:34 +08:00
parent 9c1f141a00
commit 1e8e58d3de

View File

@@ -2,7 +2,7 @@
* @Author: Kane * @Author: Kane
* @Date: 2022-04-22 10:53:49 * @Date: 2022-04-22 10:53:49
* @LastEditors: Kane * @LastEditors: Kane
* @LastEditTime: 2022-04-22 23:04:58 * @LastEditTime: 2022-04-22 23:48:28
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
* @Description: 用来推送公众号消息的程序库。 * @Description: 用来推送公众号消息的程序库。
* *
@@ -27,7 +27,7 @@ import com.cpic.xim.notify.disaster.*;
/** /**
* 推送微信公众号消息。 * 推送微信公众号消息。
* * @Description
* @author Kane * @author Kane
*/ */
public class sendMessage public class sendMessage
@@ -64,14 +64,14 @@ public class sendMessage
json = mapper.writeValueAsString( param ); json = mapper.writeValueAsString( param );
if ( json.isEmpty() ) if ( json.isEmpty())
{ {
} }
System.out.println( json ); System.out.println( json );
} }
catch ( JsonProcessingException error ) catch (JsonProcessingException error)
{ {
error.printStackTrace(); error.printStackTrace();
@@ -79,7 +79,7 @@ public class sendMessage
} }
// 推送数据 // 推送数据
URL url; URL url = null;
HttpURLConnection connection = null; HttpURLConnection connection = null;
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
@@ -107,14 +107,14 @@ public class sendMessage
String line = in.readLine(); String line = in.readLine();
while ( line != null ) while (line != null)
{ {
result.append( line ); result.append( line );
line = in.readLine(); line = in.readLine();
} }
} }
catch ( Exception error ) catch (Exception error)
{ {
error.printStackTrace(); error.printStackTrace();
} }
@@ -122,22 +122,22 @@ public class sendMessage
{ {
try try
{ {
if ( in != null ) if ( in != null)
{ {
in.close(); in.close();
} }
if ( out != null ) if ( out != null)
{ {
out.close(); out.close();
} }
if ( connection != null ) if ( connection != null)
{ {
connection.disconnect(); connection.disconnect();
} }
} }
catch ( Exception error ) catch (Exception error)
{ {
error.printStackTrace(); error.printStackTrace();
} }
@@ -147,7 +147,6 @@ public class sendMessage
/** /**
* 推送天气灾害预警!接口文档参考 彭奕洁 编写《消息发送接口调用文档》 * 推送天气灾害预警!接口文档参考 彭奕洁 编写《消息发送接口调用文档》
*
* @param officalAccountURL 产险厦门分公司公众号接口网址 * @param officalAccountURL 产险厦门分公司公众号接口网址
* @param warning 灾害警报对象 * @param warning 灾害警报对象
*/ */
@@ -164,7 +163,7 @@ public class sendMessage
headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" ); headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );
// 遍历消息,将消息推送出去。 // 遍历消息,将消息推送出去。
for ( QWeatherDisasterWarningItem item : warningItems ) for ( QWeatherDisasterWarningItem item : warningItems)
{ {
// 拼接消息内容 // 拼接消息内容
String title = item.getTitle(); String title = item.getTitle();
@@ -195,40 +194,40 @@ class WechatOfficalAccountMessageParameter
groupID = 1; groupID = 1;
} }
@JsonProperty("tplid") @JsonProperty( "tplid")
private int tplID; private int tplID;
@JsonProperty("groupid") @JsonProperty( "groupid")
private int groupID; private int groupID;
@JsonProperty("first") @JsonProperty( "first")
private String first; private String first;
@JsonProperty("keyword1") @JsonProperty( "keyword1")
private String keyword1; private String keyword1;
@JsonProperty("keyword1color") @JsonProperty( "keyword1color")
private String keyword1Color; private String keyword1Color;
@JsonProperty("keyword2") @JsonProperty( "keyword2")
private String keyword2; private String keyword2;
@JsonProperty("keyword2color") @JsonProperty( "keyword2color")
private String keyword2Color; private String keyword2Color;
@JsonProperty("remark") @JsonProperty( "remark")
private String remark; private String remark;
@JsonProperty("remarkcolor") @JsonProperty( "remarkcolor")
private String remarkColor; private String remarkColor;
@JsonProperty("url") @JsonProperty( "url")
private String url; private String url;
@JsonProperty("appid") @JsonProperty( "appid")
private String appid; private String appid;
@JsonProperty("pagepath") @JsonProperty( "pagepath")
private String pagePath; private String pagePath;
public int getTplID() public int getTplID()