mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
#1095 修复微信营销接口中有问题的回传数据接口方法
This commit is contained in:
parent
d451d3b779
commit
c805444154
@ -11,16 +11,14 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信营销接口
|
||||
* </pre>
|
||||
* 微信营销接口.
|
||||
*
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public interface WxMpMarketingService {
|
||||
/**
|
||||
* <pre>
|
||||
* 创建数据源
|
||||
* 创建数据源.
|
||||
* 接口调用请求说明
|
||||
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
||||
* </pre>
|
||||
@ -33,7 +31,7 @@ public interface WxMpMarketingService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取数据源信息
|
||||
* 获取数据源信息.
|
||||
* </pre>
|
||||
*
|
||||
* @param userActionSetId 数据源唯一ID
|
||||
@ -41,7 +39,7 @@ public interface WxMpMarketingService {
|
||||
List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 回传数据
|
||||
* 回传数据.
|
||||
* 接口调用请求说明
|
||||
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
||||
*
|
||||
@ -51,7 +49,7 @@ public interface WxMpMarketingService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取朋友圈销售线索数据接口
|
||||
* 获取朋友圈销售线索数据接口.
|
||||
* 接口调用请求说明
|
||||
*
|
||||
* http请求方式: POST
|
||||
|
@ -50,15 +50,11 @@ public class WxMpMarketingServiceImpl implements WxMpMarketingService {
|
||||
|
||||
@Override
|
||||
public void addUserAction(List<WxMpUserAction> actions) throws WxErrorException {
|
||||
JsonArray json = new JsonArray();
|
||||
for (WxMpUserAction action : actions) {
|
||||
json.add(action.toJsonObject());
|
||||
}
|
||||
wxMpService.post(USER_ACTIONS_ADD, json.toString());
|
||||
wxMpService.post(USER_ACTIONS_ADD, WxMpUserAction.listToJson(actions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpAdLeadResult getAdLeads(Date beginDate, Date endDate, List<WxMpAdLeadFilter> filtering, Integer page, Integer page_size) throws WxErrorException, IOException {
|
||||
public WxMpAdLeadResult getAdLeads(Date beginDate, Date endDate, List<WxMpAdLeadFilter> filtering, Integer page, Integer pageSize) throws WxErrorException, IOException {
|
||||
Date today = new Date();
|
||||
if (beginDate == null) {
|
||||
beginDate = today;
|
||||
@ -72,7 +68,7 @@ public class WxMpMarketingServiceImpl implements WxMpMarketingService {
|
||||
dateRange.addProperty("end_date", DateFormatUtils.format(endDate, "yyyy-MM-dd"));
|
||||
params += "&date_range=" + URLEncoder.encode(dateRange.toString(), StandardCharsets.UTF_8.name());
|
||||
params += "&page=" + page;
|
||||
params += "&page_size=" + page_size;
|
||||
params += "&pageSize=" + pageSize;
|
||||
if (filtering != null) {
|
||||
JsonArray filterJson = new JsonArray();
|
||||
for (WxMpAdLeadFilter filter : filtering) {
|
||||
|
@ -1,39 +1,69 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class WxMpUserAction implements Serializable {
|
||||
private static final long serialVersionUID = 7042393762652152209L;
|
||||
|
||||
private Long userActionSetId;
|
||||
private String url;
|
||||
private Boolean actionTime;
|
||||
private Integer actionTime;
|
||||
private String actionType;
|
||||
private String clickId;
|
||||
private Integer actionParam;
|
||||
|
||||
public JsonObject toJsonObject() {
|
||||
private JsonObject toJsonObject() {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("user_action_set_id", this.userActionSetId);
|
||||
json.addProperty("url", this.url);
|
||||
json.addProperty("action_time", this.actionTime);
|
||||
json.addProperty("action_type", this.actionType);
|
||||
|
||||
if (this.clickId != null) {
|
||||
JsonObject traceJson = new JsonObject();
|
||||
traceJson.addProperty("click_id", this.clickId);
|
||||
json.add("trace", traceJson);
|
||||
}
|
||||
|
||||
if (this.actionParam != null) {
|
||||
JsonObject actionParamJson = new JsonObject();
|
||||
actionParamJson.addProperty("value", actionParam);
|
||||
json.add("action_param", actionParamJson);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* list对象转换为json字符串
|
||||
*
|
||||
* @param actions .
|
||||
* @return .
|
||||
*/
|
||||
public static String listToJson(List<WxMpUserAction> actions) {
|
||||
JsonArray array = new JsonArray();
|
||||
for (WxMpUserAction action : actions) {
|
||||
array.add(action.toJsonObject());
|
||||
}
|
||||
|
||||
JsonObject result = new JsonObject();
|
||||
result.add("actions", array);
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* 测试类.
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @date 2019-07-14
|
||||
*/
|
||||
public class WxMpMarketingServiceImplTest {
|
||||
|
||||
@Test
|
||||
public void testAddUserActionSets() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserActionSets() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddUserAction() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAdLeads() {
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 老板加点注释吧.
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @date 2019-07-14
|
||||
*/
|
||||
public class WxMpUserActionTest {
|
||||
|
||||
@Test
|
||||
public void testListToJson() {
|
||||
assertThat(WxMpUserAction.listToJson(Lists.newArrayList(WxMpUserAction.builder()
|
||||
.actionParam(1)
|
||||
.actionTime(122)
|
||||
.actionType("haha")
|
||||
.clickId("111")
|
||||
.url("1222")
|
||||
.userActionSetId(111L)
|
||||
.build()
|
||||
))).isEqualTo("{\"actions\":[{\"user_action_set_id\":111,\"url\":\"1222\",\"action_time\":122,\"action_type\":\"haha\",\"trace\":{\"click_id\":\"111\"},\"action_param\":{\"value\":1}}]}");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user