mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #2306【微信小程序】增加小程序Short Link生成的接口
This commit is contained in:
@@ -456,6 +456,13 @@ public interface WxMaService extends WxService {
|
||||
*/
|
||||
WxMaLinkService getLinkService();
|
||||
|
||||
/**
|
||||
* 获取小程序 Short Link服务接口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
WxMaShortLinkService getShortLinkService();
|
||||
|
||||
/**
|
||||
* 获取电子发票报销方服务接口
|
||||
*
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.shortlink.GenerateShortLinkRequest;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取小程序 Short Link接口
|
||||
* 接口文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/short-link/shortlink.generate.html
|
||||
*/
|
||||
public interface WxMaShortLinkService {
|
||||
|
||||
String generate(GenerateShortLinkRequest request) throws WxErrorException;
|
||||
}
|
||||
@@ -74,6 +74,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
private final WxMaShopAfterSaleService shopAfterSaleService = new WxMaShopAfterSaleServiceImpl(this);
|
||||
private final WxMaShopDeliveryService shopDeliveryService = new WxMaShopDeliveryServiceImpl(this);
|
||||
private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this);
|
||||
private final WxMaShortLinkService shortlinkService = new WxMaShortLinkServiceImpl(this);
|
||||
private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this);
|
||||
private Map<String, WxMaConfig> configMap;
|
||||
private int retrySleepMillis = 1000;
|
||||
@@ -569,6 +570,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
return this.linkService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShortLinkService getShortLinkService() {
|
||||
return this.shortlinkService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaReimburseInvoiceService getReimburseInvoiceService() {
|
||||
return this.reimburseInvoiceService;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaShortLinkService;
|
||||
import cn.binarywang.wx.miniapp.bean.shortlink.GenerateShortLinkRequest;
|
||||
import cn.binarywang.wx.miniapp.bean.urllink.GenerateUrlLinkRequest;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.json.GsonParser;
|
||||
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Link.GENERATE_URLLINK_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.ShortLink.GENERATE_SHORT_LINK_URL;
|
||||
|
||||
/**
|
||||
* 获取小程序 Short Link接口
|
||||
* 接口文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/short-link/shortlink.generate.html
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class WxMaShortLinkServiceImpl implements WxMaShortLinkService {
|
||||
|
||||
private final WxMaService wxMaService;
|
||||
|
||||
@Override
|
||||
public String generate(GenerateShortLinkRequest request) throws WxErrorException {
|
||||
String result = this.wxMaService.post(GENERATE_SHORT_LINK_URL,request);
|
||||
String linkField = "link";
|
||||
JsonObject jsonObject = GsonParser.parse(result);
|
||||
if(jsonObject.has(linkField)){
|
||||
return jsonObject.get(linkField).toString();
|
||||
}
|
||||
throw new WxErrorException("无link");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user