1
0
mirror of synced 2025-12-19 23:08:13 +08:00

🆕 #2998 【小程序】增加获取稳定版接口调用凭据的接口,通过设置WxMaConfig#useStableAccessToken方法去开启使用稳定版接口

This commit is contained in:
FreeOfYou
2023-05-06 19:38:12 +08:00
committed by GitHub
parent 24c18b8bbc
commit c33ee14574
11 changed files with 213 additions and 10 deletions

View File

@@ -33,6 +33,8 @@ public class WxMaServiceImplTest {
@Inject
private WxMaService wxService;
@Inject
private WxMaServiceOkHttpImpl wxMaServiceOkHttp;
public void testRefreshAccessToken() throws WxErrorException {
WxMaConfig configStorage = this.wxService.getWxMaConfig();
@@ -44,6 +46,16 @@ public class WxMaServiceImplTest {
assertTrue(StringUtils.isNotBlank(after));
}
public void testStableRefreshAccessToken() throws WxErrorException {
WxMaConfig configStorage = this.wxMaServiceOkHttp.getWxMaConfig();
configStorage.useStableAccessToken(true);
String before = configStorage.getAccessToken();
this.wxMaServiceOkHttp.getAccessToken(false);
String after = configStorage.getAccessToken();
assertNotEquals(before, after);
assertTrue(StringUtils.isNotBlank(after));
}
@Test(expectedExceptions = {WxErrorException.class})
public void testGetPaidUnionId() throws WxErrorException {
final String unionId = this.wxService.getPaidUnionId("1", null, "3", "4");
@@ -134,7 +146,7 @@ public class WxMaServiceImplTest {
});
try {
Object execute = service.execute(re, "http://baidu.com", new HashMap<>());
Assert.assertTrue(false, "代码应该不会执行到这里");
Assert.fail("代码应该不会执行到这里");
} catch (WxErrorException e) {
Assert.assertEquals(WxMpErrorMsgEnum.CODE_40001.getCode(), e.getError().getErrorCode());
Assert.assertEquals(2, counter.get());

View File

@@ -1,17 +1,17 @@
package cn.binarywang.wx.miniapp.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.locks.ReentrantLock;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceOkHttpImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import com.google.inject.Binder;
import com.google.inject.Module;
import me.chanjar.weixin.common.error.WxRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import com.google.inject.Binder;
import com.google.inject.Module;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
@@ -34,6 +34,11 @@ public class ApiTestModule implements Module {
binder.bind(WxMaService.class).toInstance(wxService);
binder.bind(WxMaConfig.class).toInstance(config);
WxMaServiceOkHttpImpl wxMaServiceOkHttp = new cn.binarywang.wx.miniapp.api.impl.WxMaServiceOkHttpImpl();
wxMaServiceOkHttp.setWxMaConfig(config);
binder.bind(WxMaServiceOkHttpImpl.class).toInstance(wxMaServiceOkHttp);
} catch (IOException e) {
this.log.error(e.getMessage(), e);
}