Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.WxMaGetUserNotifyRequest;
import cn.binarywang.wx.miniapp.bean.WxMaGetUserNotifyResult;
import cn.binarywang.wx.miniapp.bean.WxMaServiceNotifyExtRequest;
import cn.binarywang.wx.miniapp.bean.WxMaServiceNotifyRequest;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import me.chanjar.weixin.common.bean.subscribemsg.CategoryData;
import me.chanjar.weixin.common.bean.subscribemsg.PubTemplateKeyword;
Expand Down Expand Up @@ -113,4 +117,44 @@ public interface WxMaSubscribeService {
*/
void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException;

/**
* <pre>
* 激活与更新服务卡片
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_setusernotify.html">激活与更新服务卡片</a>
* 接口url格式: POST https://api.weixin.qq.com/wxa/setusernotify?access_token=ACCESS_TOKEN
* </pre>
*
* @param request 请求参数
* @throws WxErrorException .
*/
void setUserNotify(WxMaServiceNotifyRequest request) throws WxErrorException;

/**
* <pre>
* 更新服务卡片扩展信息
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_setusernotifyext.html">更新服务卡片扩展信息</a>
* 接口url格式: POST https://api.weixin.qq.com/wxa/setusernotifyext?access_token=ACCESS_TOKEN
* </pre>
*
* @param request 请求参数
* @throws WxErrorException .
*/
void setUserNotifyExt(WxMaServiceNotifyExtRequest request) throws WxErrorException;

/**
* <pre>
* 查询服务卡片状态
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_getusernotify.html">查询服务卡片状态</a>
* 接口url格式: POST https://api.weixin.qq.com/wxa/getusernotify?access_token=ACCESS_TOKEN
* </pre>
*
* @param request 请求参数
* @return 服务卡片状态
* @throws WxErrorException .
*/
WxMaGetUserNotifyResult getUserNotify(WxMaGetUserNotifyRequest request) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.bean.WxMaGetUserNotifyRequest;
import cn.binarywang.wx.miniapp.bean.WxMaGetUserNotifyResult;
import cn.binarywang.wx.miniapp.bean.WxMaServiceNotifyExtRequest;
import cn.binarywang.wx.miniapp.bean.WxMaServiceNotifyRequest;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.subscribemsg.CategoryData;
Expand Down Expand Up @@ -89,4 +93,32 @@ public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErr
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}

@Override
public void setUserNotify(WxMaServiceNotifyRequest request) throws WxErrorException {
String responseContent = this.service.post(SERVICE_NOTIFY_SET_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}

@Override
public void setUserNotifyExt(WxMaServiceNotifyExtRequest request) throws WxErrorException {
String responseContent = this.service.post(SERVICE_NOTIFY_SET_EXT_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}

@Override
public WxMaGetUserNotifyResult getUserNotify(WxMaGetUserNotifyRequest request) throws WxErrorException {
String responseContent = this.service.post(SERVICE_NOTIFY_GET_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaGetUserNotifyResult.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cn.binarywang.wx.miniapp.bean;

import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 查询服务卡片状态请求.
*
* <p>接口文档:
* <a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_getusernotify.html">
* 查询服务卡片状态</a>
*
* @author GitHub Copilot
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaGetUserNotifyRequest implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 用户身份标识符.
* <pre>
* 参数:openid
* 是否必填:是
* </pre>
*/
@SerializedName("openid")
private String openid;

/**
* 动态更新令牌.
* <pre>
* 参数:notify_code
* 是否必填:是
* </pre>
*/
@SerializedName("notify_code")
private String notifyCode;

/**
* 卡片ID.
* <pre>
* 参数:notify_type
* 是否必填:是
* </pre>
*/
@SerializedName("notify_type")
private Integer notifyType;

/**
* 转为 JSON 字符串.
*
* @return JSON 字符串
*/
public String toJson() {
return WxMaGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cn.binarywang.wx.miniapp.bean;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
* 查询服务卡片状态响应.
*
* <p>接口文档:
* <a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_getusernotify.html">
* 查询服务卡片状态</a>
*
* @author GitHub Copilot
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxMaGetUserNotifyResult extends WxMaBaseResponse {
private static final long serialVersionUID = 1L;

/**
* 卡片状态信息.
*/
@SerializedName("notify_info")
private NotifyInfo notifyInfo;

/**
* 卡片状态详情.
*/
@Data
public static class NotifyInfo implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 卡片ID.
*/
@SerializedName("notify_type")
private Integer notifyType;

/**
* 上次有效推送的卡片状态与状态相关字段,没推送过为空字符串.
*/
@SerializedName("content_json")
private String contentJson;

/**
* code 状态:0 正常;1 有风险;2 异常;10 用户拒收本次code.
*/
@SerializedName("code_state")
private Integer codeState;

/**
* code 过期时间,秒级时间戳.
*/
@SerializedName("code_expire_time")
private Long codeExpireTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cn.binarywang.wx.miniapp.bean;

import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 更新服务卡片扩展信息请求.
*
* <p>接口文档:
* <a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_setusernotifyext.html">
* 更新服务卡片扩展信息</a>
*
* @author GitHub Copilot
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaServiceNotifyExtRequest implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 用户身份标识符.
* <pre>
* 参数:openid
* 是否必填:是
* 描述:用户身份标识符。
* 当使用微信支付订单号作为 code 时,需要与实际支付用户一致;
* 当通过前端获取 code 时,需要与点击 button 的用户一致。
* </pre>
*/
@SerializedName("openid")
private String openid;

/**
* 卡片ID.
* <pre>
* 参数:notify_type
* 是否必填:是
* 描述:卡片ID。
* </pre>
*/
@SerializedName("notify_type")
private Integer notifyType;

/**
* 动态更新令牌.
* <pre>
* 参数:notify_code
* 是否必填:是
* 描述:动态更新令牌。
* </pre>
*/
@SerializedName("notify_code")
private String notifyCode;

/**
* 扩展信息.
* <pre>
* 参数:ext_json
* 是否必填:是
* 描述:扩展信息,不同卡片的定义不同。
* </pre>
*/
@SerializedName("ext_json")
private String extJson;

/**
* 转为 JSON 字符串.
*
* @return JSON 字符串
*/
public String toJson() {
return WxMaGsonBuilder.create().toJson(this);
}
}
Loading