Skip to content

Commit 6646b06

Browse files
li362692680Binary Wang
authored andcommitted
🆕 【小程序】添加获取 NFC 的小程序 scheme 接口
1 parent 38ac8e4 commit 6646b06

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSchemeService.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* <pre>
88
* 小程序Scheme码相关操作接口.
99
*
10-
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
10+
*
1111
* </pre>
1212
*
1313
* @author : cofedream
@@ -16,9 +16,16 @@
1616
public interface WxMaSchemeService {
1717
/**
1818
* 获取小程序scheme码
19-
*
19+
*文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
2020
* @param request 请求参数
2121
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
2222
*/
2323
String generate(WxMaGenerateSchemeRequest request) throws WxErrorException;
24+
/**
25+
* 获取NFC 的小程序 scheme
26+
*文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html
27+
* @param request 请求参数
28+
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
29+
*/
30+
String generateNFC(WxMaGenerateSchemeRequest request) throws WxErrorException;
2431
}

‎weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImpl.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import me.chanjar.weixin.common.error.WxErrorException;
1212
import me.chanjar.weixin.common.util.json.GsonParser;
1313

14+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENERATE_NFC_SCHEME_URL;
1415
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENERATE_SCHEME_URL;
1516

1617
/**
@@ -21,6 +22,13 @@
2122
public class WxMaSchemeServiceImpl implements WxMaSchemeService {
2223
private final WxMaService wxMaService;
2324

25+
/**
26+
* 获取小程序scheme码
27+
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
28+
*
29+
* @param request 请求参数
30+
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
31+
*/
2432
@Override
2533
public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException {
2634
String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson());
@@ -30,4 +38,21 @@ public String generate(WxMaGenerateSchemeRequest request) throws WxErrorExceptio
3038
}
3139
return jsonObject.get("openlink").getAsString();
3240
}
41+
42+
/**
43+
* 获取NFC 的小程序 scheme
44+
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html
45+
*
46+
* @param request 请求参数
47+
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
48+
*/
49+
@Override
50+
public String generateNFC(WxMaGenerateSchemeRequest request) throws WxErrorException {
51+
String responseContent = this.wxMaService.post(GENERATE_NFC_SCHEME_URL, request.toJson());
52+
JsonObject jsonObject = GsonParser.parse(responseContent);
53+
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
54+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
55+
}
56+
return jsonObject.get("openlink").getAsString();
57+
}
3358
}

‎weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ public interface Run {
339339

340340
public interface Scheme {
341341
String GENERATE_SCHEME_URL = "https://api.weixin.qq.com/wxa/generatescheme";
342+
String GENERATE_NFC_SCHEME_URL = "https://api.weixin.qq.com/wxa/generatenfcscheme";
342343
}
343344

344345
public interface Link {

0 commit comments

Comments
 (0)