mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #1976 【小程序】增加获取小程序scheme码的接口
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 小程序Scheme码相关操作接口.
|
||||
*
|
||||
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
|
||||
* </pre>
|
||||
*
|
||||
* @author : cofedream
|
||||
* @date : 2021-01-26
|
||||
*/
|
||||
public interface WxMaSchemeService {
|
||||
String GENERATE_SCHEME_URL = "https://api.weixin.qq.com/wxa/generatescheme";
|
||||
|
||||
/**
|
||||
* 获取小程序scheme码
|
||||
*
|
||||
* @param request 请求参数
|
||||
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
|
||||
*/
|
||||
String generate(WxMaGenerateSchemeRequest request) throws WxErrorException;
|
||||
}
|
||||
@@ -229,6 +229,12 @@ public interface WxMaService extends WxService {
|
||||
*/
|
||||
WxMaQrcodeService getQrcodeService();
|
||||
|
||||
/**
|
||||
* 返回获取小程序scheme码实现对象,以方便调用其各个接口.
|
||||
* @return WxMaSchemeService
|
||||
*/
|
||||
WxMaSchemeService getWxMaSchemeService();
|
||||
|
||||
/**
|
||||
* 返回订阅消息配置相关接口方法的实现类对象, 以方便调用其各个接口.
|
||||
*
|
||||
|
||||
@@ -47,6 +47,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
private final WxMaMediaService materialService = new WxMaMediaServiceImpl(this);
|
||||
private final WxMaUserService userService = new WxMaUserServiceImpl(this);
|
||||
private final WxMaQrcodeService qrCodeService = new WxMaQrcodeServiceImpl(this);
|
||||
private final WxMaSchemeService schemeService = new WxMaSchemeServiceImpl(this);
|
||||
private final WxMaAnalysisService analysisService = new WxMaAnalysisServiceImpl(this);
|
||||
private final WxMaCodeService codeService = new WxMaCodeServiceImpl(this);
|
||||
private final WxMaSettingService settingService = new WxMaSettingServiceImpl(this);
|
||||
@@ -413,6 +414,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
return this.qrCodeService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaSchemeService getWxMaSchemeService() {
|
||||
return schemeService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaSubscribeService getSubscribeService() {
|
||||
return this.subscribeService;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaSchemeService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.json.GsonParser;
|
||||
|
||||
/**
|
||||
* @author : cofedream
|
||||
* @date : 2021-01-28
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class WxMaSchemeServiceImpl implements WxMaSchemeService {
|
||||
private static final String ERR_CODE = "errcode";
|
||||
private final WxMaService wxMaService;
|
||||
|
||||
@Override
|
||||
public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException {
|
||||
String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson());
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return jsonObject.get("openlink").getAsString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user