修正带参数的二维码接口相关文档注释,并加入对有效期的判断

This commit is contained in:
Binary Wang 2017-01-09 16:11:54 +08:00
parent eeb0452d64
commit b1f3b71a09
3 changed files with 22 additions and 12 deletions

View File

@ -7,7 +7,7 @@ import java.io.File;
/**
* 二维码相关操作接口
*
* 文档地址https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435
* @author Binary Wang
*/
public interface WxMpQrcodeService {
@ -15,28 +15,28 @@ public interface WxMpQrcodeService {
/**
* <pre>
* 换取临时二维码ticket
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
* </pre>
*
* @param sceneId 参数
* @param expireSeconds 过期秒数默认60秒最小60秒最大1800秒
* @param sceneId 场景值ID临时二维码时为32位非0整型
* @param expireSeconds 该二维码有效时间以秒为单位 最大不超过2592000即30天此字段如果不填则默认有效期为30秒
*/
WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException;
/**
* <pre>
* 换取永久二维码ticket
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
* </pre>
*
* @param sceneId 参数永久二维码时最大值为100000目前参数只支持1--100000
* @param sceneId 场景值ID最大值为100000目前参数只支持1--100000
*/
WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException;
/**
* <pre>
* 换取永久字符串二维码ticket
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
* </pre>
*
* @param sceneStr 参数字符串类型长度现在为1到64
@ -46,7 +46,7 @@ public interface WxMpQrcodeService {
/**
* <pre>
* 换取二维码图片文件jpg格式
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
* </pre>
*
* @param ticket 二维码ticket
@ -56,7 +56,7 @@ public interface WxMpQrcodeService {
/**
* <pre>
* 换取二维码图片url地址可以选择是否生成压缩的网址
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
* </pre>
*
* @param ticket 二维码ticket
@ -67,7 +67,7 @@ public interface WxMpQrcodeService {
/**
* <pre>
* 换取二维码图片url地址
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435">生成带参数的二维码</a>
* </pre>
*
* @param ticket 二维码ticket

View File

@ -28,7 +28,17 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
@Override
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException {
if (sceneId == 0) {
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景只不能为0").build());
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景值不能为0").build());
}
//expireSeconds 该二维码有效时间以秒为单位 最大不超过2592000即30天此字段如果不填则默认有效期为30秒
if (expireSeconds != null && expireSeconds > 2592000) {
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1)
.setErrorMsg("临时二维码有效时间最大不能超过2592000即30天").build());
}
if (expireSeconds == null) {
expireSeconds = 30;
}
String url = API_URL_PREFIX + "/create";

View File

@ -19,7 +19,7 @@ import java.io.File;
*/
@Test(groups = "qrCodeAPI")
@Guice(modules = ApiTestModule.class)
public class WxMpQrCodeServiceImplTest {
public class WxMpQrcodeServiceImplTest {
@Inject
protected WxMpService wxService;