Skip to content

Commit c805444

Browse files
committed
#1095 修复微信营销接口中有问题的回传数据接口方法
1 parent d451d3b commit c805444

File tree

5 files changed

+98
-16
lines changed

5 files changed

+98
-16
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMarketingService.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
import java.util.List;
1212

1313
/**
14-
* <pre>
15-
* 微信营销接口
16-
* </pre>
14+
* 微信营销接口.
1715
*
1816
* @author <a href="https://github.com/007gzs">007</a>
1917
*/
2018
public interface WxMpMarketingService {
2119
/**
2220
* <pre>
23-
* 创建数据源
21+
* 创建数据源.
2422
* 接口调用请求说明
2523
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
2624
* </pre>
@@ -33,15 +31,15 @@ public interface WxMpMarketingService {
3331

3432
/**
3533
* <pre>
36-
* 获取数据源信息
34+
* 获取数据源信息.
3735
* </pre>
3836
*
3937
* @param userActionSetId 数据源唯一ID
4038
*/
4139
List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException;
4240

4341
/**
44-
* 回传数据
42+
* 回传数据.
4543
* 接口调用请求说明
4644
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
4745
*
@@ -51,7 +49,7 @@ public interface WxMpMarketingService {
5149

5250
/**
5351
* <pre>
54-
* 获取朋友圈销售线索数据接口
52+
* 获取朋友圈销售线索数据接口.
5553
* 接口调用请求说明
5654
*
5755
* http请求方式: POST

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMarketingServiceImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,11 @@ public List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws Wx
5050

5151
@Override
5252
public void addUserAction(List<WxMpUserAction> actions) throws WxErrorException {
53-
JsonArray json = new JsonArray();
54-
for (WxMpUserAction action : actions) {
55-
json.add(action.toJsonObject());
56-
}
57-
wxMpService.post(USER_ACTIONS_ADD, json.toString());
53+
wxMpService.post(USER_ACTIONS_ADD, WxMpUserAction.listToJson(actions));
5854
}
5955

6056
@Override
61-
public WxMpAdLeadResult getAdLeads(Date beginDate, Date endDate, List<WxMpAdLeadFilter> filtering, Integer page, Integer page_size) throws WxErrorException, IOException {
57+
public WxMpAdLeadResult getAdLeads(Date beginDate, Date endDate, List<WxMpAdLeadFilter> filtering, Integer page, Integer pageSize) throws WxErrorException, IOException {
6258
Date today = new Date();
6359
if (beginDate == null) {
6460
beginDate = today;
@@ -72,7 +68,7 @@ public WxMpAdLeadResult getAdLeads(Date beginDate, Date endDate, List<WxMpAdLead
7268
dateRange.addProperty("end_date", DateFormatUtils.format(endDate, "yyyy-MM-dd"));
7369
params += "&date_range=" + URLEncoder.encode(dateRange.toString(), StandardCharsets.UTF_8.name());
7470
params += "&page=" + page;
75-
params += "&page_size=" + page_size;
71+
params += "&pageSize=" + pageSize;
7672
if (filtering != null) {
7773
JsonArray filterJson = new JsonArray();
7874
for (WxMpAdLeadFilter filter : filtering) {
Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,69 @@
11
package me.chanjar.weixin.mp.bean.marketing;
22

3+
import com.google.gson.JsonArray;
34
import com.google.gson.JsonObject;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
47
import lombok.Data;
8+
import lombok.NoArgsConstructor;
59

610
import java.io.Serializable;
11+
import java.util.List;
712

813
/**
914
* @author <a href="https://github.com/007gzs">007</a>
1015
*/
1116

1217
@Data
18+
@NoArgsConstructor
19+
@AllArgsConstructor
20+
@Builder
1321
public class WxMpUserAction implements Serializable {
1422
private static final long serialVersionUID = 7042393762652152209L;
23+
1524
private Long userActionSetId;
1625
private String url;
17-
private Boolean actionTime;
26+
private Integer actionTime;
1827
private String actionType;
1928
private String clickId;
2029
private Integer actionParam;
2130

22-
public JsonObject toJsonObject() {
31+
private JsonObject toJsonObject() {
2332
JsonObject json = new JsonObject();
2433
json.addProperty("user_action_set_id", this.userActionSetId);
2534
json.addProperty("url", this.url);
2635
json.addProperty("action_time", this.actionTime);
36+
json.addProperty("action_type", this.actionType);
37+
2738
if (this.clickId != null) {
2839
JsonObject traceJson = new JsonObject();
2940
traceJson.addProperty("click_id", this.clickId);
3041
json.add("trace", traceJson);
3142
}
43+
3244
if (this.actionParam != null) {
3345
JsonObject actionParamJson = new JsonObject();
3446
actionParamJson.addProperty("value", actionParam);
3547
json.add("action_param", actionParamJson);
3648
}
49+
3750
return json;
3851
}
52+
53+
/**
54+
* list对象转换为json字符串
55+
*
56+
* @param actions .
57+
* @return .
58+
*/
59+
public static String listToJson(List<WxMpUserAction> actions) {
60+
JsonArray array = new JsonArray();
61+
for (WxMpUserAction action : actions) {
62+
array.add(action.toJsonObject());
63+
}
64+
65+
JsonObject result = new JsonObject();
66+
result.add("actions", array);
67+
return result.toString();
68+
}
3969
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.chanjar.weixin.mp.api.impl;
2+
3+
import org.testng.annotations.Test;
4+
5+
import static org.testng.Assert.*;
6+
7+
/**
8+
* 测试类.
9+
*
10+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
11+
* @date 2019-07-14
12+
*/
13+
public class WxMpMarketingServiceImplTest {
14+
15+
@Test
16+
public void testAddUserActionSets() {
17+
}
18+
19+
@Test
20+
public void testGetUserActionSets() {
21+
}
22+
23+
@Test
24+
public void testAddUserAction() {
25+
}
26+
27+
@Test
28+
public void testGetAdLeads() {
29+
}
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package me.chanjar.weixin.mp.bean.marketing;
2+
3+
import com.google.common.collect.Lists;
4+
import org.testng.annotations.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
/**
9+
* 老板加点注释吧.
10+
*
11+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
12+
* @date 2019-07-14
13+
*/
14+
public class WxMpUserActionTest {
15+
16+
@Test
17+
public void testListToJson() {
18+
assertThat(WxMpUserAction.listToJson(Lists.newArrayList(WxMpUserAction.builder()
19+
.actionParam(1)
20+
.actionTime(122)
21+
.actionType("haha")
22+
.clickId("111")
23+
.url("1222")
24+
.userActionSetId(111L)
25+
.build()
26+
))).isEqualTo("{\"actions\":[{\"user_action_set_id\":111,\"url\":\"1222\",\"action_time\":122,\"action_type\":\"haha\",\"trace\":{\"click_id\":\"111\"},\"action_param\":{\"value\":1}}]}");
27+
}
28+
}

0 commit comments

Comments
 (0)