mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 22:11:40 +08:00
添加换取二维码图片url地址的重构方法(可以选择是否生成压缩的网址)
This commit is contained in:
parent
5358d68fff
commit
bc22b03ea3
@ -511,6 +511,17 @@ public interface WxMpService {
|
||||
*/
|
||||
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片url地址(可以选择是否生成压缩的网址)
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
* @param ticket 二维码ticket
|
||||
* @param needShortUrl 是否需要压缩的二维码地址
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException;
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片url地址
|
||||
|
@ -519,11 +519,16 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String qrCodePictureUrl(String ticket) throws WxErrorException {
|
||||
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException {
|
||||
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s";
|
||||
try {
|
||||
return this.shortUrl(String.format(url,
|
||||
URLEncoder.encode(ticket, Charsets.UTF_8.name())));
|
||||
String resultUrl = String.format(url,
|
||||
URLEncoder.encode(ticket, Charsets.UTF_8.name()));
|
||||
if(needShortUrl){
|
||||
return this.shortUrl(resultUrl);
|
||||
}
|
||||
|
||||
return resultUrl;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
WxError error = WxError.newBuilder().setErrorCode(-1)
|
||||
.setErrorMsg(e.getMessage()).build();
|
||||
@ -531,6 +536,11 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String qrCodePictureUrl(String ticket) throws WxErrorException {
|
||||
return qrCodePictureUrl(ticket, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortUrl(String long_url) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/shorturl";
|
||||
|
Loading…
Reference in New Issue
Block a user