1
0
mirror of synced 2025-12-21 08:30:11 +08:00

添加多客服中客服管理的6个接口

This commit is contained in:
BinaryWang
2016-07-04 17:31:45 +08:00
parent 1ebcd9c864
commit e169bcc2e9
13 changed files with 725 additions and 24 deletions

View File

@@ -1,24 +1,36 @@
package me.chanjar.weixin.mp.api;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.lang3.builder.ToStringBuilder;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import java.io.InputStream;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.mp.api.impl.WxMpKefuServiceImpl;
public class ApiTestModule implements Module {
@Override
public void configure(Binder binder) {
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxXmlMpInMemoryConfigStorage config = fromXml(WxXmlMpInMemoryConfigStorage.class, is1);
WxMpServiceImpl wxService = new WxMpServiceImpl();
wxService.setWxMpConfigStorage(config);
try (InputStream is1 = ClassLoader
.getSystemResourceAsStream("test-config.xml")) {
WxXmlMpInMemoryConfigStorage config = fromXml(
WxXmlMpInMemoryConfigStorage.class, is1);
WxMpServiceImpl wxService = new WxMpServiceImpl();
wxService.setWxMpConfigStorage(config);
WxMpKefuService customerService = new WxMpKefuServiceImpl();
wxService.setCustomerService(customerService);
binder.bind(WxMpServiceImpl.class).toInstance(wxService);
binder.bind(WxMpConfigStorage.class).toInstance(config);
binder.bind(WxMpServiceImpl.class).toInstance(wxService);
binder.bind(WxMpConfigStorage.class).toInstance(config);
} catch (IOException e) {
e.printStackTrace();
}
}
public static <T> T fromXml(Class<T> clazz, InputStream is) {
@@ -29,22 +41,24 @@ public class ApiTestModule implements Module {
}
@XStreamAlias("xml")
public static class WxXmlMpInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
public static class WxXmlMpInMemoryConfigStorage
extends WxMpInMemoryConfigStorage {
protected String openId;
public String getOpenId() {
return openId;
return this.openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
@Override
public String toString() {
return "SimpleWxConfigProvider [appId=" + appId + ", secret=" + secret + ", accessToken=" + accessToken
+ ", expiresTime=" + expiresTime + ", token=" + token + ", openId=" + openId + "]";
return ToStringBuilder.reflectionToString(this);
}
}
}

View File

@@ -0,0 +1,70 @@
package me.chanjar.weixin.mp.api.impl;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.customerservice.request.WxMpKfAccountRequest;
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfList;
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfOnlineList;
import java.io.File;
import org.testng.Assert;
/**
* 测试客服相关接口
* @author Binary Wang
*
*/
@Test
@Guice(modules = ApiTestModule.class)
public class WxMpKefuImplTest {
private static final String KF_ACCOUNT = "kf2009@youxintest";
@Inject
protected WxMpServiceImpl wxService;
public void testKfList() throws WxErrorException {
WxMpKfList kfList = this.wxService.getKefuService().kfList();
Assert.assertNotNull(kfList);
System.err.println(kfList);
}
public void testKfOnlineList() throws WxErrorException {
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService().kfOnlineList();
Assert.assertNotNull(kfOnlineList);
System.err.println(kfOnlineList);
}
public void testKfAccountAdd() throws WxErrorException {
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
.kfAccount(KF_ACCOUNT).nickName("我晕").rawPassword("123").build();
Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request));
}
@Test(dependsOnMethods = { "testKfAccountAdd" })
public void testKfAccountUpdate() throws WxErrorException {
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
.kfAccount(KF_ACCOUNT).nickName("我晕").rawPassword("123").build();
Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request));
}
@Test(dependsOnMethods = { "testKfAccountUpdate" })
public void testKfAccountUploadHeadImg() throws WxErrorException {
File imgFile = new File("src\\test\\resources\\mm.jpeg");
boolean result = this.wxService.getKefuService().kfAccountUploadHeadImg(KF_ACCOUNT, imgFile);
Assert.assertTrue(result);
}
@Test(dependsOnMethods = { "testKfAccountUploadHeadImg" })
public void testKfAccountDel() throws WxErrorException {
boolean result = this.wxService.getKefuService().kfAccountDel(KF_ACCOUNT);
Assert.assertTrue(result);
}
}

View File

@@ -0,0 +1,41 @@
package me.chanjar.weixin.mp.bean.result.kefu;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfList;
@Test
public class WxMpKfListTest {
public void testFromJson() {
String json=" {\r\n" +
" \"kf_list\" : [\r\n" +
" {\r\n" +
" \"kf_account\" : \"test1@test\",\r\n" +
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" +
" \"kf_id\" : \"1001\",\r\n" +
" \"kf_nick\" : \"ntest1\"\r\n" +
" },\r\n" +
" {\r\n" +
" \"kf_account\" : \"test2@test\",\r\n" +
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" +
" \"kf_id\" : \"1002\",\r\n" +
" \"kf_nick\" : \"ntest2\"\r\n" +
" },\r\n" +
" {\r\n" +
" \"kf_account\" : \"test3@test\",\r\n" +
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" +
" \"kf_id\" : \"1003\",\r\n" +
" \"kf_nick\" : \"ntest3\"\r\n" +
" }\r\n" +
" ]\r\n" +
" }";
WxMpKfList wxMpKfList = WxMpKfList.fromJson(json);
Assert.assertNotNull(wxMpKfList);
System.err.println(ToStringBuilder.reflectionToString(wxMpKfList));
}
}

View File

@@ -0,0 +1,39 @@
package me.chanjar.weixin.mp.bean.result.kefu;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfOnlineList;
@Test
public class WxMpKfOnlineListTest {
@Test
public void testFromJson() {
String json = "{\r\n" +
" \"kf_online_list\": [\r\n" +
" {\r\n" +
" \"kf_account\": \"test1@test\", \r\n" +
" \"status\": 1, \r\n" +
" \"kf_id\": \"1001\", \r\n" +
" \"auto_accept\": 0, \r\n" +
" \"accepted_case\": 1\r\n" +
" },\r\n" +
" {\r\n" +
" \"kf_account\": \"test2@test\", \r\n" +
" \"status\": 1, \r\n" +
" \"kf_id\": \"1002\", \r\n" +
" \"auto_accept\": 0, \r\n" +
" \"accepted_case\": 2\r\n" +
" }\r\n" +
" ]\r\n" +
"}";
WxMpKfOnlineList wxMpKfOnlineList = WxMpKfOnlineList.fromJson(json);
Assert.assertNotNull(wxMpKfOnlineList);
System.err.println(ToStringBuilder.reflectionToString(wxMpKfOnlineList));
}
}