@Test(dataProvider = "sceneIds") public void testQrCodeCreateTmpTicket(int sceneId) throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(sceneId, null); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); Assert.assertTrue(ticket.getExpireSeconds() != -1); System.out.println(ticket); }
@Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0！").build()); } if (expireSeconds != null && expireSeconds > 2592000) { throw new WxErrorException(WxError.builder().errorCode(-1) .errorMsg("临时二维码有效时间最大不能超过2592000（即30天）！").build()); } if (expireSeconds == null) { expireSeconds = 30; } String url = API_URL_PREFIX + "/create"; JsonObject json = new JsonObject(); json.addProperty("action_name", "QR_SCENE"); json.addProperty("expire_seconds", expireSeconds); JsonObject actionInfo = new JsonObject(); JsonObject scene = new JsonObject(); scene.addProperty("scene_id", sceneId); actionInfo.add("scene", scene); json.add("action_info", actionInfo); String responseContent = this.wxMpService.post(url, json.toString()); return WxMpQrCodeTicket.fromJson(responseContent); }
WxMpQrcodeServiceImpl implements WxMpQrcodeService { @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0！").build()); } if (expireSeconds != null && expireSeconds > 2592000) { throw new WxErrorException(WxError.builder().errorCode(-1) .errorMsg("临时二维码有效时间最大不能超过2592000（即30天）！").build()); } if (expireSeconds == null) { expireSeconds = 30; } String url = API_URL_PREFIX + "/create"; JsonObject json = new JsonObject(); json.addProperty("action_name", "QR_SCENE"); json.addProperty("expire_seconds", expireSeconds); JsonObject actionInfo = new JsonObject(); JsonObject scene = new JsonObject(); scene.addProperty("scene_id", sceneId); actionInfo.add("scene", scene); json.add("action_info", actionInfo); String responseContent = this.wxMpService.post(url, json.toString()); return WxMpQrCodeTicket.fromJson(responseContent); } }
WxMpQrcodeServiceImpl implements WxMpQrcodeService { @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0！").build()); } if (expireSeconds != null && expireSeconds > 2592000) { throw new WxErrorException(WxError.builder().errorCode(-1) .errorMsg("临时二维码有效时间最大不能超过2592000（即30天）！").build()); } if (expireSeconds == null) { expireSeconds = 30; } String url = API_URL_PREFIX + "/create"; JsonObject json = new JsonObject(); json.addProperty("action_name", "QR_SCENE"); json.addProperty("expire_seconds", expireSeconds); JsonObject actionInfo = new JsonObject(); JsonObject scene = new JsonObject(); scene.addProperty("scene_id", sceneId); actionInfo.add("scene", scene); json.add("action_info", actionInfo); String responseContent = this.wxMpService.post(url, json.toString()); return WxMpQrCodeTicket.fromJson(responseContent); } WxMpQrcodeServiceImpl(WxMpService wxMpService); }
WxMpQrcodeServiceImpl implements WxMpQrcodeService { @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0！").build()); } if (expireSeconds != null && expireSeconds > 2592000) { throw new WxErrorException(WxError.builder().errorCode(-1) .errorMsg("临时二维码有效时间最大不能超过2592000（即30天）！").build()); } if (expireSeconds == null) { expireSeconds = 30; } String url = API_URL_PREFIX + "/create"; JsonObject json = new JsonObject(); json.addProperty("action_name", "QR_SCENE"); json.addProperty("expire_seconds", expireSeconds); JsonObject actionInfo = new JsonObject(); JsonObject scene = new JsonObject(); scene.addProperty("scene_id", sceneId); actionInfo.add("scene", scene); json.add("action_info", actionInfo); String responseContent = this.wxMpService.post(url, json.toString()); return WxMpQrCodeTicket.fromJson(responseContent); } WxMpQrcodeServiceImpl(WxMpService wxMpService); @Override WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds); @Override WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds); @Override WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId); @Override WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr); @Override File qrCodePicture(WxMpQrCodeTicket ticket); @Override String qrCodePictureUrl(String ticket, boolean needShortUrl); @Override String qrCodePictureUrl(String ticket); }
WxMpQrcodeServiceImpl implements WxMpQrcodeService { @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0！").build()); } if (expireSeconds != null && expireSeconds > 2592000) { throw new WxErrorException(WxError.builder().errorCode(-1) .errorMsg("临时二维码有效时间最大不能超过2592000（即30天）！").build()); } if (expireSeconds == null) { expireSeconds = 30; } String url = API_URL_PREFIX + "/create"; JsonObject json = new JsonObject(); json.addProperty("action_name", "QR_SCENE"); json.addProperty("expire_seconds", expireSeconds); JsonObject actionInfo = new JsonObject(); JsonObject scene = new JsonObject(); scene.addProperty("scene_id", sceneId); actionInfo.add("scene", scene); json.add("action_info", actionInfo); String responseContent = this.wxMpService.post(url, json.toString()); return WxMpQrCodeTicket.fromJson(responseContent); } WxMpQrcodeServiceImpl(WxMpService wxMpService); @Override WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds); @Override WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds); @Override WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId); @Override WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr); @Override File qrCodePicture(WxMpQrCodeTicket ticket); @Override String qrCodePictureUrl(String ticket, boolean needShortUrl); @Override String qrCodePictureUrl(String ticket);  }