1.WxMaLinkService(WxJava-MiniApp Java SDK 4.5.0 API)
依赖:一开始用的是3.6.0的版本发现调用不了WxMaLinkService这个接口,最后网上查询在发现版本低
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<!-- <version>3.6.0</version>-->
<version>4.5.0</version>
</dependency>
WxMaLinkService源码
public interface WxMaLinkService {
String generateUrlLink(GenerateUrlLinkRequest var1) throws WxErrorException;
String generateShortLink(GenerateShortLinkRequest var1) throws WxErrorException;
}
提供了两个方法:generateUrlLink(),generateShortLink(),具体实现:
public String generateUrlLink(GenerateUrlLinkRequest request) throws WxErrorException {
String result = this.wxMaService.post("https://api.weixin.qq.com/wxa/generate_urllink", request);
String linkField = "url_link";
JsonObject jsonObject = GsonParser.parse(result);
if (jsonObject.has(linkField)) {
return jsonObject.get(linkField).getAsString();
} else {
throw new WxErrorException("无url_link");
}
}
public String generateShortLink(GenerateShortLinkRequest request) throws WxErrorException {
String result = this.wxMaService.post("https://api.weixin.qq.com/wxa/genwxashortlink", request);
String linkField = "link";
JsonObject jsonObject = GsonParser.parse(result);
if (jsonObject.has(linkField)) {
return jsonObject.get(linkField).getAsString();
} else {
throw new WxErrorException("无link");
}
}
generateUrlLink:获取小程序 URL Link接口 接口文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html
generateShortLink:获取小程序 Short Link接口 接口文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/short-link/shortlink.generate.html