mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-03 05:41:46 +08:00
优化多公众号支持代码
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2019/3/29.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class BaseWxMpServiceImplTest {
|
||||
@Inject
|
||||
private WxMpService wxService;
|
||||
|
||||
@Test
|
||||
public void testSwitchover() {
|
||||
assertTrue(this.wxService.switchover("another"));
|
||||
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
|
||||
assertFalse(this.wxService.switchover("whatever"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchover1() throws WxErrorException {
|
||||
assertThat(this.wxService.switchover1("another").getAccessToken()).isNotEmpty();
|
||||
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
|
||||
}
|
||||
}
|
||||
@ -9,9 +9,11 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
|
||||
import org.testng.annotations.*;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* 测试菜单
|
||||
@ -19,7 +21,7 @@ import static org.testng.Assert.*;
|
||||
* @author chanjarster
|
||||
* @author Binary Wang
|
||||
*/
|
||||
@Test(groups = "menuAPI")
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpMenuServiceImplTest {
|
||||
|
||||
@ -85,9 +87,6 @@ public class WxMpMenuServiceImplTest {
|
||||
"}";
|
||||
|
||||
this.menuId = this.wxService.getMenuService().menuCreate(json);
|
||||
if (this.wxService.switchover("test-1")) {
|
||||
this.menuId = this.wxService.getMenuService().menuCreate(json);
|
||||
}
|
||||
System.out.println(this.menuId);
|
||||
}
|
||||
|
||||
@ -129,9 +128,7 @@ public class WxMpMenuServiceImplTest {
|
||||
" \"language\":\"zh_CN\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
if (this.wxService.switchover("test-1")) {
|
||||
this.menuId = this.wxService.getMenuService().menuCreate(json);
|
||||
}
|
||||
this.menuId = this.wxService.getMenuService().menuCreate(json);
|
||||
System.out.println(this.menuId);
|
||||
}
|
||||
|
||||
@ -194,7 +191,7 @@ public class WxMpMenuServiceImplTest {
|
||||
System.out.println(wxMenu.toJson());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testMenuGet","testMenuCreate"})
|
||||
@Test(dependsOnMethods = {"testMenuGet", "testMenuCreate"})
|
||||
public void testMenuDelete() throws WxErrorException {
|
||||
this.wxService.getMenuService().menuDelete();
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@ package me.chanjar.weixin.mp.api.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
|
||||
@ -16,7 +14,6 @@ import com.thoughtworks.xstream.XStream;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl;
|
||||
|
||||
public class ApiTestModule implements Module {
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
@ -31,14 +28,13 @@ public class ApiTestModule implements Module {
|
||||
|
||||
TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream);
|
||||
config.setAccessTokenLock(new ReentrantLock());
|
||||
WxMpService wxMpServiceMulti = new WxMpServiceHttpClientImpl();
|
||||
WxMpService mpService = new WxMpServiceHttpClientImpl();
|
||||
|
||||
// TODO 多WxAppId
|
||||
wxMpServiceMulti.setWxMpConfigStorage(config);
|
||||
wxMpServiceMulti.addWxMpConfigStorage("test-1", config);
|
||||
mpService.setWxMpConfigStorage(config);
|
||||
mpService.addConfigStorage("another", config);
|
||||
|
||||
binder.bind(WxMpConfigStorage.class).toInstance(config);
|
||||
binder.bind(WxMpService.class).toInstance(wxMpServiceMulti);
|
||||
binder.bind(WxMpService.class).toInstance(mpService);
|
||||
} catch (IOException e) {
|
||||
this.log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user