From 9e3f256032a0ba5cdc356c5d88417bd3b57ae9d0 Mon Sep 17 00:00:00 2001 From: hywr <33077958+hywr@users.noreply.github.com> Date: Sun, 18 Jul 2021 23:04:48 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2206=20=E3=80=90=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E3=80=91=E5=A2=9E=E5=8A=A0=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=B9=B3=E5=8F=B0=E5=90=AF=E5=8A=A8ticket=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/api/WxOpenComponentService.java | 15 +- .../api/impl/WxOpenComponentServiceImpl.java | 11 + .../impl/WxOpenComponentServiceImplTest.java | 236 ++++++++++-------- .../weixin/open/test/ApiTestModule.java | 2 + 4 files changed, 150 insertions(+), 114 deletions(-) diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java index 9c771c392..48f727ac3 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java @@ -1,10 +1,8 @@ package me.chanjar.weixin.open.api; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; -import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult; -import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken; +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.open.bean.WxOpenCreateResult; @@ -31,6 +29,10 @@ public interface WxOpenComponentService { * The constant API_COMPONENT_TOKEN_URL. */ String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"; + /** + * 启动ticket推送服务 + */ + String API_START_PUSH_TICKET = "https://api.weixin.qq.com/cgi-bin/component/api_start_push_ticket"; /** * The constant API_CREATE_PREAUTHCODE_URL. */ @@ -220,6 +222,13 @@ public interface WxOpenComponentService { */ boolean checkSignature(String timestamp, String nonce, String signature); + /** + * 启动ticket推送服务 该 API 用于启动ticket推送服务 + * + * @throws WxErrorException 如果调用失败返回此异常 + */ + void startPushTicket() throws WxErrorException; + /** * Gets component access token. * diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java index e745b493a..f3ca14696 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java @@ -149,6 +149,17 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { } } + @Override + public void startPushTicket() throws WxErrorException { + WxOpenConfigStorage config = getWxOpenConfigStorage(); + + JsonObject json = new JsonObject(); + json.addProperty("component_appid", config.getComponentAppId()); + json.addProperty("component_secret", config.getComponentAppSecret()); + + getWxOpenService().post(API_START_PUSH_TICKET, json.toString()); + } + @Override public String getComponentAccessToken(boolean forceRefresh) throws WxErrorException { final WxOpenConfigStorage config = this.getWxOpenConfigStorage(); diff --git a/weixin-java-open/src/test/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImplTest.java b/weixin-java-open/src/test/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImplTest.java index 47a5069f2..c9fefec02 100644 --- a/weixin-java-open/src/test/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImplTest.java +++ b/weixin-java-open/src/test/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImplTest.java @@ -1,5 +1,10 @@ package me.chanjar.weixin.open.api.impl; +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.open.api.WxOpenComponentService; +import me.chanjar.weixin.open.test.ApiTestModule; +import org.testng.annotations.Guice; import org.testng.annotations.Test; /** @@ -8,153 +13,162 @@ import org.testng.annotations.Test; * @author Binary Wang * @date 2020-06-06 */ +@Guice(modules = ApiTestModule.class) public class WxOpenComponentServiceImplTest { - @Test - public void testGetWxMpServiceByAppid() { - } + @Inject + WxOpenComponentService wxOpenComponentService; - @Test - public void testGetWxMaServiceByAppid() { - } + @Test + public void testGetWxMpServiceByAppid() { + } - @Test - public void testGetWxFastMaServiceByAppid() { - } + @Test + public void testGetWxMaServiceByAppid() { + } - @Test - public void testGetWxOpenService() { - } + @Test + public void testGetWxFastMaServiceByAppid() { + } - @Test - public void testGetWxOpenConfigStorage() { - } + @Test + public void testGetWxOpenService() { + } - @Test - public void testCheckSignature() { - } + @Test + public void testGetWxOpenConfigStorage() { + } - @Test - public void testGetComponentAccessToken() { - } + @Test + public void testCheckSignature() { + } - @Test - public void testPost() { - } + @Test + public void testGetComponentAccessToken() { + } - @Test - public void testTestPost() { - } + @Test + public void testPost() { + } - @Test - public void testGet() { - } + @Test + public void testTestPost() { + } - @Test - public void testTestGet() { - } + @Test + public void testGet() { + } - @Test - public void testGetPreAuthUrl() { - } + @Test + public void testTestGet() { + } - @Test - public void testTestGetPreAuthUrl() { - } + @Test + public void testGetPreAuthUrl() { + } - @Test - public void testGetMobilePreAuthUrl() { - } + @Test + public void testTestGetPreAuthUrl() { + } - @Test - public void testTestGetMobilePreAuthUrl() { - } + @Test + public void testGetMobilePreAuthUrl() { + } - @Test - public void testRoute() { - } + @Test + public void testTestGetMobilePreAuthUrl() { + } - @Test - public void testGetQueryAuth() { - } + @Test + public void testRoute() { + } - @Test - public void testGetAuthorizerInfo() { - } + @Test + public void testGetQueryAuth() { + } - @Test - public void testGetAuthorizerList() { - } + @Test + public void testGetAuthorizerInfo() { + } - @Test - public void testGetAuthorizerOption() { - } + @Test + public void testGetAuthorizerList() { + } - @Test - public void testSetAuthorizerOption() { - } + @Test + public void testGetAuthorizerOption() { + } - @Test - public void testGetAuthorizerAccessToken() { - } + @Test + public void testSetAuthorizerOption() { + } - @Test - public void testOauth2getAccessToken() { - } + @Test + public void testGetAuthorizerAccessToken() { + } - @Test - public void testTestCheckSignature() { - } + @Test + public void testOauth2getAccessToken() { + } - @Test - public void testOauth2refreshAccessToken() { - } + @Test + public void testTestCheckSignature() { + } - @Test - public void testOauth2buildAuthorizationUrl() { - } + @Test + public void testOauth2refreshAccessToken() { + } - @Test - public void testMiniappJscode2Session() { - } + @Test + public void testOauth2buildAuthorizationUrl() { + } - @Test - public void testGetTemplateDraftList() { - } + @Test + public void testMiniappJscode2Session() { + } - @Test - public void testGetTemplateList() { - } + @Test + public void testGetTemplateDraftList() { + } - @Test - public void testAddToTemplate() { - } + @Test + public void testGetTemplateList() { + } - @Test - public void testDeleteTemplate() { - } + @Test + public void testAddToTemplate() { + } - @Test - public void testCreateOpenAccount() { - } + @Test + public void testDeleteTemplate() { + } - @Test - public void testBindOpenAccount() { - } + @Test + public void testCreateOpenAccount() { + } - @Test - public void testUnbindOpenAccount() { - } + @Test + public void testBindOpenAccount() { + } - @Test - public void testGetOpenAccount() { - } + @Test + public void testUnbindOpenAccount() { + } - @Test - public void testFastRegisterWeapp() { - } + @Test + public void testGetOpenAccount() { + } - @Test - public void testFastRegisterWeappSearch() { - } + @Test + public void testFastRegisterWeapp() { + } + + @Test + public void testFastRegisterWeappSearch() { + } + + @Test + public void testStartPushTicket() throws WxErrorException { + wxOpenComponentService.startPushTicket(); + } } diff --git a/weixin-java-open/src/test/java/me/chanjar/weixin/open/test/ApiTestModule.java b/weixin-java-open/src/test/java/me/chanjar/weixin/open/test/ApiTestModule.java index 8a3c3b946..e3abb4d9d 100644 --- a/weixin-java-open/src/test/java/me/chanjar/weixin/open/test/ApiTestModule.java +++ b/weixin-java-open/src/test/java/me/chanjar/weixin/open/test/ApiTestModule.java @@ -5,6 +5,7 @@ import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import me.chanjar.weixin.open.api.WxOpenComponentService; import me.chanjar.weixin.open.api.WxOpenMaService; import me.chanjar.weixin.open.api.WxOpenMpService; import me.chanjar.weixin.open.api.WxOpenService; @@ -33,6 +34,7 @@ public class ApiTestModule implements Module { binder.bind(TestConfigStorage.class).toInstance(config); binder.bind(WxOpenService.class).toInstance(service); + binder.bind(WxOpenComponentService.class).toInstance(service.getWxOpenComponentService()); if (config.getTestMpAppId() != null && !config.getTestMpAppId().isEmpty()) { //如果配置了测试公众号,则构建公众号服务依赖