Skip to content

Commit 9de8759

Browse files
authored
🆕 #4040 【小程序】新增 URL Link 二维码快速跳转规则管理服务
1 parent abc9a97 commit 9de8759

9 files changed

Lines changed: 375 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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaQrcodeJumpService;
4+
import cn.binarywang.wx.miniapp.api.WxMaService;
5+
import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRule;
6+
import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRuleListResponse;
7+
import com.google.gson.JsonObject;
8+
import lombok.RequiredArgsConstructor;
9+
import me.chanjar.weixin.common.error.WxErrorException;
10+
11+
import java.util.Collections;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.QrcodeJump.*;
17+
import static me.chanjar.weixin.common.util.json.WxGsonBuilder.create;
18+
19+
/**
20+
* {@link WxMaQrcodeJumpService} 实现。
21+
*/
22+
@RequiredArgsConstructor
23+
public class WxMaQrcodeJumpServiceImpl implements WxMaQrcodeJumpService {
24+
private final WxMaService wxMaService;
25+
26+
@Override
27+
public String addRule(WxMaQrcodeJumpRule rule) throws WxErrorException {
28+
return this.wxMaService.post(QRCODE_JUMP_ADD, create().toJson(rule));
29+
}
30+
31+
@Override
32+
public List<WxMaQrcodeJumpRule> getRules(Boolean isDefault, String prefix) throws WxErrorException {
33+
final JsonObject request = new JsonObject();
34+
if (isDefault != null) {
35+
request.addProperty("is_default", isDefault);
36+
}
37+
if (prefix != null) {
38+
request.addProperty("prefix", prefix);
39+
}
40+
41+
String response = this.wxMaService.post(QRCODE_JUMP_GET, request.toString());
42+
WxMaQrcodeJumpRuleListResponse result = create().fromJson(response, WxMaQrcodeJumpRuleListResponse.class);
43+
if (result == null || result.getRuleList() == null || result.getRuleList().isEmpty()) {
44+
return Collections.emptyList();
45+
}
46+
return result.getRuleList();
47+
}
48+
49+
@Override
50+
public List<WxMaQrcodeJumpRule> getRuleList(Integer getType, Integer pageNum, Integer pageSize) throws WxErrorException {
51+
final JsonObject request = new JsonObject();
52+
if (getType != null) {
53+
request.addProperty("get_type", getType);
54+
}
55+
if (pageNum != null) {
56+
request.addProperty("page_num", pageNum);
57+
}
58+
if (pageSize != null) {
59+
request.addProperty("page_size", pageSize);
60+
}
61+
62+
String response = this.wxMaService.post(QRCODE_JUMP_GET_LIST, request.toString());
63+
WxMaQrcodeJumpRuleListResponse result = create().fromJson(response, WxMaQrcodeJumpRuleListResponse.class);
64+
if (result == null || result.getRuleList() == null || result.getRuleList().isEmpty()) {
65+
return Collections.emptyList();
66+
}
67+
return result.getRuleList();
68+
}
69+
70+
@Override
71+
public String deleteRule(String prefix) throws WxErrorException {
72+
final Map<String, String> request = new HashMap<>(1);
73+
request.put("prefix", prefix);
74+
return this.wxMaService.post(QRCODE_JUMP_DELETE, create().toJson(request));
75+
}
76+
}
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 isExpire;
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)