Skip to content

Commit 8c63f13

Browse files
committed
#686 获取体验小程序的体验二维码接口增加path参数
1 parent 214e7e5 commit 8c63f13

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package cn.binarywang.wx.miniapp.api;
22

3+
import java.util.List;
4+
35
import cn.binarywang.wx.miniapp.bean.code.WxMaCategory;
46
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeAuditStatus;
57
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest;
68
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeSubmitAuditRequest;
79
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution;
810
import me.chanjar.weixin.common.error.WxErrorException;
911

10-
import java.util.List;
11-
1212
/**
1313
* 小程序代码管理相关 API(大部分只能是第三方平台调用)
1414
* 文档:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=&lang=zh_CN
@@ -44,11 +44,15 @@ public interface WxMaCodeService {
4444

4545
/**
4646
* 获取体验小程序的体验二维码
47+
* 文档地址:
48+
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=&lang=zh_CN
4749
*
50+
* @param path 指定体验版二维码跳转到某个具体页面(如果不需要的话,则不需要填path参数,可在路径后以“?参数”方式传入参数)
51+
* 具体的路径加参数需要urlencode(方法内部处理),比如page/index?action=1编码后得到page%2Findex%3Faction%3D1
4852
* @return 二维码 bytes
4953
* @throws WxErrorException 上传失败时抛出,具体错误码请看类注释文档
5054
*/
51-
byte[] getQrCode() throws WxErrorException;
55+
byte[] getQrCode(String path) throws WxErrorException;
5256

5357
/**
5458
* 获取授权小程序帐号的可选类目

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package cn.binarywang.wx.miniapp.api.impl;
22

3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.net.URLEncoder;
6+
import java.nio.charset.StandardCharsets;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.util.List;
10+
11+
import org.apache.commons.lang3.StringUtils;
12+
313
import cn.binarywang.wx.miniapp.api.WxMaCodeService;
414
import cn.binarywang.wx.miniapp.api.WxMaService;
515
import cn.binarywang.wx.miniapp.bean.code.WxMaCategory;
@@ -17,12 +27,6 @@
1727
import me.chanjar.weixin.common.util.http.RequestExecutor;
1828
import me.chanjar.weixin.common.util.json.GsonHelper;
1929

20-
import java.io.File;
21-
import java.io.IOException;
22-
import java.nio.file.Files;
23-
import java.nio.file.Path;
24-
import java.util.List;
25-
2630
/**
2731
* @author <a href="https://github.com/charmingoh">Charming</a>
2832
* @since 2018-04-26 20:00
@@ -41,13 +45,19 @@ public void commit(WxMaCodeCommitRequest commitRequest) throws WxErrorException
4145
}
4246

4347
@Override
44-
public byte[] getQrCode() throws WxErrorException {
48+
public byte[] getQrCode(String path) throws WxErrorException {
4549
String appId = this.wxMaService.getWxMaConfig().getAppid();
4650
Path qrCodeFilePath = null;
4751
try {
4852
RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor
4953
.create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("weixin-java-tools-ma-" + appId).toFile());
50-
qrCodeFilePath = this.wxMaService.execute(executor, GET_QRCODE_URL, null).toPath();
54+
55+
final StringBuilder url = new StringBuilder(GET_QRCODE_URL);
56+
if (StringUtils.isNotBlank(path)) {
57+
url.append("?path=").append(URLEncoder.encode(path, StandardCharsets.UTF_8.name()));
58+
}
59+
60+
qrCodeFilePath = this.wxMaService.execute(executor, url.toString(), null).toPath();
5161
return Files.readAllBytes(qrCodeFilePath);
5262
} catch (IOException e) {
5363
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);

weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package cn.binarywang.wx.miniapp.api.impl;
22

3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import org.testng.annotations.*;
9+
310
import cn.binarywang.wx.miniapp.api.WxMaCodeService;
411
import cn.binarywang.wx.miniapp.api.WxMaService;
512
import cn.binarywang.wx.miniapp.bean.code.WxMaCategory;
@@ -11,16 +18,8 @@
1118
import cn.binarywang.wx.miniapp.config.WxMaConfig;
1219
import cn.binarywang.wx.miniapp.test.ApiTestModule;
1320
import com.google.inject.Inject;
14-
import org.testng.annotations.Guice;
15-
import org.testng.annotations.Test;
16-
17-
import java.util.Arrays;
18-
import java.util.HashMap;
19-
import java.util.List;
20-
import java.util.Map;
2121

22-
import static org.testng.Assert.assertNotNull;
23-
import static org.testng.Assert.assertTrue;
22+
import static org.testng.Assert.*;
2423

2524
/**
2625
* @author <a href="https://github.com/charmingoh">Charming</a>
@@ -77,7 +76,7 @@ public void testCommit() throws Exception {
7776

7877
@Test
7978
public void testGetQrCode() throws Exception {
80-
byte[] qrCode = wxService.getCodeService().getQrCode();
79+
byte[] qrCode = wxService.getCodeService().getQrCode(null);
8180
assertTrue(qrCode.length > 0);
8281
}
8382

0 commit comments

Comments
 (0)