#686 获取体验小程序的体验二维码接口增加path参数

This commit is contained in:
Binary Wang 2018-08-08 21:04:49 +08:00
parent 214e7e58fa
commit 8c63f13387
3 changed files with 34 additions and 21 deletions

View File

@ -1,5 +1,7 @@
package cn.binarywang.wx.miniapp.api;
import java.util.List;
import cn.binarywang.wx.miniapp.bean.code.WxMaCategory;
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeAuditStatus;
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest;
@ -7,8 +9,6 @@ import cn.binarywang.wx.miniapp.bean.code.WxMaCodeSubmitAuditRequest;
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
* 小程序代码管理相关 API大部分只能是第三方平台调用
* 文档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 {
/**
* 获取体验小程序的体验二维码
* 文档地址
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=&lang=zh_CN
*
* @param path 指定体验版二维码跳转到某个具体页面如果不需要的话则不需要填path参数可在路径后以?参数方式传入参数
* 具体的路径加参数需要urlencode方法内部处理比如page/index?action=1编码后得到page%2Findex%3Faction%3D1
* @return 二维码 bytes
* @throws WxErrorException 上传失败时抛出具体错误码请看类注释文档
*/
byte[] getQrCode() throws WxErrorException;
byte[] getQrCode(String path) throws WxErrorException;
/**
* 获取授权小程序帐号的可选类目

View File

@ -1,5 +1,15 @@
package cn.binarywang.wx.miniapp.api.impl;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import cn.binarywang.wx.miniapp.api.WxMaCodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.code.WxMaCategory;
@ -17,12 +27,6 @@ import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.json.GsonHelper;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
/**
* @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-26 20:00
@ -41,13 +45,19 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
}
@Override
public byte[] getQrCode() throws WxErrorException {
public byte[] getQrCode(String path) throws WxErrorException {
String appId = this.wxMaService.getWxMaConfig().getAppid();
Path qrCodeFilePath = null;
try {
RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor
.create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("weixin-java-tools-ma-" + appId).toFile());
qrCodeFilePath = this.wxMaService.execute(executor, GET_QRCODE_URL, null).toPath();
final StringBuilder url = new StringBuilder(GET_QRCODE_URL);
if (StringUtils.isNotBlank(path)) {
url.append("?path=").append(URLEncoder.encode(path, StandardCharsets.UTF_8.name()));
}
qrCodeFilePath = this.wxMaService.execute(executor, url.toString(), null).toPath();
return Files.readAllBytes(qrCodeFilePath);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);

View File

@ -1,5 +1,12 @@
package cn.binarywang.wx.miniapp.api.impl;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.testng.annotations.*;
import cn.binarywang.wx.miniapp.api.WxMaCodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.code.WxMaCategory;
@ -11,16 +18,8 @@ import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.test.ApiTestModule;
import com.google.inject.Inject;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.*;
/**
* @author <a href="https://github.com/charmingoh">Charming</a>
@ -77,7 +76,7 @@ public class WxMaCodeServiceImplTest {
@Test
public void testGetQrCode() throws Exception {
byte[] qrCode = wxService.getCodeService().getQrCode();
byte[] qrCode = wxService.getCodeService().getQrCode(null);
assertTrue(qrCode.length > 0);
}