🆕 【小程序】添加获取 NFC 的小程序 scheme 接口

This commit is contained in:
四叶草 2023-07-31 02:42:52 +00:00 committed by Binary Wang
parent 38ac8e4698
commit 6646b064b8
3 changed files with 35 additions and 2 deletions

View File

@ -7,7 +7,7 @@ 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
@ -16,9 +16,16 @@ import me.chanjar.weixin.common.error.WxErrorException;
public interface WxMaSchemeService {
/**
* 获取小程序scheme码
*
*文档地址https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
* @param request 请求参数
* @throws WxErrorException 生成失败时抛出具体错误码请看文档
*/
String generate(WxMaGenerateSchemeRequest request) throws WxErrorException;
/**
* 获取NFC 的小程序 scheme
*文档地址https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html
* @param request 请求参数
* @throws WxErrorException 生成失败时抛出具体错误码请看文档
*/
String generateNFC(WxMaGenerateSchemeRequest request) throws WxErrorException;
}

View File

@ -11,6 +11,7 @@ import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENERATE_NFC_SCHEME_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENERATE_SCHEME_URL;
/**
@ -21,6 +22,13 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENER
public class WxMaSchemeServiceImpl implements WxMaSchemeService {
private final WxMaService wxMaService;
/**
* 获取小程序scheme码
* 文档地址https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
*
* @param request 请求参数
* @throws WxErrorException 生成失败时抛出具体错误码请看文档
*/
@Override
public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson());
@ -30,4 +38,21 @@ public class WxMaSchemeServiceImpl implements WxMaSchemeService {
}
return jsonObject.get("openlink").getAsString();
}
/**
* 获取NFC 的小程序 scheme
* 文档地址https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html
*
* @param request 请求参数
* @throws WxErrorException 生成失败时抛出具体错误码请看文档
*/
@Override
public String generateNFC(WxMaGenerateSchemeRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(GENERATE_NFC_SCHEME_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("openlink").getAsString();
}
}

View File

@ -339,6 +339,7 @@ public class WxMaApiUrlConstants {
public interface Scheme {
String GENERATE_SCHEME_URL = "https://api.weixin.qq.com/wxa/generatescheme";
String GENERATE_NFC_SCHEME_URL = "https://api.weixin.qq.com/wxa/generatenfcscheme";
}
public interface Link {