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;
|
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>
|
* <pre>
|
||||||
* 换取二维码图片url地址
|
* 换取二维码图片url地址
|
||||||
|
@ -519,17 +519,27 @@ public class WxMpServiceImpl implements WxMpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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";
|
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s";
|
||||||
try {
|
try {
|
||||||
return this.shortUrl(String.format(url,
|
String resultUrl = String.format(url,
|
||||||
URLEncoder.encode(ticket, Charsets.UTF_8.name())));
|
URLEncoder.encode(ticket, Charsets.UTF_8.name()));
|
||||||
|
if(needShortUrl){
|
||||||
|
return this.shortUrl(resultUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultUrl;
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
WxError error = WxError.newBuilder().setErrorCode(-1)
|
WxError error = WxError.newBuilder().setErrorCode(-1)
|
||||||
.setErrorMsg(e.getMessage()).build();
|
.setErrorMsg(e.getMessage()).build();
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String qrCodePictureUrl(String ticket) throws WxErrorException {
|
||||||
|
return qrCodePictureUrl(ticket, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String shortUrl(String long_url) throws WxErrorException {
|
public String shortUrl(String long_url) throws WxErrorException {
|
||||||
|
Loading…
Reference in New Issue
Block a user