File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -508,6 +508,17 @@ public interface WxMpService {
508508 */
509509 public File qrCodePicture (WxMpQrCodeTicket ticket ) throws WxErrorException ;
510510
511+ /**
512+ * <pre>
513+ * 换取二维码图片url地址
514+ * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
515+ * </pre>
516+ * @param ticket 二维码ticket
517+ * @return
518+ * @throws WxErrorException
519+ */
520+ public String qrCodePictureUrl (String ticket ) throws WxErrorException ;
521+
511522 /**
512523 * <pre>
513524 * 长链接转短链接接口
Original file line number Diff line number Diff line change 4646import java .io .IOException ;
4747import java .io .InputStream ;
4848import java .io .StringReader ;
49+ import java .io .UnsupportedEncodingException ;
50+ import java .net .URLEncoder ;
4951import java .security .NoSuchAlgorithmException ;
5052import java .util .*;
5153import java .util .Map .Entry ;
@@ -472,6 +474,19 @@ public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException {
472474 return execute (new QrCodeRequestExecutor (), url , ticket );
473475 }
474476
477+ @ Override
478+ public String qrCodePictureUrl (String ticket ) throws WxErrorException {
479+ String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s" ;
480+ try {
481+ return String .format (url , URLEncoder .encode (ticket , "utf-8" ));
482+ } catch (UnsupportedEncodingException e ) {
483+ WxError error = new WxError ();
484+ error .setErrorCode (-1 );
485+ error .setErrorMsg (e .getMessage ());
486+ throw new WxErrorException (error );
487+ }
488+ }
489+
475490 public String shortUrl (String long_url ) throws WxErrorException {
476491 String url = "https://api.weixin.qq.com/cgi-bin/shorturl" ;
477492 JsonObject o = new JsonObject ();
You can’t perform that action at this time.
0 commit comments