Skip to content
Open
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
@@ -0,0 +1,56 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRule;
import me.chanjar.weixin.common.error.WxErrorException;

import java.util.List;

/**
* 小程序 URL Link 二维码快速跳转规则管理服务。
*/
public interface WxMaQrcodeJumpService {

/**
* 添加二维码快速跳转规则。
*
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/qr-code-quickly-jump.html
*
* @param rule 规则
* @return 结果(errmsg/errcode)
*/
String addRule(WxMaQrcodeJumpRule rule) throws WxErrorException;

/**
* 获取二维码快速跳转规则。
*
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/get-qr-code-jump-rule.html
*
* @param isDefault 是否查询默认规则
* @param prefix 路径前缀(最长 32 个字符)
* @return 二维码规则列表
*/
List<WxMaQrcodeJumpRule> getRules(Boolean isDefault, String prefix) throws WxErrorException;

/**
* 分页获取二维码快速跳转规则列表。
*
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/get-qr-code-jump-rule-list.html
*
* @param getType 1:查询前缀匹配的规则;2:查询默认规则
* @param pageNum 页码,从 1 开始
* @param pageSize 每页条数,最多 20
* @return 二维码规则列表
*/
List<WxMaQrcodeJumpRule> getRuleList(Integer getType, Integer pageNum, Integer pageSize) throws WxErrorException;

/**
* 删除二维码快速跳转规则。
*
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/delete-qr-code-jump-rule.html
*
* @param prefix 路径前缀
* @return 结果(errmsg/errcode)
*/
String deleteRule(String prefix) throws WxErrorException;
}

Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ WxMaApiResponse execute(
*/
WxMaLinkService getLinkService();

/**
* 获取 URL Link 二维码快速跳转规则管理服务对象。
*
* 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/qr-code-quickly-jump.html
*
* @return 二维码快速跳转规则管理服务对象WxMaQrcodeJumpService
*/
WxMaQrcodeJumpService getQrcodeJumpService();

/**
* 获取电子发票报销方服务接口服务对象。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
new WxMaShopAfterSaleServiceImpl(this);
private final WxMaShopDeliveryService shopDeliveryService = new WxMaShopDeliveryServiceImpl(this);
private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this);
private final WxMaQrcodeJumpService qrcodeJumpService = new WxMaQrcodeJumpServiceImpl(this);
private final WxMaReimburseInvoiceService reimburseInvoiceService =
new WxMaReimburseInvoiceServiceImpl(this);
private final WxMaDeviceSubscribeService deviceSubscribeService =
Expand Down Expand Up @@ -788,6 +789,11 @@ public WxMaLinkService getLinkService() {
return this.linkService;
}

@Override
public WxMaQrcodeJumpService getQrcodeJumpService() {
return this.qrcodeJumpService;
}

@Override
public WxMaReimburseInvoiceService getReimburseInvoiceService() {
return this.reimburseInvoiceService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package cn.binarywang.wx.miniapp.api.impl;

import cn.binarywang.wx.miniapp.api.WxMaQrcodeJumpService;
import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRule;
import cn.binarywang.wx.miniapp.bean.qrcode.WxMaQrcodeJumpRuleListResponse;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.QrcodeJump.*;
import static me.chanjar.weixin.common.util.json.WxGsonBuilder.create;

/**
* {@link WxMaQrcodeJumpService} 实现。
*/
@RequiredArgsConstructor
public class WxMaQrcodeJumpServiceImpl implements WxMaQrcodeJumpService {
private final BaseWxMaServiceImpl wxMaService;
Comment on lines +3 to +23

@Override
public String addRule(WxMaQrcodeJumpRule rule) throws WxErrorException {
return this.wxMaService.post(QRCODE_JUMP_ADD, create().toJson(rule));
}

@Override
public List<WxMaQrcodeJumpRule> getRules(Boolean isDefault, String prefix) throws WxErrorException {
final JsonObject request = new JsonObject();
if (isDefault != null) {
request.addProperty("is_default", isDefault);
}
if (prefix != null) {
request.addProperty("prefix", prefix);
}

String response = this.wxMaService.post(QRCODE_JUMP_GET, request.toString());
WxMaQrcodeJumpRuleListResponse result = create().fromJson(response, WxMaQrcodeJumpRuleListResponse.class);
if (result == null || result.getRuleList() == null || result.getRuleList().isEmpty()) {
return Collections.emptyList();
}
return result.getRuleList();
}

@Override
public List<WxMaQrcodeJumpRule> getRuleList(Integer getType, Integer pageNum, Integer pageSize) throws WxErrorException {
final JsonObject request = new JsonObject();
if (getType != null) {
request.addProperty("get_type", getType);
}
if (pageNum != null) {
request.addProperty("page_num", pageNum);
}
if (pageSize != null) {
request.addProperty("page_size", pageSize);
}

String response = this.wxMaService.post(QRCODE_JUMP_GET_LIST, request.toString());
WxMaQrcodeJumpRuleListResponse result = create().fromJson(response, WxMaQrcodeJumpRuleListResponse.class);
if (result == null || result.getRuleList() == null || result.getRuleList().isEmpty()) {
return Collections.emptyList();
}
return result.getRuleList();
}

@Override
public String deleteRule(String prefix) throws WxErrorException {
final Map<String, String> request = new HashMap<>(1);
request.put("prefix", prefix);
return this.wxMaService.post(QRCODE_JUMP_DELETE, create().toJson(request));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cn.binarywang.wx.miniapp.bean.qrcode;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
* URL Link 二维码快速跳转规则。
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaQrcodeJumpRule implements Serializable {
private static final long serialVersionUID = -3450269467817402123L;

/**
* 跳转链接规则前缀,最多 32 个字符。
*/
@SerializedName("prefix")
private String prefix;

/**
* 是否支持子路径匹配。
*/
@SerializedName("permit_sub_rule")
private Boolean permitSubRule;

/**
* 跳转版本,1:正式版;2:测试版;3:体验版。
*/
@SerializedName("open_version")
private Integer openVersion;

/**
* 正式版跳转页面。
*/
@SerializedName("path")
private String path;

/**
* 测试版/体验版可跳转小程序信息。
*/
@SerializedName("debug_wxa_info")
private List<WxMaQrcodeJumpWxaItem> debugWxaInfo;

/**
* 二维码规则是否失效。
*/
@SerializedName("is_expire")
private Boolean expire;
Comment on lines +55 to +56
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cn.binarywang.wx.miniapp.bean.qrcode;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
* URL Link 二维码快速跳转规则列表返回值。
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaQrcodeJumpRuleListResponse implements Serializable {
private static final long serialVersionUID = 6706970228943946110L;

/**
* 规则列表。
*/
@SerializedName("rule_list")
private List<WxMaQrcodeJumpRule> ruleList;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cn.binarywang.wx.miniapp.bean.qrcode;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* URL Link 跳转规则中的小程序信息。
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaQrcodeJumpWxaItem implements Serializable {
private static final long serialVersionUID = -675341413130655505L;

/**
* 小程序 appid。
*/
@SerializedName("appid")
private String appId;

/**
* 跳转页面路径。
*/
@SerializedName("path")
private String path;
}

Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ public interface Link {
String QUERY_URLLINK_URL = "https://api.weixin.qq.com/wxa/query_urllink";
}

/**
* URL Link 二维码快速跳转规则管理.
*/
public interface QrcodeJump {
String QRCODE_JUMP_ADD = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/addcategoryrule";
String QRCODE_JUMP_GET = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/getcategory";
String QRCODE_JUMP_GET_LIST = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/getcategorybypage";
String QRCODE_JUMP_DELETE = "https://api.weixin.qq.com/wxaapi/wxaqrcodefast/deletecategoryrule";
}

public interface ShortLink {
String GENERATE_SHORT_LINK_URL = "https://api.weixin.qq.com/wxa/genwxashortlink";
}
Expand Down
Loading