@@ -26,44 +26,52 @@ public WxMpQrcodeServiceImpl(WxMpService wxMpService) {
2626 }
2727
2828 @ Override
29- public WxMpQrCodeTicket qrCodeCreateTmpTicket (int scene_id , Integer expire_seconds ) throws WxErrorException {
29+ public WxMpQrCodeTicket qrCodeCreateTmpTicket (int sceneId , Integer expireSeconds ) throws WxErrorException {
30+ if (sceneId == 0 ) {
31+ throw new WxErrorException (WxError .newBuilder ().setErrorCode (-1 ).setErrorMsg ("临时二维码场景只不能为0!" ).build ());
32+ }
33+
3034 String url = API_URL_PREFIX + "/create" ;
3135 JsonObject json = new JsonObject ();
3236 json .addProperty ("action_name" , "QR_SCENE" );
33- if (expire_seconds != null ) {
34- json .addProperty ("expire_seconds" , expire_seconds );
37+ if (expireSeconds != null ) {
38+ json .addProperty ("expire_seconds" , expireSeconds );
3539 }
3640 JsonObject actionInfo = new JsonObject ();
3741 JsonObject scene = new JsonObject ();
38- scene .addProperty ("scene_id" , scene_id );
42+ scene .addProperty ("scene_id" , sceneId );
3943 actionInfo .add ("scene" , scene );
4044 json .add ("action_info" , actionInfo );
4145 String responseContent = this .wxMpService .execute (new SimplePostRequestExecutor (), url , json .toString ());
4246 return WxMpQrCodeTicket .fromJson (responseContent );
4347 }
4448
4549 @ Override
46- public WxMpQrCodeTicket qrCodeCreateLastTicket (int scene_id ) throws WxErrorException {
50+ public WxMpQrCodeTicket qrCodeCreateLastTicket (int sceneId ) throws WxErrorException {
51+ if (sceneId < 1 || sceneId > 100000 ) {
52+ throw new WxErrorException (WxError .newBuilder ().setErrorCode (-1 ).setErrorMsg ("永久二维码的场景值目前只支持1--100000!" ).build ());
53+ }
54+
4755 String url = API_URL_PREFIX + "/create" ;
4856 JsonObject json = new JsonObject ();
4957 json .addProperty ("action_name" , "QR_LIMIT_SCENE" );
5058 JsonObject actionInfo = new JsonObject ();
5159 JsonObject scene = new JsonObject ();
52- scene .addProperty ("scene_id" , scene_id );
60+ scene .addProperty ("scene_id" , sceneId );
5361 actionInfo .add ("scene" , scene );
5462 json .add ("action_info" , actionInfo );
5563 String responseContent = this .wxMpService .execute (new SimplePostRequestExecutor (), url , json .toString ());
5664 return WxMpQrCodeTicket .fromJson (responseContent );
5765 }
5866
5967 @ Override
60- public WxMpQrCodeTicket qrCodeCreateLastTicket (String scene_str ) throws WxErrorException {
68+ public WxMpQrCodeTicket qrCodeCreateLastTicket (String sceneStr ) throws WxErrorException {
6169 String url = API_URL_PREFIX + "/create" ;
6270 JsonObject json = new JsonObject ();
6371 json .addProperty ("action_name" , "QR_LIMIT_STR_SCENE" );
6472 JsonObject actionInfo = new JsonObject ();
6573 JsonObject scene = new JsonObject ();
66- scene .addProperty ("scene_str" , scene_str );
74+ scene .addProperty ("scene_str" , sceneStr );
6775 actionInfo .add ("scene" , scene );
6876 json .add ("action_info" , actionInfo );
6977 String responseContent = this .wxMpService .execute (new SimplePostRequestExecutor (), url , json .toString ());
@@ -81,15 +89,15 @@ public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErr
8189 String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s" ;
8290 try {
8391 String resultUrl = String .format (url ,
84- URLEncoder .encode (ticket , StandardCharsets .UTF_8 .name ()));
92+ URLEncoder .encode (ticket , StandardCharsets .UTF_8 .name ()));
8593 if (needShortUrl ) {
8694 return this .wxMpService .shortUrl (resultUrl );
8795 }
8896
8997 return resultUrl ;
9098 } catch (UnsupportedEncodingException e ) {
9199 WxError error = WxError .newBuilder ().setErrorCode (-1 )
92- .setErrorMsg (e .getMessage ()).build ();
100+ .setErrorMsg (e .getMessage ()).build ();
93101 throw new WxErrorException (error );
94102 }
95103 }
0 commit comments