Skip to content

Commit a647fe8

Browse files
authored
🎨 #2474【小程序】createWxaCodeUnlimit 接口方法支持设置check_path参数
1 parent 1309e9e commit a647fe8

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor
193193
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,
194194
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
195195
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
196+
* @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
197+
* 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
196198
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
197199
* @param width 默认430 二维码的宽度
198200
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
@@ -201,7 +203,7 @@ File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor
201203
* @return 文件内容字节数组
202204
* @throws WxErrorException 异常
203205
*/
204-
byte[] createWxaCodeUnlimitBytes(String scene, String page, String envVersion, int width, boolean autoColor,
206+
byte[] createWxaCodeUnlimitBytes(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor,
205207
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException;
206208

207209
/**
@@ -217,6 +219,8 @@ byte[] createWxaCodeUnlimitBytes(String scene, String page, String envVersion, i
217219
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
218220
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
219221
* @param filePath 二维码生成的文件路径,例如: /var/temp
222+
* @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
223+
* 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
220224
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
221225
* @param width 默认430 二维码的宽度
222226
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
@@ -225,7 +229,7 @@ byte[] createWxaCodeUnlimitBytes(String scene, String page, String envVersion, i
225229
* @return 文件对象
226230
* @throws WxErrorException 异常
227231
*/
228-
File createWxaCodeUnlimit(String scene, String page, String filePath, String envVersion, int width, boolean autoColor,
232+
File createWxaCodeUnlimit(String scene, String page, String filePath, boolean checkPath, String envVersion, int width, boolean autoColor,
229233
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException;
230234

231235
/**
@@ -240,6 +244,8 @@ File createWxaCodeUnlimit(String scene, String page, String filePath, String env
240244
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,
241245
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
242246
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
247+
* @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
248+
* 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
243249
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
244250
* @param width 默认430 二维码的宽度
245251
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
@@ -248,7 +254,7 @@ File createWxaCodeUnlimit(String scene, String page, String filePath, String env
248254
* @return 文件对象
249255
* @throws WxErrorException 异常
250256
*/
251-
File createWxaCodeUnlimit(String scene, String page, String envVersion, int width, boolean autoColor,
257+
File createWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor,
252258
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException;
253259

254260
/**

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,25 @@ public File createWxaCode(String path) throws WxErrorException {
7676
}
7777

7878
@Override
79-
public byte[] createWxaCodeUnlimitBytes(String scene, String page, String envVersion, int width, boolean autoColor,
79+
public byte[] createWxaCodeUnlimitBytes(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor,
8080
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
8181
return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()),
82-
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, envVersion, width, autoColor, lineColor, isHyaline));
82+
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline));
8383
}
8484

8585
@Override
86-
public File createWxaCodeUnlimit(String scene, String page, String envVersion, int width, boolean autoColor,
86+
public File createWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor,
8787
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
8888
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()),
89-
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, envVersion, width, autoColor, lineColor, isHyaline));
89+
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline));
9090
}
9191

92-
private WxaCodeUnlimit buildWxaCodeUnlimit(String scene, String page, String envVersion, int width, boolean autoColor,
92+
private WxaCodeUnlimit buildWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor,
9393
WxMaCodeLineColor lineColor, boolean isHyaline) {
9494
WxaCodeUnlimit wxaCodeUnlimit = new WxaCodeUnlimit();
9595
wxaCodeUnlimit.setScene(scene);
9696
wxaCodeUnlimit.setPage(page);
97+
wxaCodeUnlimit.setCheckPath(checkPath);
9798
wxaCodeUnlimit.setEnvVersion(envVersion);
9899
wxaCodeUnlimit.setWidth(width);
99100
wxaCodeUnlimit.setAutoColor(autoColor);
@@ -105,7 +106,7 @@ private WxaCodeUnlimit buildWxaCodeUnlimit(String scene, String page, String env
105106

106107
@Override
107108
public File createWxaCodeUnlimit(String scene, String page) throws WxErrorException {
108-
return this.createWxaCodeUnlimit(scene, page, "release", 430, true, null, false);
109+
return this.createWxaCodeUnlimit(scene, page, true, "release", 430, true, null, false);
109110
}
110111

111112
@Override
@@ -144,15 +145,15 @@ public File createWxaCode(String path, String filePath) throws WxErrorException
144145
}
145146

146147
@Override
147-
public File createWxaCodeUnlimit(String scene, String page, String filePath, String envVersion, int width, boolean autoColor,
148+
public File createWxaCodeUnlimit(String scene, String page, String filePath, boolean checkPath, String envVersion, int width, boolean autoColor,
148149
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
149150
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath),
150-
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, envVersion, width, autoColor, lineColor, isHyaline));
151+
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline));
151152
}
152153

153154
@Override
154155
public File createWxaCodeUnlimit(String scene, String page, String filePath) throws WxErrorException {
155-
return this.createWxaCodeUnlimit(scene, page, filePath, "release", 430, true, null, false);
156+
return this.createWxaCodeUnlimit(scene, page, filePath, true, "release", 430, true, null, false);
156157
}
157158

158159
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxaCodeUnlimit.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class WxaCodeUnlimit extends AbstractWxMaQrcodeWrapper implements Seriali
2020
private String scene;
2121
private String page;
2222

23+
@SerializedName("check_path")
24+
private boolean checkPath = true;
25+
2326
@SerializedName("env_version")
2427
private String envVersion = "release";
2528

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testCreateWxaCodeBytes() throws WxErrorException {
5252

5353
@Test
5454
public void testCreateWxaCodeUnlimitBytes() throws WxErrorException {
55-
final byte[] wxCode = this.wxService.getQrcodeService().createWxaCodeUnlimitBytes("111", null, "trial", 122, true, null, false);
55+
final byte[] wxCode = this.wxService.getQrcodeService().createWxaCodeUnlimitBytes("111", "pages/unknown", false, "trial", 122, true, null, false);
5656
assertThat(wxCode).isNotNull();
5757
}
5858

0 commit comments

Comments
 (0)