commit
15819c7a43
@ -15,6 +15,7 @@ import com.foxinmy.weixin4j.wxa.api.QrCodeApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.SecCheckApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.TemplateApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.TemplateMessageApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.SubscribeMessageApi;
|
||||
|
||||
/**
|
||||
* The facade of WeChat Mini Program APIs.
|
||||
@ -29,6 +30,7 @@ public class WeixinAppFacade {
|
||||
private final TemplateMessageApi templateMessageApi;
|
||||
private final CustomMessageApi customMessageApi;
|
||||
private final SecCheckApi secCheckApi;
|
||||
private final SubscribeMessageApi subscribeMessageApi;
|
||||
|
||||
/**
|
||||
* Constructs {@link WeixinAppFacade} using {@link FileCacheStorager}.
|
||||
@ -111,6 +113,7 @@ public class WeixinAppFacade {
|
||||
this.templateMessageApi = new TemplateMessageApi(tokenManager, properties);
|
||||
this.customMessageApi = new CustomMessageApi(tokenManager, properties);
|
||||
this.secCheckApi = new SecCheckApi(tokenManager, properties);
|
||||
this.subscribeMessageApi = new SubscribeMessageApi(tokenManager, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,6 +152,15 @@ public class WeixinAppFacade {
|
||||
return templateMessageApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订阅消息相关的 API。
|
||||
*
|
||||
* @return 模板消息相关的 API。
|
||||
*/
|
||||
public SubscribeMessageApi getSubscribeMessageApi() {
|
||||
return subscribeMessageApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服消息相关的 API。
|
||||
*
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class SubscribeMessageApi extends TokenManagerApi {
|
||||
|
||||
public SubscribeMessageApi(TokenManager tokenManager) {
|
||||
super(tokenManager, null);
|
||||
}
|
||||
|
||||
public SubscribeMessageApi(TokenManager tokenManager, Properties properties) {
|
||||
super(tokenManager, properties);
|
||||
}
|
||||
/**
|
||||
* 发送订阅消息
|
||||
*
|
||||
* @param toUser 接收者(用户)的 openid。
|
||||
* @param templateId 所需下发的订阅模板id
|
||||
* @param page 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
|
||||
* @param data 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
|
||||
* @throws WeixinException indicates getting access token failed, or sending template message failed.
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html">发送订阅消息</a>
|
||||
*/
|
||||
public void sendSubscribeMessage(
|
||||
String toUser,
|
||||
String templateId,
|
||||
String page,
|
||||
Map<String, String> data
|
||||
) throws WeixinException {
|
||||
|
||||
final SubscribeMessageParameter message = new SubscribeMessageParameter(
|
||||
toUser, templateId, page, data
|
||||
);
|
||||
WxaApiResult r = this.post("wxopen_subscribe_message_send", message, WxaApiResult.TYPE_REFERENCE);
|
||||
r.checkErrCode();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class SubscribeMessageParameter {
|
||||
|
||||
private static final long serialVersionUID = 2018052601L;
|
||||
|
||||
private String toUser;
|
||||
private String templateId;
|
||||
private String page;
|
||||
private Map<String, SubscribeMessageData> data;
|
||||
|
||||
public SubscribeMessageParameter() {
|
||||
|
||||
}
|
||||
|
||||
public SubscribeMessageParameter(
|
||||
String toUser,
|
||||
String templateId,
|
||||
String page,
|
||||
Map<String, String> data
|
||||
) {
|
||||
this.toUser = toUser;
|
||||
this.templateId = templateId;
|
||||
this.page = page;
|
||||
if (data != null) {
|
||||
this.data = new HashMap<String, SubscribeMessageData>(data.size());
|
||||
for (Map.Entry<String, String> entry : data.entrySet()) {
|
||||
this.data.put(entry.getKey(), new SubscribeMessageData(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JSONField(name = "touser")
|
||||
public String getToUser() {
|
||||
return toUser;
|
||||
}
|
||||
|
||||
public void setToUser(String toUser) {
|
||||
this.toUser = toUser;
|
||||
}
|
||||
|
||||
@JSONField(name = "template_id")
|
||||
public String getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
public void setTemplateId(String templateId) {
|
||||
this.templateId = templateId;
|
||||
}
|
||||
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(String page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Map<String, SubscribeMessageData> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Map<String, SubscribeMessageData> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SubscribeMessageData
|
||||
*/
|
||||
public static class SubscribeMessageData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2018052601L;
|
||||
|
||||
private String value;
|
||||
|
||||
public SubscribeMessageData() {
|
||||
|
||||
}
|
||||
|
||||
public SubscribeMessageData(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package com.foxinmy.weixin4j.wxa.model.subscribemessage;
|
||||
|
||||
/**
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
|
||||
*/
|
||||
public enum ParameterType {
|
||||
|
||||
/**
|
||||
* 20个以内字符 可汉字、数字、字母或符号组合
|
||||
* 可汉字、数字、字母或符号组合
|
||||
*/
|
||||
THING("thing"),
|
||||
|
||||
/**
|
||||
* 24小时制时间格式(支持+年月日)
|
||||
* 例如:15:01,或:2019年10月1日 15:01
|
||||
*/
|
||||
TIME("time"),
|
||||
|
||||
/**
|
||||
* 年月日格式(支持+24小时制时间)
|
||||
* 例如:2019年10月1日,或:2019年10月1日 15:01
|
||||
*/
|
||||
DATE("date"),
|
||||
|
||||
/**
|
||||
* 10个以内纯汉字或20个以内纯字母或符号
|
||||
* 中文名10个汉字内;纯英文名20个字母内;中文和字母混合按中文名算,10个字内
|
||||
*/
|
||||
NAME("name"),
|
||||
|
||||
/**
|
||||
* 32位以内数字
|
||||
* 只能数字,可带小数
|
||||
*/
|
||||
NUMBER("number"),
|
||||
|
||||
/**
|
||||
* 32位以内字母
|
||||
* 只能字母
|
||||
*/
|
||||
LETTER("letter"),
|
||||
|
||||
/**
|
||||
* 5位以内符号
|
||||
* 只能符号
|
||||
*/
|
||||
SYMBOL("symbol"),
|
||||
|
||||
/**
|
||||
* 5个以内汉字
|
||||
* 5个以内纯汉字,例如:配送中
|
||||
*/
|
||||
PHRASE("phrase"),
|
||||
|
||||
/**
|
||||
* 1个币种符号+10位以内纯数字,可带小数,结尾可带“元”
|
||||
* 可带小数
|
||||
*/
|
||||
AMOUNT("amount"),
|
||||
|
||||
/**
|
||||
* 8位以内,第一位与最后一位可为汉字,其余为字母或数字
|
||||
* 车牌号码:粤A8Z888挂
|
||||
*/
|
||||
CAR_NUMBER("car_number"),
|
||||
|
||||
/**
|
||||
* 17位以内,数字、符号
|
||||
* 电话号码,例:+86-0766-66888866
|
||||
*/
|
||||
PHONE_NUMBER("phone_number"),
|
||||
|
||||
/**
|
||||
* 32位以内数字、字母或符号
|
||||
* 可数字、字母或符号组合
|
||||
*/
|
||||
CHARACTER_STRING("character_string");
|
||||
|
||||
private final String value;
|
||||
|
||||
ParameterType(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Models for {@link com.foxinmy.weixin4j.wxa.api.TemplateApi}.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
package com.foxinmy.weixin4j.wxa.model.subscribemessage;
|
||||
@ -38,6 +38,8 @@ wxopen_template_del={api_cgi_url}/wxopen/template/del?access_token=%s
|
||||
# \u53d1\u9001\u6a21\u7248\u6d88\u606f
|
||||
wxopen_template_message_send={api_cgi_url}/message/wxopen/template/send?access_token=%s
|
||||
|
||||
# \u53d1\u9001\u8ba2\u9605\u6d88\u606f
|
||||
wxopen_subscribe_message_send={api_cgi_url}/message/subscribe/send?access_token=%s
|
||||
|
||||
# \u53d1\u9001\u5ba2\u670d\u6d88\u606f
|
||||
message_custom_send={api_cgi_url}/message/custom/send?access_token=%s
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user