diff --git a/src/main/java/chanjarster/weixin/api/WxService.java b/src/main/java/chanjarster/weixin/api/WxService.java index b9d85249..f298d7fa 100644 --- a/src/main/java/chanjarster/weixin/api/WxService.java +++ b/src/main/java/chanjarster/weixin/api/WxService.java @@ -294,6 +294,17 @@ public interface WxService { */ public WxQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException; + /** + *
+ * 换取二维码图片 + * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码 + *+ * @param ticket 二维码ticket + * @return + * @throws WxErrorException + */ + public File qrCodePicture(WxQrCodeTicket ticket) throws WxErrorException; + /** * 注入 {@link WxConfigStorage} 的实现 * @param wxConfigProvider diff --git a/src/main/java/chanjarster/weixin/api/WxServiceImpl.java b/src/main/java/chanjarster/weixin/api/WxServiceImpl.java index e175ad3d..ec9838e9 100644 --- a/src/main/java/chanjarster/weixin/api/WxServiceImpl.java +++ b/src/main/java/chanjarster/weixin/api/WxServiceImpl.java @@ -35,9 +35,10 @@ import chanjarster.weixin.bean.result.WxQrCodeTicket; import chanjarster.weixin.bean.result.WxUser; import chanjarster.weixin.bean.result.WxUserList; import chanjarster.weixin.exception.WxErrorException; -import chanjarster.weixin.util.fs.FileUtil; +import chanjarster.weixin.util.fs.FileUtils; import chanjarster.weixin.util.http.MediaDownloadRequestExecutor; import chanjarster.weixin.util.http.MediaUploadRequestExecutor; +import chanjarster.weixin.util.http.QrCodeRequestExecutor; import chanjarster.weixin.util.http.RequestExecutor; import chanjarster.weixin.util.http.SimpleGetRequestExecutor; import chanjarster.weixin.util.http.SimplePostRequestExecutor; @@ -161,7 +162,7 @@ public class WxServiceImpl implements WxService { } public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException { - return mediaUpload(mediaType,FileUtil.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType)); + return mediaUpload(mediaType,FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType)); } public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException { @@ -293,6 +294,11 @@ public class WxServiceImpl implements WxService { return WxQrCodeTicket.fromJson(responseContent); } + public File qrCodePicture(WxQrCodeTicket ticket) throws WxErrorException { + String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode"; + return execute(new QrCodeRequestExecutor(), url, ticket); + } + /** * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求 * @param executor diff --git a/src/main/java/chanjarster/weixin/util/fs/FileUtil.java b/src/main/java/chanjarster/weixin/util/fs/FileUtils.java similarity index 97% rename from src/main/java/chanjarster/weixin/util/fs/FileUtil.java rename to src/main/java/chanjarster/weixin/util/fs/FileUtils.java index 3faeb4dd..85386b60 100644 --- a/src/main/java/chanjarster/weixin/util/fs/FileUtil.java +++ b/src/main/java/chanjarster/weixin/util/fs/FileUtils.java @@ -5,7 +5,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -public class FileUtil { +public class FileUtils { /** * 创建临时文件 diff --git a/src/main/java/chanjarster/weixin/util/http/MediaDownloadRequestExecutor.java b/src/main/java/chanjarster/weixin/util/http/MediaDownloadRequestExecutor.java index 46e563d5..0433b783 100644 --- a/src/main/java/chanjarster/weixin/util/http/MediaDownloadRequestExecutor.java +++ b/src/main/java/chanjarster/weixin/util/http/MediaDownloadRequestExecutor.java @@ -15,10 +15,10 @@ import org.apache.http.entity.ContentType; import chanjarster.weixin.bean.result.WxError; import chanjarster.weixin.exception.WxErrorException; -import chanjarster.weixin.util.fs.FileUtil; +import chanjarster.weixin.util.fs.FileUtils; /** - * 下载媒体文件请求执行器,请求的参数是String, 返回的结果是String + * 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File * @author chanjarster * */ @@ -52,7 +52,7 @@ public class MediaDownloadRequestExecutor implements RequestExecutor