Skip to content

Commit b1f3b71

Browse files
committed
修正带参数的二维码接口相关文档注释,并加入对有效期的判断
1 parent eeb0452 commit b1f3b71

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@
77

88
/**
99
* 二维码相关操作接口
10-
*
10+
* 文档地址:https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435
1111
* @author Binary Wang
1212
*/
1313
public interface WxMpQrcodeService {
1414

1515
/**
1616
* <pre>
1717
* 换取临时二维码ticket
18-
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
18+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
1919
* </pre>
2020
*
21-
* @param sceneId 参数。
22-
* @param expireSeconds 过期秒数,默认60秒,最小60秒,最大1800秒
21+
* @param sceneId 场景值ID,临时二维码时为32位非0整型
22+
* @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
2323
*/
2424
WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException;
2525

2626
/**
2727
* <pre>
2828
* 换取永久二维码ticket
29-
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
29+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
3030
* </pre>
3131
*
32-
* @param sceneId 参数。永久二维码时最大值为100000(目前参数只支持1--100000)
32+
* @param sceneId 场景值ID,最大值为100000(目前参数只支持1--100000)
3333
*/
3434
WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException;
3535

3636
/**
3737
* <pre>
3838
* 换取永久字符串二维码ticket
39-
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
39+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
4040
* </pre>
4141
*
4242
* @param sceneStr 参数。字符串类型长度现在为1到64
@@ -46,7 +46,7 @@ public interface WxMpQrcodeService {
4646
/**
4747
* <pre>
4848
* 换取二维码图片文件,jpg格式
49-
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
49+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
5050
* </pre>
5151
*
5252
* @param ticket 二维码ticket
@@ -56,7 +56,7 @@ public interface WxMpQrcodeService {
5656
/**
5757
* <pre>
5858
* 换取二维码图片url地址(可以选择是否生成压缩的网址)
59-
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
59+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
6060
* </pre>
6161
*
6262
* @param ticket 二维码ticket
@@ -67,7 +67,7 @@ public interface WxMpQrcodeService {
6767
/**
6868
* <pre>
6969
* 换取二维码图片url地址
70-
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
70+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
7171
* </pre>
7272
*
7373
* @param ticket 二维码ticket

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ public WxMpQrcodeServiceImpl(WxMpService wxMpService) {
2828
@Override
2929
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException {
3030
if (sceneId == 0) {
31-
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景只不能为0!").build());
31+
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景值不能为0!").build());
32+
}
33+
34+
//expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
35+
if (expireSeconds != null && expireSeconds > 2592000) {
36+
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1)
37+
.setErrorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build());
38+
}
39+
40+
if (expireSeconds == null) {
41+
expireSeconds = 30;
3242
}
3343

3444
String url = API_URL_PREFIX + "/create";

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
@Test(groups = "qrCodeAPI")
2121
@Guice(modules = ApiTestModule.class)
22-
public class WxMpQrCodeServiceImplTest {
22+
public class WxMpQrcodeServiceImplTest {
2323
@Inject
2424
protected WxMpService wxService;
2525

0 commit comments

Comments
 (0)