🎨 #3005【小程序/公众号】提供更新access_token的消费接口
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.bean.WxAccessTokenEntity;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxMpErrorMsgEnum;
|
||||
@@ -46,6 +47,35 @@ public class WxMaServiceImplTest {
|
||||
assertTrue(StringUtils.isNotBlank(after));
|
||||
}
|
||||
|
||||
|
||||
private void updateAccessTokenBefore(WxAccessTokenEntity wxAccessTokenEntity) {
|
||||
System.out.println("token:" + wxAccessTokenEntity.toString());
|
||||
}
|
||||
|
||||
public void testTokenCallBack() throws WxErrorException {
|
||||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||
WxMaConfig configStorage = this.wxService.getWxMaConfig();
|
||||
config.setAppid(configStorage.getAppid());
|
||||
config.setSecret(configStorage.getSecret());
|
||||
// //第一种方式
|
||||
// config.setUpdateAccessTokenBefore(e -> {
|
||||
// System.out.println("token:" + e.toString());
|
||||
// });
|
||||
//第二种方式
|
||||
config.setUpdateAccessTokenBefore(this::updateAccessTokenBefore);
|
||||
this.wxService.setWxMaConfig(config);
|
||||
|
||||
String before = config.getAccessToken();
|
||||
this.wxService.getAccessToken(true);
|
||||
String after = config.getAccessToken();
|
||||
assertNotEquals(before, after);
|
||||
assertTrue(StringUtils.isNotBlank(after));
|
||||
config.enableUpdateAccessTokenBefore(false);
|
||||
this.wxService.getAccessToken(true);
|
||||
after = config.getAccessToken();
|
||||
System.out.println(after);
|
||||
}
|
||||
|
||||
public void testStableRefreshAccessToken() throws WxErrorException {
|
||||
WxMaConfig configStorage = this.wxMaServiceOkHttp.getWxMaConfig();
|
||||
configStorage.useStableAccessToken(true);
|
||||
@@ -56,6 +86,7 @@ public class WxMaServiceImplTest {
|
||||
assertTrue(StringUtils.isNotBlank(after));
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = {WxErrorException.class})
|
||||
public void testGetPaidUnionId() throws WxErrorException {
|
||||
final String unionId = this.wxService.getPaidUnionId("1", null, "3", "4");
|
||||
|
||||
Reference in New Issue
Block a user