|
|
@@ -26,16 +26,20 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException { |
|
|
|
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { |
|
|
|
if (sceneId == 0) { |
|
|
|
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景只不能为0!").build()); |
|
|
|
} |
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/create"; |
|
|
|
JsonObject json = new JsonObject(); |
|
|
|
json.addProperty("action_name", "QR_SCENE"); |
|
|
|
if (expire_seconds != null) { |
|
|
|
json.addProperty("expire_seconds", expire_seconds); |
|
|
|
if (expireSeconds != null) { |
|
|
|
json.addProperty("expire_seconds", expireSeconds); |
|
|
|
} |
|
|
|
JsonObject actionInfo = new JsonObject(); |
|
|
|
JsonObject scene = new JsonObject(); |
|
|
|
scene.addProperty("scene_id", scene_id); |
|
|
|
scene.addProperty("scene_id", sceneId); |
|
|
|
actionInfo.add("scene", scene); |
|
|
|
json.add("action_info", actionInfo); |
|
|
|
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); |
|
|
@@ -43,13 +47,17 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException { |
|
|
|
public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException { |
|
|
|
if (sceneId < 1 || sceneId > 100000) { |
|
|
|
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("永久二维码的场景值目前只支持1--100000!").build()); |
|
|
|
} |
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/create"; |
|
|
|
JsonObject json = new JsonObject(); |
|
|
|
json.addProperty("action_name", "QR_LIMIT_SCENE"); |
|
|
|
JsonObject actionInfo = new JsonObject(); |
|
|
|
JsonObject scene = new JsonObject(); |
|
|
|
scene.addProperty("scene_id", scene_id); |
|
|
|
scene.addProperty("scene_id", sceneId); |
|
|
|
actionInfo.add("scene", scene); |
|
|
|
json.add("action_info", actionInfo); |
|
|
|
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); |
|
|
@@ -57,13 +65,13 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException { |
|
|
|
public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException { |
|
|
|
String url = API_URL_PREFIX + "/create"; |
|
|
|
JsonObject json = new JsonObject(); |
|
|
|
json.addProperty("action_name", "QR_LIMIT_STR_SCENE"); |
|
|
|
JsonObject actionInfo = new JsonObject(); |
|
|
|
JsonObject scene = new JsonObject(); |
|
|
|
scene.addProperty("scene_str", scene_str); |
|
|
|
scene.addProperty("scene_str", sceneStr); |
|
|
|
actionInfo.add("scene", scene); |
|
|
|
json.add("action_info", actionInfo); |
|
|
|
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); |
|
|
@@ -81,7 +89,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { |
|
|
|
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s"; |
|
|
|
try { |
|
|
|
String resultUrl = String.format(url, |
|
|
|
URLEncoder.encode(ticket, StandardCharsets.UTF_8.name())); |
|
|
|
URLEncoder.encode(ticket, StandardCharsets.UTF_8.name())); |
|
|
|
if (needShortUrl) { |
|
|
|
return this.wxMpService.shortUrl(resultUrl); |
|
|
|
} |
|
|
@@ -89,7 +97,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { |
|
|
|
return resultUrl; |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
WxError error = WxError.newBuilder().setErrorCode(-1) |
|
|
|
.setErrorMsg(e.getMessage()).build(); |
|
|
|
.setErrorMsg(e.getMessage()).build(); |
|
|
|
throw new WxErrorException(error); |
|
|
|
} |
|
|
|
} |
|
|
|