Skip to content

Commit 93229e2

Browse files
authored
feat: 新增小程序URL Link二维码快速跳转规则管理服务与模型
1 parent 604dac3 commit 93229e2

9 files changed

Lines changed: 374 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cn.binarywang.wx.miniapp.api;
2+
3+
import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRule;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
6+
import java.util.List;
7+
8+
/**
9+
* 小程序 URL Link 二维码快速跳转规则管理服务。
10+
*/
11+
public interface WxMaQrcodeJumpService {
12+
13+
/**
14+
* 添加二维码快速跳转规则。
15+
*
16+
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/qr-code-quickly-jump.html
17+
*
18+
* @param rule 规则
19+
* @return 结果(errmsg/errcode)
20+
*/
21+
String addRule(WxMaQrcodeJumpRule rule) throws WxErrorException;
22+
23+
/**
24+
* 获取二维码快速跳转规则。
25+
*
26+
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/get-qr-code-jump-rule.html
27+
*
28+
* @param isDefault 是否查询默认规则
29+
* @param prefix 路径前缀(最长 32 个字符)
30+
* @return 二维码规则列表
31+
*/
32+
List<WxMaQrcodeJumpRule> getRules(Boolean isDefault, String prefix) throws WxErrorException;
33+
34+
/**
35+
* 分页获取二维码快速跳转规则列表。
36+
*
37+
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/get-qr-code-jump-rule-list.html
38+
*
39+
* @param getType 1:查询前缀匹配的规则;2:查询默认规则
40+
* @param pageNum 页码,从 1 开始
41+
* @param pageSize 每页条数,最多 20
42+
* @return 二维码规则列表
43+
*/
44+
List<WxMaQrcodeJumpRule> getRuleList(Integer getType, Integer pageNum, Integer pageSize) throws WxErrorException;
45+
46+
/**
47+
* 删除二维码快速跳转规则。
48+
*
49+
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/delete-qr-code-jump-rule.html
50+
*
51+
* @param prefix 路径前缀
52+
* @return 结果(errmsg/errcode)
53+
*/
54+
String deleteRule(String prefix) throws WxErrorException;
55+
}
56+

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,15 @@ WxMaApiResponse execute(
472472
*/
473473
WxMaLinkService getLinkService();
474474

475+
/**
476+
* 获取 URL Link 二维码快速跳转规则管理服务对象。
477+
*
478+
* 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/qr-code-quickly-jump.html
479+
*
480+
* @return 二维码快速跳转规则管理服务对象WxMaQrcodeJumpService
481+
*/
482+
WxMaQrcodeJumpService getQrcodeJumpService();
483+
475484
/**
476485
* 获取电子发票报销方服务接口服务对象。
477486
*

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
140140
new WxMaShopAfterSaleServiceImpl(this);
141141
private final WxMaShopDeliveryService shopDeliveryService = new WxMaShopDeliveryServiceImpl(this);
142142
private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this);
143+
private final WxMaQrcodeJumpService qrcodeJumpService = new WxMaQrcodeJumpServiceImpl(this);
143144
private final WxMaReimburseInvoiceService reimburseInvoiceService =
144145
new WxMaReimburseInvoiceServiceImpl(this);
145146
private final WxMaDeviceSubscribeService deviceSubscribeService =
@@ -788,6 +789,11 @@ public WxMaLinkService getLinkService() {
788789
return this.linkService;
789790
}
790791

792+
@Override
793+
public WxMaQrcodeJumpService getQrcodeJumpService() {
794+
return this.qrcodeJumpService;
795+
}
796+
791797
@Override
792798
public WxMaReimburseInvoiceService getReimburseInvoiceService() {
793799
return this.reimburseInvoiceService;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaQrcodeJumpService;
4+
import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRule;
5+
import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRuleListResponse;
6+
import com.google.gson.JsonObject;
7+
import lombok.RequiredArgsConstructor;
8+
import me.chanjar.weixin.common.error.WxErrorException;
9+
10+
import java.util.Collections;
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.QrcodeJump.*;
16+
import static me.chanjar.weixin.common.util.json.WxGsonBuilder.create;
17+
18+
/**
19+
* {@link WxMaQrcodeJumpService} 实现。
20+
*/
21+
@RequiredArgsConstructor
22+
public class WxMaQrcodeJumpServiceImpl implements WxMaQrcodeJumpService {
23+
private final BaseWxMaServiceImpl wxMaService;
24+
25+
@Override
26+
public String addRule(WxMaQrcodeJumpRule rule) throws WxErrorException {
27+
return this.wxMaService.post(QRCODE_JUMP_ADD, create().toJson(rule));
28+
}
29+
30+
@Override
31+
public List<WxMaQrcodeJumpRule> getRules(Boolean isDefault, String prefix) throws WxErrorException {
32+
final JsonObject request = new JsonObject();
33+
if (isDefault != null) {
34+
request.addProperty("is_default", isDefault);
35+
}
36+
if (prefix != null) {
37+
request.addProperty("prefix", prefix);
38+
}
39+
40+
String response = this.wxMaService.post(QRCODE_JUMP_GET, request.toString());
41+
WxMaQrcodeJumpRuleListResponse result = create().fromJson(response, WxMaQrcodeJumpRuleListResponse.class);
42+
if (result == null || result.getRuleList() == null || result.getRuleList().isEmpty()) {
43+
return Collections.emptyList();
44+
}
45+
return result.getRuleList();
46+
}
47+
48+
@Override
49+
public List<WxMaQrcodeJumpRule> getRuleList(Integer getType, Integer pageNum, Integer pageSize) throws WxErrorException {
50+
final JsonObject request = new JsonObject();
51+
if (getType != null) {
52+
request.addProperty("get_type", getType);
53+
}
54+
if (pageNum != null) {
55+
request.addProperty("page_num", pageNum);
56+
}
57+
if (pageSize != null) {
58+
request.addProperty("page_size", pageSize);
59+
}
60+
61+
String response = this.wxMaService.post(QRCODE_JUMP_GET_LIST, request.toString());
62+
WxMaQrcodeJumpRuleListResponse result = create().fromJson(response, WxMaQrcodeJumpRuleListResponse.class);
63+
if (result == null || result.getRuleList() == null || result.getRuleList().isEmpty()) {
64+
return Collections.emptyList();
65+
}
66+
return result.getRuleList();
67+
}
68+
69+
@Override
70+
public String deleteRule(String prefix) throws WxErrorException {
71+
final Map<String, String> request = new HashMap<>(1);
72+
request.put("prefix", prefix);
73+
return this.wxMaService.post(QRCODE_JUMP_DELETE, create().toJson(request));
74+
}
75+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cn.binarywang.wx.miniapp.bean.qrcode;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* URL Link 二维码快速跳转规则。
14+
*/
15+
@Data
16+
@Builder
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
public class WxMaQrcodeJumpRule implements Serializable {
20+
private static final long serialVersionUID = -3450269467817402123L;
21+
22+
/**
23+
* 跳转链接规则前缀,最多 32 个字符。
24+
*/
25+
@SerializedName("prefix")
26+
private String prefix;
27+
28+
/**
29+
* 是否支持子路径匹配。
30+
*/
31+
@SerializedName("permit_sub_rule")
32+
private Boolean permitSubRule;
33+
34+
/**
35+
* 跳转版本,1:正式版;2:测试版;3:体验版。
36+
*/
37+
@SerializedName("open_version")
38+
private Integer openVersion;
39+
40+
/**
41+
* 正式版跳转页面。
42+
*/
43+
@SerializedName("path")
44+
private String path;
45+
46+
/**
47+
* 测试版/体验版可跳转小程序信息。
48+
*/
49+
@SerializedName("debug_wxa_info")
50+
private List<WxMaQrcodeJumpWxaItem> debugWxaInfo;
51+
52+
/**
53+
* 二维码规则是否失效。
54+
*/
55+
@SerializedName("is_expire")
56+
private Boolean expire;
57+
}
58+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cn.binarywang.wx.miniapp.bean.qrcode;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* URL Link 二维码快速跳转规则列表返回值。
14+
*/
15+
@Data
16+
@Builder
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
public class WxMaQrcodeJumpRuleListResponse implements Serializable {
20+
private static final long serialVersionUID = 6706970228943946110L;
21+
22+
/**
23+
* 规则列表。
24+
*/
25+
@SerializedName("rule_list")
26+
private List<WxMaQrcodeJumpRule> ruleList;
27+
}
28+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cn.binarywang.wx.miniapp.bean.qrcode;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.io.Serializable;
10+
11+
/**
12+
* URL Link 跳转规则中的小程序信息。
13+
*/
14+
@Data
15+
@Builder
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
public class WxMaQrcodeJumpWxaItem implements Serializable {
19+
private static final long serialVersionUID = -675341413130655505L;
20+
21+
/**
22+
* 小程序 appid。
23+
*/
24+
@SerializedName("appid")
25+
private String appId;
26+
27+
/**
28+
* 跳转页面路径。
29+
*/
30+
@SerializedName("path")
31+
private String path;
32+
}
33+

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ public interface Link {
301301
String QUERY_URLLINK_URL = "https://api.weixin.qq.com/wxa/query_urllink";
302302
}
303303

304+
/**
305+
* URL Link 二维码快速跳转规则管理.
306+
*/
307+
public interface QrcodeJump {
308+
String QRCODE_JUMP_ADD = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/addcategoryrule";
309+
String QRCODE_JUMP_GET = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/getcategory";
310+
String QRCODE_JUMP_GET_LIST = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/getcategorybypage";
311+
String QRCODE_JUMP_DELETE = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/deletecategoryrule";
312+
}
313+
304314
public interface ShortLink {
305315
String GENERATE_SHORT_LINK_URL = "https://api.weixin.qq.com/wxa/genwxashortlink";
306316
}

0 commit comments

Comments
 (0)