diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java index 32e4e78ca..46fc97d2b 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java @@ -193,6 +193,8 @@ public interface WxMaQrcodeService { * @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~, * 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式) * @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面 + * @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错); + * 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用 * @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" * @param width 默认430 二维码的宽度 * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 @@ -201,7 +203,7 @@ public interface WxMaQrcodeService { * @return 文件内容字节数组 * @throws WxErrorException 异常 */ - byte[] createWxaCodeUnlimitBytes(String scene, String page, String envVersion, int width, boolean autoColor, + byte[] createWxaCodeUnlimitBytes(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException; /** @@ -217,6 +219,8 @@ public interface WxMaQrcodeService { * 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式) * @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面 * @param filePath 二维码生成的文件路径,例如: /var/temp + * @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错); + * 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用 * @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" * @param width 默认430 二维码的宽度 * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 @@ -225,7 +229,7 @@ public interface WxMaQrcodeService { * @return 文件对象 * @throws WxErrorException 异常 */ - File createWxaCodeUnlimit(String scene, String page, String filePath, String envVersion, int width, boolean autoColor, + File createWxaCodeUnlimit(String scene, String page, String filePath, boolean checkPath, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException; /** @@ -240,6 +244,8 @@ public interface WxMaQrcodeService { * @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~, * 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式) * @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面 + * @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错); + * 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用 * @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop" * @param width 默认430 二维码的宽度 * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 @@ -248,7 +254,7 @@ public interface WxMaQrcodeService { * @return 文件对象 * @throws WxErrorException 异常 */ - File createWxaCodeUnlimit(String scene, String page, String envVersion, int width, boolean autoColor, + File createWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException; /** diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java index ccfac099b..072119bc2 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java @@ -76,24 +76,25 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { } @Override - public byte[] createWxaCodeUnlimitBytes(String scene, String page, String envVersion, int width, boolean autoColor, + public byte[] createWxaCodeUnlimitBytes(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()), - GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, envVersion, width, autoColor, lineColor, isHyaline)); + GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline)); } @Override - public File createWxaCodeUnlimit(String scene, String page, String envVersion, int width, boolean autoColor, + public File createWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()), - GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, envVersion, width, autoColor, lineColor, isHyaline)); + GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline)); } - private WxaCodeUnlimit buildWxaCodeUnlimit(String scene, String page, String envVersion, int width, boolean autoColor, + private WxaCodeUnlimit buildWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) { WxaCodeUnlimit wxaCodeUnlimit = new WxaCodeUnlimit(); wxaCodeUnlimit.setScene(scene); wxaCodeUnlimit.setPage(page); + wxaCodeUnlimit.setCheckPath(checkPath); wxaCodeUnlimit.setEnvVersion(envVersion); wxaCodeUnlimit.setWidth(width); wxaCodeUnlimit.setAutoColor(autoColor); @@ -105,7 +106,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { @Override public File createWxaCodeUnlimit(String scene, String page) throws WxErrorException { - return this.createWxaCodeUnlimit(scene, page, "release", 430, true, null, false); + return this.createWxaCodeUnlimit(scene, page, true, "release", 430, true, null, false); } @Override @@ -144,15 +145,15 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { } @Override - public File createWxaCodeUnlimit(String scene, String page, String filePath, String envVersion, int width, boolean autoColor, + public File createWxaCodeUnlimit(String scene, String page, String filePath, boolean checkPath, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath), - GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, envVersion, width, autoColor, lineColor, isHyaline)); + GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline)); } @Override public File createWxaCodeUnlimit(String scene, String page, String filePath) throws WxErrorException { - return this.createWxaCodeUnlimit(scene, page, filePath, "release", 430, true, null, false); + return this.createWxaCodeUnlimit(scene, page, filePath, true, "release", 430, true, null, false); } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxaCodeUnlimit.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxaCodeUnlimit.java index f9c902efd..32e713ad8 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxaCodeUnlimit.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxaCodeUnlimit.java @@ -20,6 +20,9 @@ public class WxaCodeUnlimit extends AbstractWxMaQrcodeWrapper implements Seriali private String scene; private String page; + @SerializedName("check_path") + private boolean checkPath = true; + @SerializedName("env_version") private String envVersion = "release"; diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java index cf500c2b2..25988f5fd 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImplTest.java @@ -52,7 +52,7 @@ public class WxMaQrcodeServiceImplTest { @Test public void testCreateWxaCodeUnlimitBytes() throws WxErrorException { - final byte[] wxCode = this.wxService.getQrcodeService().createWxaCodeUnlimitBytes("111", null, "trial", 122, true, null, false); + final byte[] wxCode = this.wxService.getQrcodeService().createWxaCodeUnlimitBytes("111", "pages/unknown", false, "trial", 122, true, null, false); assertThat(wxCode).isNotNull(); }