🆕 #3124 【小程序】实现查询 URL Link的接口

This commit is contained in:
杨镇涛
2023-11-13 23:44:19 +08:00
committed by GitHub
parent 473d2c14c3
commit b9bd619e6f
6 changed files with 157 additions and 0 deletions

View File

@@ -3,6 +3,8 @@ package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.shortlink.GenerateShortLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.GenerateUrlLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.request.QueryUrlLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.response.QueryUrlLinkResponse;
import me.chanjar.weixin.common.error.WxErrorException;
/**
@@ -29,4 +31,14 @@ public interface WxMaLinkService {
* @throws WxErrorException .
*/
String generateShortLink(GenerateShortLinkRequest request) throws WxErrorException;
/**
* 查询 URL Link
* 接口文档: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-link/queryUrlLink.html
*
* @param request 请求
* @return link地址
* @throws WxErrorException .
*/
QueryUrlLinkResponse queryUrlLink(QueryUrlLinkRequest request) throws WxErrorException;
}

View File

@@ -4,12 +4,16 @@ import cn.binarywang.wx.miniapp.api.WxMaLinkService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.shortlink.GenerateShortLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.GenerateUrlLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.request.QueryUrlLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.response.QueryUrlLinkResponse;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Link.GENERATE_URLLINK_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Link.QUERY_URLLINK_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.ShortLink.GENERATE_SHORT_LINK_URL;
/**
@@ -44,4 +48,10 @@ public class WxMaLinkServiceImpl implements WxMaLinkService {
}
throw new WxErrorException("无link");
}
@Override
public QueryUrlLinkResponse queryUrlLink(QueryUrlLinkRequest request) throws WxErrorException {
String result = this.wxMaService.post(QUERY_URLLINK_URL, request);
return WxGsonBuilder.create().fromJson(result, QueryUrlLinkResponse.class);
}
}