Skip to content

Commit bc22b03

Browse files
committed
添加换取二维码图片url地址的重构方法(可以选择是否生成压缩的网址)
1 parent 5358d68 commit bc22b03

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,17 @@ public interface WxMpService {
511511
*/
512512
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException;
513513

514+
/**
515+
* <pre>
516+
* 换取二维码图片url地址(可以选择是否生成压缩的网址)
517+
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
518+
* </pre>
519+
* @param ticket 二维码ticket
520+
* @param needShortUrl 是否需要压缩的二维码地址
521+
* @return
522+
* @throws WxErrorException
523+
*/
524+
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException;
514525
/**
515526
* <pre>
516527
* 换取二维码图片url地址

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,27 @@ public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException {
519519
}
520520

521521
@Override
522-
public String qrCodePictureUrl(String ticket) throws WxErrorException {
522+
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException {
523523
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s";
524524
try {
525-
return this.shortUrl(String.format(url,
526-
URLEncoder.encode(ticket, Charsets.UTF_8.name())));
525+
String resultUrl = String.format(url,
526+
URLEncoder.encode(ticket, Charsets.UTF_8.name()));
527+
if(needShortUrl){
528+
return this.shortUrl(resultUrl);
529+
}
530+
531+
return resultUrl;
527532
} catch (UnsupportedEncodingException e) {
528533
WxError error = WxError.newBuilder().setErrorCode(-1)
529534
.setErrorMsg(e.getMessage()).build();
530535
throw new WxErrorException(error);
531536
}
532537
}
538+
539+
@Override
540+
public String qrCodePictureUrl(String ticket) throws WxErrorException {
541+
return qrCodePictureUrl(ticket, false);
542+
}
533543

534544
@Override
535545
public String shortUrl(String long_url) throws WxErrorException {

0 commit comments

Comments
 (0)