1
0
mirror of synced 2025-12-21 16:38:01 +08:00

#844 整合优化ticket管理相关接口代码,方便获取sdk_ticket、jsapi_ticket和card_api_ticket等。

This commit is contained in:
Binary Wang
2018-11-18 15:45:02 +08:00
parent 1cd06082aa
commit 49633cd123
11 changed files with 369 additions and 443 deletions

View File

@@ -1,38 +0,0 @@
package me.chanjar.weixin.mp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.apache.commons.lang3.StringUtils;
import org.testng.*;
import org.testng.annotations.*;
/**
* 基础API测试
*
* @author chanjarster
*/
@Test(groups = "baseAPI")
@Guice(modules = ApiTestModule.class)
public class WxMpBaseAPITest {
@Inject
protected WxMpService wxService;
public void testRefreshAccessToken() throws WxErrorException {
WxMpConfigStorage configStorage = this.wxService.getWxMpConfigStorage();
String before = configStorage.getAccessToken();
this.wxService.getAccessToken(false);
String after = configStorage.getAccessToken();
Assert.assertNotEquals(before, after);
Assert.assertTrue(StringUtils.isNotBlank(after));
}
public void testJsapiTicket() throws WxErrorException {
String jsapiTicket = this.wxService.getJsapiTicket(false);
System.out.println(jsapiTicket);
Assert.assertNotNull(jsapiTicket);
}
}

View File

@@ -1,14 +1,18 @@
package me.chanjar.weixin.mp.api.impl;
import org.apache.commons.lang3.StringUtils;
import org.testng.*;
import org.testng.annotations.*;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
import org.testng.*;
import org.testng.annotations.*;
import me.chanjar.weixin.mp.enums.TicketType;
import static org.testng.Assert.*;
@@ -40,4 +44,19 @@ public class WxMpServiceImplTest {
System.out.println(qrConnectUrl);
}
public void testGetTicket() throws WxErrorException {
String ticket = this.wxService.getTicket(TicketType.SDK, false);
System.out.println(ticket);
Assert.assertNotNull(ticket);
}
public void testRefreshAccessToken() throws WxErrorException {
WxMpConfigStorage configStorage = this.wxService.getWxMpConfigStorage();
String before = configStorage.getAccessToken();
this.wxService.getAccessToken(false);
String after = configStorage.getAccessToken();
Assert.assertNotEquals(before, after);
Assert.assertTrue(StringUtils.isNotBlank(after));
}
}

View File

@@ -1,18 +1,19 @@
package me.chanjar.weixin.mp.demo;
import java.io.InputStream;
import java.util.concurrent.locks.ReentrantLock;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import java.io.InputStream;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author Daniel Qian
*/
@XStreamAlias("xml")
class WxMpDemoInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
private static final long serialVersionUID = -3706236839197109704L;
public static WxMpDemoInMemoryConfigStorage fromXml(InputStream is) {
XStream xstream = XStreamInitializer.getInstance();
@@ -24,10 +25,4 @@ class WxMpDemoInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
return wxMpDemoInMemoryConfigStorage;
}
@Override
public String toString() {
return "SimpleWxConfigProvider [appId=" + this.appId + ", secret=" + this.secret + ", accessToken=" + this.accessToken
+ ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + ", templateId=" + this.templateId + "]";
}
}