mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	添加换取二维码图片url地址的重构方法(可以选择是否生成压缩的网址)
This commit is contained in:
		| @ -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,11 +519,16 @@ 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(); | ||||||
| @ -531,6 +536,11 @@ public class WxMpServiceImpl implements WxMpService { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|    |    | ||||||
|  |   @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 { | ||||||
|     String url = "https://api.weixin.qq.com/cgi-bin/shorturl"; |     String url = "https://api.weixin.qq.com/cgi-bin/shorturl"; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 BinaryWang
					BinaryWang