mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-04 12:47:46 +08:00
#1095 修复微信营销接口中有问题的回传数据接口方法
This commit is contained in:
parent
d451d3b779
commit
c805444154
@ -11,16 +11,14 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* 微信营销接口.
|
||||||
* 微信营销接口
|
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* @author <a href="https://github.com/007gzs">007</a>
|
* @author <a href="https://github.com/007gzs">007</a>
|
||||||
*/
|
*/
|
||||||
public interface WxMpMarketingService {
|
public interface WxMpMarketingService {
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 创建数据源
|
* 创建数据源.
|
||||||
* 接口调用请求说明
|
* 接口调用请求说明
|
||||||
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
||||||
* </pre>
|
* </pre>
|
||||||
@ -33,7 +31,7 @@ public interface WxMpMarketingService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 获取数据源信息
|
* 获取数据源信息.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param userActionSetId 数据源唯一ID
|
* @param userActionSetId 数据源唯一ID
|
||||||
@ -41,7 +39,7 @@ public interface WxMpMarketingService {
|
|||||||
List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException;
|
List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回传数据
|
* 回传数据.
|
||||||
* 接口调用请求说明
|
* 接口调用请求说明
|
||||||
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
||||||
*
|
*
|
||||||
@ -51,7 +49,7 @@ public interface WxMpMarketingService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 获取朋友圈销售线索数据接口
|
* 获取朋友圈销售线索数据接口.
|
||||||
* 接口调用请求说明
|
* 接口调用请求说明
|
||||||
*
|
*
|
||||||
* http请求方式: POST
|
* http请求方式: POST
|
||||||
|
@ -50,15 +50,11 @@ public class WxMpMarketingServiceImpl implements WxMpMarketingService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addUserAction(List<WxMpUserAction> actions) throws WxErrorException {
|
public void addUserAction(List<WxMpUserAction> actions) throws WxErrorException {
|
||||||
JsonArray json = new JsonArray();
|
wxMpService.post(USER_ACTIONS_ADD, WxMpUserAction.listToJson(actions));
|
||||||
for (WxMpUserAction action : actions) {
|
|
||||||
json.add(action.toJsonObject());
|
|
||||||
}
|
|
||||||
wxMpService.post(USER_ACTIONS_ADD, json.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
Date today = new Date();
|
||||||
if (beginDate == null) {
|
if (beginDate == null) {
|
||||||
beginDate = today;
|
beginDate = today;
|
||||||
@ -72,7 +68,7 @@ public class WxMpMarketingServiceImpl implements WxMpMarketingService {
|
|||||||
dateRange.addProperty("end_date", DateFormatUtils.format(endDate, "yyyy-MM-dd"));
|
dateRange.addProperty("end_date", DateFormatUtils.format(endDate, "yyyy-MM-dd"));
|
||||||
params += "&date_range=" + URLEncoder.encode(dateRange.toString(), StandardCharsets.UTF_8.name());
|
params += "&date_range=" + URLEncoder.encode(dateRange.toString(), StandardCharsets.UTF_8.name());
|
||||||
params += "&page=" + page;
|
params += "&page=" + page;
|
||||||
params += "&page_size=" + page_size;
|
params += "&pageSize=" + pageSize;
|
||||||
if (filtering != null) {
|
if (filtering != null) {
|
||||||
JsonArray filterJson = new JsonArray();
|
JsonArray filterJson = new JsonArray();
|
||||||
for (WxMpAdLeadFilter filter : filtering) {
|
for (WxMpAdLeadFilter filter : filtering) {
|
||||||
|
@ -1,39 +1,69 @@
|
|||||||
package me.chanjar.weixin.mp.bean.marketing;
|
package me.chanjar.weixin.mp.bean.marketing;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="https://github.com/007gzs">007</a>
|
* @author <a href="https://github.com/007gzs">007</a>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
public class WxMpUserAction implements Serializable {
|
public class WxMpUserAction implements Serializable {
|
||||||
private static final long serialVersionUID = 7042393762652152209L;
|
private static final long serialVersionUID = 7042393762652152209L;
|
||||||
|
|
||||||
private Long userActionSetId;
|
private Long userActionSetId;
|
||||||
private String url;
|
private String url;
|
||||||
private Boolean actionTime;
|
private Integer actionTime;
|
||||||
private String actionType;
|
private String actionType;
|
||||||
private String clickId;
|
private String clickId;
|
||||||
private Integer actionParam;
|
private Integer actionParam;
|
||||||
|
|
||||||
public JsonObject toJsonObject() {
|
private JsonObject toJsonObject() {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
json.addProperty("user_action_set_id", this.userActionSetId);
|
json.addProperty("user_action_set_id", this.userActionSetId);
|
||||||
json.addProperty("url", this.url);
|
json.addProperty("url", this.url);
|
||||||
json.addProperty("action_time", this.actionTime);
|
json.addProperty("action_time", this.actionTime);
|
||||||
|
json.addProperty("action_type", this.actionType);
|
||||||
|
|
||||||
if (this.clickId != null) {
|
if (this.clickId != null) {
|
||||||
JsonObject traceJson = new JsonObject();
|
JsonObject traceJson = new JsonObject();
|
||||||
traceJson.addProperty("click_id", this.clickId);
|
traceJson.addProperty("click_id", this.clickId);
|
||||||
json.add("trace", traceJson);
|
json.add("trace", traceJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.actionParam != null) {
|
if (this.actionParam != null) {
|
||||||
JsonObject actionParamJson = new JsonObject();
|
JsonObject actionParamJson = new JsonObject();
|
||||||
actionParamJson.addProperty("value", actionParam);
|
actionParamJson.addProperty("value", actionParam);
|
||||||
json.add("action_param", actionParamJson);
|
json.add("action_param", actionParamJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
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