合并开发分支,发布正式版
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 testSwitchoverTo() throws WxErrorException {
|
||||
assertThat(this.wxService.switchoverTo("another").getAccessToken()).isNotEmpty();
|
||||
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.enums.AiLangType;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import me.chanjar.weixin.mp.enums.AiLangType;
|
||||
|
||||
import java.io.File;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@@ -35,13 +37,12 @@ public class WxMpAiOpenServiceImplTest {
|
||||
String voiceId = System.currentTimeMillis() + "a";
|
||||
AiLangType lang = AiLangType.zh_CN;
|
||||
final String result = this.wxService.getAiOpenService().recogniseVoice(voiceId, lang, new File("d:\\t.mp3"));
|
||||
System.out.println(result);
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslate() throws WxErrorException {
|
||||
final String responseContent = this.wxService.getAiOpenService()
|
||||
.translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹");
|
||||
System.out.println(responseContent);
|
||||
final String result = this.wxService.getAiOpenService().translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
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.bean.result.WxMpCardResult;
|
||||
import org.testng.annotations.*;
|
||||
import me.chanjar.weixin.mp.bean.card.*;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.AssertJUnit.*;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.AssertJUnit.assertNotNull;
|
||||
|
||||
/**
|
||||
* 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码
|
||||
@@ -100,4 +103,107 @@ public class WxMpCardServiceImplTest {
|
||||
assertNotNull(result);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGrouponCard() throws WxErrorException {
|
||||
|
||||
BaseInfo base = new BaseInfo();
|
||||
base.setLogoUrl("http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0");
|
||||
base.setBrandName("测试优惠券");
|
||||
base.setCodeType("CODE_TYPE_QRCODE");
|
||||
base.setTitle("测试标题");
|
||||
base.setColor("Color010");
|
||||
base.setNotice("测试Notice");
|
||||
base.setServicePhone("020-88888888");
|
||||
base.setDescription("不可与其他优惠同享\\n如需团购券发票,请在消费时向商户提出\\n店内均可使用,仅限堂食");
|
||||
DateInfo info = new DateInfo();
|
||||
info.setType("DATE_TYPE_FIX_TERM");
|
||||
info.setFixedBeginTerm(0);
|
||||
info.setFixedTerm(30);
|
||||
base.setDateInfo(info);
|
||||
Sku sku = new Sku();
|
||||
sku.setQuantity(100);
|
||||
base.setSku(sku);
|
||||
base.setGetLimit(1);
|
||||
base.setCanShare(true);
|
||||
base.setCanGiveFriend(true);
|
||||
base.setUseAllLocations(true);
|
||||
base.setCenterTitle("顶部居中按钮");
|
||||
base.setCenterSubTitle("按钮下方的wording");
|
||||
base.setCenterUrl("www.qq.com");
|
||||
base.setCustomUrl("http://www.qq.com");
|
||||
base.setCustomUrlName("立即使用");
|
||||
base.setCustomUrlSubTitle("副标题tip");
|
||||
base.setPromotionUrlName("更多优惠");
|
||||
base.setPromotionUrl("http://www.qq.com");
|
||||
base.setLocationIdList("1234");
|
||||
|
||||
//团购券
|
||||
WxMpCardCreateMessage grouponMessage = new WxMpCardCreateMessage();
|
||||
GrouponCardCreateRequest grouponCardCreateRequest = new GrouponCardCreateRequest();
|
||||
GrouponCard grouponCard = new GrouponCard();
|
||||
grouponCard.setBaseInfo(base);
|
||||
grouponCard.setDealDetail("deal detail");
|
||||
|
||||
grouponCardCreateRequest.setGroupon(grouponCard);
|
||||
grouponMessage.setCardCreateRequest(grouponCardCreateRequest);
|
||||
|
||||
System.out.println(this.wxService.getCardService().createCard(grouponMessage));
|
||||
|
||||
//现金券
|
||||
WxMpCardCreateMessage cashMessage = new WxMpCardCreateMessage();
|
||||
CashCardCreateRequest cashCardCreateRequest = new CashCardCreateRequest();
|
||||
CashCard cashCard = new CashCard();
|
||||
cashCard.setBaseInfo(base);
|
||||
cashCard.setLeastCost(1000);
|
||||
cashCard.setReduceCost(100);
|
||||
|
||||
cashCardCreateRequest.setCash(cashCard);
|
||||
cashMessage.setCardCreateRequest(cashCardCreateRequest);
|
||||
|
||||
System.out.println(this.wxService.getCardService().createCard(cashMessage));
|
||||
|
||||
//折扣券
|
||||
WxMpCardCreateMessage discountMessage = new WxMpCardCreateMessage();
|
||||
DiscountCardCreateRequest discountCardCreateRequest = new DiscountCardCreateRequest();
|
||||
DiscountCard discountCard = new DiscountCard();
|
||||
discountCard.setBaseInfo(base);
|
||||
discountCard.setDiscount(30);
|
||||
|
||||
discountCardCreateRequest.setDiscount(discountCard);
|
||||
discountMessage.setCardCreateRequest(discountCardCreateRequest);
|
||||
|
||||
System.out.println(this.wxService.getCardService().createCard(discountMessage));
|
||||
|
||||
//兑换券
|
||||
WxMpCardCreateMessage giftMessage = new WxMpCardCreateMessage();
|
||||
GiftCardCreateRequest giftCardCreateRequest = new GiftCardCreateRequest();
|
||||
GiftCard giftCard = new GiftCard();
|
||||
giftCard.setBaseInfo(base);
|
||||
giftCard.setGift("星巴克雪瑞纳咖啡大杯");
|
||||
|
||||
giftCardCreateRequest.setGift(giftCard);
|
||||
giftMessage.setCardCreateRequest(giftCardCreateRequest);
|
||||
System.out.println(this.wxService.getCardService().createCard(giftMessage));
|
||||
|
||||
//普通兑换券
|
||||
WxMpCardCreateMessage generalMessage = new WxMpCardCreateMessage();
|
||||
GeneralCardCreateRequest generalCardCreateRequest = new GeneralCardCreateRequest();
|
||||
GeneralCard generalCard = new GeneralCard();
|
||||
generalCard.setBaseInfo(base);
|
||||
generalCard.setDefaultDetail("音乐木盒");
|
||||
|
||||
generalCardCreateRequest.setGeneralCoupon(generalCard);
|
||||
generalMessage.setCardCreateRequest(generalCardCreateRequest);
|
||||
System.out.println(this.wxService.getCardService().createCard(generalMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCard() throws Exception {
|
||||
String cardId = "pwkrWjtw7W4_l50kCQcZ1in1yS6g";
|
||||
WxMpCardDeleteResult result = this.wxService.getCardService().deleteCard(cardId);
|
||||
assertEquals(result.isSuccess(), true);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ public class WxMpMemberCardServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpService wxService;
|
||||
private String cardId = "p2iQk1uwOUYlzHm4s-UYdZnABW88";
|
||||
private String code = "435223630779";
|
||||
private String openId = "o2iQk1u5X-XIJkatmAK1Q8VVuS90";
|
||||
private String cardId = "p4p-v1bKn9tiQHxyO79aKmuTIZlQ";
|
||||
private String code = "224765120681";
|
||||
private String openId = "o4p-v1TIemEIpBSrSrTprkCaG6Xc";
|
||||
|
||||
@Test
|
||||
public void createMemberCard() throws Exception {
|
||||
@@ -150,6 +150,15 @@ public class WxMpMemberCardServiceImplTest {
|
||||
WxMpMemberCardService memberCardService = this.wxService.getMemberCardService();
|
||||
ActivatePluginParam response = memberCardService.getActivatePluginParam(cardId, "test");
|
||||
System.out.println(response);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActivateTempInfo() throws Exception {
|
||||
String activateTicket = "fDZv9eMQAFfrNr3XBoqhb8eUX67DFb6h8yXDelGSMDLfg2OAIGQcU7mEKecnWZBK%2B%2Bvm%2FtZxZJrbRkdJB%2FUmpVoJkEsbeH%2BOefcntAsYDKA%3D";
|
||||
WxMpMemberCardService memberCardService = this.wxService.getMemberCardService();
|
||||
WxMpMemberCardActivateTempInfoResult result = memberCardService.getActivateTempInfo(activateTicket);
|
||||
assertNotNull(result);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -88,6 +90,48 @@ public class WxMpMenuServiceImplTest {
|
||||
System.out.println(this.menuId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiCreateConditionalMenu() throws WxErrorException {
|
||||
String json = "{\n" +
|
||||
" \"button\":[\n" +
|
||||
" { \n" +
|
||||
" \"type\":\"click\",\n" +
|
||||
" \"name\":\"今日歌曲\",\n" +
|
||||
" \"key\":\"V1001_TODAY_MUSIC\" \n" +
|
||||
" },\n" +
|
||||
" { \n" +
|
||||
" \"name\":\"菜单\",\n" +
|
||||
" \"sub_button\":[\n" +
|
||||
" { \n" +
|
||||
" \"type\":\"view\",\n" +
|
||||
" \"name\":\"搜索\",\n" +
|
||||
" \"url\":\"http://www.soso.com/\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"type\":\"view\",\n" +
|
||||
" \"name\":\"视频\",\n" +
|
||||
" \"url\":\"http://v.qq.com/\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"type\":\"click\",\n" +
|
||||
" \"name\":\"赞一下我们\",\n" +
|
||||
" \"key\":\"V1001_GOOD\"\n" +
|
||||
" }]\n" +
|
||||
" }],\n" +
|
||||
"\"matchrule\":{\n" +
|
||||
" \"tag_id\":\"2\",\n" +
|
||||
" \"sex\":\"1\",\n" +
|
||||
" \"country\":\"中国\",\n" +
|
||||
" \"province\":\"广东\",\n" +
|
||||
" \"city\":\"广州\",\n" +
|
||||
" \"client_platform_type\":\"2\",\n" +
|
||||
" \"language\":\"zh_CN\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
this.menuId = this.wxService.getMenuService().menuCreate(json);
|
||||
System.out.println(this.menuId);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testCreateConditionalMenu"})
|
||||
public void testMenuGet_AfterCreateConditionalMenu() throws WxErrorException {
|
||||
WxMpMenu wxMenu = this.wxService.getMenuService().menuGet();
|
||||
@@ -147,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();
|
||||
}
|
||||
|
||||
@@ -14,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());
|
||||
@@ -29,11 +28,13 @@ public class ApiTestModule implements Module {
|
||||
|
||||
TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream);
|
||||
config.setAccessTokenLock(new ReentrantLock());
|
||||
WxMpService wxService = new WxMpServiceHttpClientImpl();
|
||||
wxService.setWxMpConfigStorage(config);
|
||||
WxMpService mpService = new WxMpServiceHttpClientImpl();
|
||||
|
||||
mpService.setWxMpConfigStorage(config);
|
||||
mpService.addConfigStorage("another", config);
|
||||
|
||||
binder.bind(WxMpService.class).toInstance(wxService);
|
||||
binder.bind(WxMpConfigStorage.class).toInstance(config);
|
||||
binder.bind(WxMpService.class).toInstance(mpService);
|
||||
} catch (IOException e) {
|
||||
this.log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.chanjar.weixin.mp.bean.result;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadResult;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxMpAdLeadResultTest {
|
||||
@Test
|
||||
public void testFromJson() throws Exception {
|
||||
String json = "{\n" +
|
||||
"\t\"data\": {\n" +
|
||||
"\t\t\"page_info\": {\n" +
|
||||
"\t\t\t\"total_number\": 39,\n" +
|
||||
"\t\t\t\"page\": 1,\n" +
|
||||
"\t\t\t\"page_size\": 100,\n" +
|
||||
"\t\t\t\"total_page\": 1\n" +
|
||||
"\t\t},\n" +
|
||||
"\t\t\"list\": [{\n" +
|
||||
"\t\t\t\"click_id\": \"<click_id1>\",\n" +
|
||||
"\t\t\t\"adgroup_name\": \"<adgroup_name>\",\n" +
|
||||
"\t\t\t\"campaign_id\": 1800000001,\n" +
|
||||
"\t\t\t\"leads_info\": [{\n" +
|
||||
"\t\t\t\t\"value\": \"13800138000\",\n" +
|
||||
"\t\t\t\t\"key\": \"电话号码\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"2019-03-14 00:54:34\",\n" +
|
||||
"\t\t\t\t\"key\": \"提交时间\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"123\",\n" +
|
||||
"\t\t\t\t\"key\": \"自定义问题\"\n" +
|
||||
"\t\t\t}],\n" +
|
||||
"\t\t\t\"agency_name\": \"\",\n" +
|
||||
"\t\t\t\"agency_id\": \"\",\n" +
|
||||
"\t\t\t\"campaign_name\": \"<campaign_name>\",\n" +
|
||||
"\t\t\t\"adgroup_id\": 1800000002\n" +
|
||||
"\t\t}, {\n" +
|
||||
"\t\t\t\"click_id\": \"<click_id2>\",\n" +
|
||||
"\t\t\t\"adgroup_name\": \"<adgroup_name>\",\n" +
|
||||
"\t\t\t\"campaign_id\": 1800000001,\n" +
|
||||
"\t\t\t\"leads_info\": [{\n" +
|
||||
"\t\t\t\t\"value\": \"13800138001\",\n" +
|
||||
"\t\t\t\t\"key\": \"电话号码\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"2019-03-14 02:10:39\",\n" +
|
||||
"\t\t\t\t\"key\": \"提交时间\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"321\",\n" +
|
||||
"\t\t\t\t\"key\": \"自定义问题\"\n" +
|
||||
"\t\t\t}],\n" +
|
||||
"\t\t\t\"agency_name\": \"\",\n" +
|
||||
"\t\t\t\"agency_id\": \"\",\n" +
|
||||
"\t\t\t\"campaign_name\": \"<campaign_name>\",\n" +
|
||||
"\t\t\t\"adgroup_id\": 1800000002\n" +
|
||||
"\t\t}]\n" +
|
||||
"\t},\n" +
|
||||
"\t\"errcode\": 0,\n" +
|
||||
"\t\"errmsg\": \"\"\n" +
|
||||
"}";
|
||||
|
||||
WxMpAdLeadResult adLeadResult = WxMpAdLeadResult.fromJson(json);
|
||||
|
||||
assertNotNull(adLeadResult);
|
||||
assertNotNull(adLeadResult.getPageInfo());
|
||||
assertNotNull(adLeadResult.getAdLeads());
|
||||
assertTrue(adLeadResult.getAdLeads().size() > 0);
|
||||
|
||||
System.out.println(adLeadResult);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user