View Javadoc
1   package com.foxinmy.weixin4j.wxa.api;
2   
3   import java.util.Map;
4   import java.util.Properties;
5   
6   import com.foxinmy.weixin4j.exception.WeixinException;
7   import com.foxinmy.weixin4j.token.TokenManager;
8   
9   /**
10   * 发送订阅消息。
11   *
12   * <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html">发送订阅消息</a>
13   * @since 1.9
14   */
15  public class SubscribeMessageApi extends TokenManagerApi {
16  
17  	public SubscribeMessageApi(TokenManager tokenManager) {
18  		super(tokenManager, null);
19  	}
20  
21  	public SubscribeMessageApi(TokenManager tokenManager, Properties properties) {
22  		super(tokenManager, properties);
23  	}
24  	/**
25  	 * 发送订阅消息
26  	 *
27  	 * @param toUser 接收者(用户)的 openid。
28  	 * @param templateId 所需下发的订阅模板id
29  	 * @param page 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
30  	 * @param data 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
31  	 * @throws WeixinException indicates getting access token failed, or sending template message failed.
32  	 * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html">发送订阅消息</a>
33  	 */
34  	public void sendSubscribeMessage(
35  		String toUser,
36  		String templateId,
37  		String page,
38  		Map<String, String> data
39  	) throws WeixinException {
40  
41  		final SubscribeMessageParameter message = new SubscribeMessageParameter(
42  			toUser, templateId, page, data
43  		);
44  		WxaApiResult r = this.post("wxopen_subscribe_message_send", message, WxaApiResult.TYPE_REFERENCE);
45  		r.checkErrCode();
46  	}
47  
48  }