mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 【小程序】添加获取 NFC 的小程序 scheme 接口
This commit is contained in:
parent
38ac8e4698
commit
6646b064b8
@ -7,7 +7,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
|||||||
* <pre>
|
* <pre>
|
||||||
* 小程序Scheme码相关操作接口.
|
* 小程序Scheme码相关操作接口.
|
||||||
*
|
*
|
||||||
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author : cofedream
|
* @author : cofedream
|
||||||
@ -16,9 +16,16 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
|||||||
public interface WxMaSchemeService {
|
public interface WxMaSchemeService {
|
||||||
/**
|
/**
|
||||||
* 获取小程序scheme码
|
* 获取小程序scheme码
|
||||||
*
|
*文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
|
||||||
* @param request 请求参数
|
* @param request 请求参数
|
||||||
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
|
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
|
||||||
*/
|
*/
|
||||||
String generate(WxMaGenerateSchemeRequest 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;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import me.chanjar.weixin.common.error.WxError;
|
|||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import me.chanjar.weixin.common.util.json.GsonParser;
|
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;
|
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 {
|
public class WxMaSchemeServiceImpl implements WxMaSchemeService {
|
||||||
private final WxMaService wxMaService;
|
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
|
@Override
|
||||||
public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException {
|
public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException {
|
||||||
String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson());
|
String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson());
|
||||||
@ -30,4 +38,21 @@ public class WxMaSchemeServiceImpl implements WxMaSchemeService {
|
|||||||
}
|
}
|
||||||
return jsonObject.get("openlink").getAsString();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,6 +339,7 @@ public class WxMaApiUrlConstants {
|
|||||||
|
|
||||||
public interface Scheme {
|
public interface Scheme {
|
||||||
String GENERATE_SCHEME_URL = "https://api.weixin.qq.com/wxa/generatescheme";
|
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 {
|
public interface Link {
|
||||||
|
Loading…
Reference in New Issue
Block a user