保存进度!
This commit is contained in:
parent
3dda8252f6
commit
d23826e056
@ -1,20 +0,0 @@
|
||||
|
||||
package com.cpic.xim.wechat.common;
|
||||
|
||||
public class PushMessage {
|
||||
|
||||
/**
|
||||
* 向公众号推送通知消息。接口文档参考 彭奕洁 编写《消息发送接口调用文档》
|
||||
* @param url 公众号接口网址。
|
||||
* @param title 通知的标题。
|
||||
* @param notifyType 通知类型。
|
||||
* @param notifyMessage 通知文本内容。
|
||||
*/
|
||||
public static void PushNotifyMessage( String url,
|
||||
String title,
|
||||
String notifyType,
|
||||
String notifyMessage )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
|
||||
package com.cpic.xim.wechat.officalAccount;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class PushMessage
|
||||
{
|
||||
|
||||
/**
|
||||
* 向公众号推送通知消息。接口文档参考 彭奕洁 编写《消息发送接口调用文档》
|
||||
*
|
||||
* @param wechatOfficalAccountURL 公众号接口网址。
|
||||
* @param title 通知的标题。
|
||||
* @param notifyType 通知类型。
|
||||
* @param notifyMessage 通知文本内容。
|
||||
*/
|
||||
public static void PushNotifyMessage( String wechatOfficalAccountURL,
|
||||
String title,
|
||||
String notifyType,
|
||||
String notifyMessage )
|
||||
|
||||
{
|
||||
WechatOfficalAccountMessageParameter param = new WechatOfficalAccountMessageParameter();
|
||||
|
||||
//param.setUrl( url );
|
||||
param.setFirst( title );
|
||||
param.setKeyword1( notifyType );
|
||||
param.setKeyword1Color( "#ff000000" );
|
||||
param.setKeyword2( notifyMessage );
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
try
|
||||
{
|
||||
String json = mapper.writeValueAsString( param );
|
||||
}
|
||||
catch ( JsonProcessingException error )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WechatOfficalAccountMessageParameter
|
||||
{
|
||||
|
||||
WechatOfficalAccountMessageParameter()
|
||||
{
|
||||
tplID = 57;
|
||||
groupID = 1;
|
||||
}
|
||||
|
||||
@JsonProperty("tplid")
|
||||
private int tplID;
|
||||
|
||||
@JsonProperty("groupid")
|
||||
private int groupID;
|
||||
|
||||
@JsonProperty("first")
|
||||
private String first;
|
||||
|
||||
@JsonProperty("keyword1")
|
||||
private String keyword1;
|
||||
|
||||
@JsonProperty("keyword1color")
|
||||
private String keyword1Color;
|
||||
|
||||
@JsonProperty("keyword2")
|
||||
private String keyword2;
|
||||
|
||||
@JsonProperty("keyword2color")
|
||||
private String keyword2Color;
|
||||
|
||||
@JsonProperty("remark")
|
||||
private String remark;
|
||||
|
||||
@JsonProperty("remarkcolor")
|
||||
private String remarkColor;
|
||||
|
||||
@JsonProperty("url")
|
||||
private String url;
|
||||
|
||||
@JsonProperty("appid")
|
||||
private String appid;
|
||||
|
||||
@JsonProperty("pagepath")
|
||||
private String pagePath;
|
||||
|
||||
public int getTplID()
|
||||
{
|
||||
return tplID;
|
||||
}
|
||||
|
||||
public void setTplID( int tplID )
|
||||
{
|
||||
this.tplID = tplID;
|
||||
}
|
||||
|
||||
public int getGroupID()
|
||||
{
|
||||
return groupID;
|
||||
}
|
||||
|
||||
public void setGroupID( int groupID )
|
||||
{
|
||||
this.groupID = groupID;
|
||||
}
|
||||
|
||||
public String getFirst()
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst( String first )
|
||||
{
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public String getKeyword1()
|
||||
{
|
||||
return keyword1;
|
||||
}
|
||||
|
||||
public void setKeyword1( String keyword1 )
|
||||
{
|
||||
this.keyword1 = keyword1;
|
||||
}
|
||||
|
||||
public String getKeyword1Color()
|
||||
{
|
||||
return keyword1Color;
|
||||
}
|
||||
|
||||
public void setKeyword1Color( String keyword1Color )
|
||||
{
|
||||
this.keyword1Color = keyword1Color;
|
||||
}
|
||||
|
||||
public String getKeyword2()
|
||||
{
|
||||
return keyword2;
|
||||
}
|
||||
|
||||
public void setKeyword2( String keyword2 )
|
||||
{
|
||||
this.keyword2 = keyword2;
|
||||
}
|
||||
|
||||
public String getKeyword2Color()
|
||||
{
|
||||
return keyword2Color;
|
||||
}
|
||||
|
||||
public void setKeyword2Color( String keyword2Color )
|
||||
{
|
||||
this.keyword2Color = keyword2Color;
|
||||
}
|
||||
|
||||
public String getRemark()
|
||||
{
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark( String remark )
|
||||
{
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getRemarkColor()
|
||||
{
|
||||
return remarkColor;
|
||||
}
|
||||
|
||||
public void setRemarkColor( String remarkColor )
|
||||
{
|
||||
this.remarkColor = remarkColor;
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl( String url )
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getAppid()
|
||||
{
|
||||
return appid;
|
||||
}
|
||||
|
||||
public void setAppid( String appid )
|
||||
{
|
||||
this.appid = appid;
|
||||
}
|
||||
|
||||
public String getPagePath()
|
||||
{
|
||||
return pagePath;
|
||||
}
|
||||
|
||||
public void setPagePath( String pagePath )
|
||||
{
|
||||
this.pagePath = pagePath;
|
||||
}
|
||||
}
|
70
文档/example.java
Normal file
70
文档/example.java
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-18 11:37:33
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-04-18 11:41:09
|
||||
* @FilePath: \undefinedd:\develop\产险厦门分公司项目\天气灾害预警\文档\example.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
|
||||
public class HttpUtils {
|
||||
public static String sendPostWithJson(String url, String jsonStr, HashMap<String,String> headers) {
|
||||
// 返回的结果
|
||||
String jsonResult = "";
|
||||
|
||||
try {
|
||||
HttpClient client = new HttpClient();
|
||||
// 连接超时
|
||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(3*1000);
|
||||
// 读取数据超时
|
||||
client.getHttpConnectionManager().getParams().setSoTimeout(3*60*1000);
|
||||
client.getParams().setContentCharset("UTF-8");
|
||||
|
||||
PostMethod postMethod = new PostMethod(url);
|
||||
|
||||
postMethod.setRequestHeader("content-type", headers.get("content-type"));
|
||||
|
||||
// 非空
|
||||
if (null != jsonStr && !"".equals(jsonStr))
|
||||
{
|
||||
StringRequestEntity requestEntity = new StringRequestEntity(jsonStr, headers.get("content-type"), "UTF-8");
|
||||
postMethod.setRequestEntity(requestEntity);
|
||||
}
|
||||
|
||||
int status = client.executeMethod(postMethod);
|
||||
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
jsonResult = postMethod.getResponseBodyAsString();
|
||||
} else {
|
||||
throw new RuntimeException("接口连接失败!");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("接口连接失败!");
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String requestUrl = "http://localhost:8070/test/rz/server/rzxx/at_VaildToken.do";
|
||||
String jsonStr = "{\"name\":\"张三\"}";
|
||||
|
||||
HashMap<String, String> headers = new HashMap<>(3);
|
||||
headers.put("content-type", "application/json");
|
||||
|
||||
// 发送post请求
|
||||
String resultData = HttpUtils.sendPostWithJson(requestUrl, jsonStr,headers);
|
||||
|
||||
// 并接收返回结果
|
||||
System.out.println(resultData);
|
||||
}
|
||||
|
||||
|
||||
}
|
BIN
文档/公众号接口/~$发送接口调用文档.docx
Normal file
BIN
文档/公众号接口/~$发送接口调用文档.docx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user