mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
#376 增加摇一摇周边的部分相关接口
This commit is contained in:
parent
9eda612db3
commit
d32cf99b6d
@ -1,8 +1,10 @@
|
|||||||
package me.chanjar.weixin.mp.api;
|
package me.chanjar.weixin.mp.api;
|
||||||
|
|
||||||
|
import me.chanjar.weixin.common.bean.result.WxError;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
|
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
|
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
|
||||||
|
import me.chanjar.weixin.mp.bean.shake.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 摇一摇周边的相关接口
|
* 摇一摇周边的相关接口
|
||||||
@ -24,4 +26,36 @@ public interface WxMpShakeService {
|
|||||||
*/
|
*/
|
||||||
WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException;
|
WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 页面管理<br/>
|
||||||
|
* 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459246752
|
||||||
|
* </pre>
|
||||||
|
* @param shakeAroundPageAddQuery
|
||||||
|
* @return
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 配置设备与页面的关联关系<br/>
|
||||||
|
* 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459301931
|
||||||
|
* </pre>
|
||||||
|
* @param shakeAroundDeviceBindPageQuery
|
||||||
|
* @return
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 查询设备与页面的关联关系<br/>
|
||||||
|
* 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443447914
|
||||||
|
* </pre>
|
||||||
|
* @param shakeAroundRelationSearchQuery
|
||||||
|
* @return
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package me.chanjar.weixin.mp.api.impl;
|
package me.chanjar.weixin.mp.api.impl;
|
||||||
|
|
||||||
|
import me.chanjar.weixin.common.bean.result.WxError;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.mp.api.WxMpShakeService;
|
import me.chanjar.weixin.mp.api.WxMpShakeService;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
|
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
|
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
|
||||||
|
import me.chanjar.weixin.mp.bean.shake.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by rememberber on 2017/6/5.
|
* Created by rememberber on 2017/6/5.
|
||||||
|
*
|
||||||
* @author rememberber
|
* @author rememberber
|
||||||
*/
|
*/
|
||||||
public class WxMpShakeServiceImpl implements WxMpShakeService {
|
public class WxMpShakeServiceImpl implements WxMpShakeService {
|
||||||
@ -36,4 +39,28 @@ public class WxMpShakeServiceImpl implements WxMpShakeService {
|
|||||||
String responseContent = this.wxMpService.post(url, postData);
|
String responseContent = this.wxMpService.post(url, postData);
|
||||||
return WxMpShakeInfoResult.fromJson(responseContent);
|
return WxMpShakeInfoResult.fromJson(responseContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException {
|
||||||
|
String url = "https://api.weixin.qq.com/shakearound/page/add";
|
||||||
|
String postData = shakeAroundPageAddQuery.toJsonString();
|
||||||
|
String responseContent = this.wxMpService.post(url, postData);
|
||||||
|
return WxMpShakeAroundPageAddResult.fromJson(responseContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException {
|
||||||
|
String url = "https://api.weixin.qq.com/shakearound/device/bindpage";
|
||||||
|
String postData = shakeAroundDeviceBindPageQuery.toJsonString();
|
||||||
|
String responseContent = this.wxMpService.post(url, postData);
|
||||||
|
return WxError.fromJson(responseContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException {
|
||||||
|
String url = "https://api.weixin.qq.com/shakearound/relation/search";
|
||||||
|
String postData = shakeAroundRelationSearchQuery.toJsonString();
|
||||||
|
String responseContent = this.wxMpService.post(url, postData);
|
||||||
|
return WxMpShakeAroundRelationSearchResult.fromJson(responseContent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.shake;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxMpDeviceIdentifier implements Serializable {
|
||||||
|
private Integer device_id;
|
||||||
|
private String uuid;
|
||||||
|
private Integer page_id;
|
||||||
|
private Integer major;
|
||||||
|
private Integer minor;
|
||||||
|
public JsonObject toJsonObject(){
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("device_id", device_id);
|
||||||
|
jsonObject.addProperty("uuid", uuid);
|
||||||
|
jsonObject.addProperty("major", major);
|
||||||
|
jsonObject.addProperty("minor", minor);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.shake;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxMpShakeAroundDeviceBindPageQuery {
|
||||||
|
private WxMpDeviceIdentifier deviceIdentifier;
|
||||||
|
private Collection<Integer> pageIds;
|
||||||
|
public String toJsonString(){
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.add("device_identifier", deviceIdentifier.toJsonObject());
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
for(Integer pageid: pageIds){
|
||||||
|
jsonArray.add(pageid);
|
||||||
|
}
|
||||||
|
jsonObject.add("page_ids", jsonArray);
|
||||||
|
return jsonObject.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.shake;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
@Data
|
||||||
|
public class WxMpShakeAroundPageAddQuery implements Serializable {
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String pageUrl;
|
||||||
|
private String comment;
|
||||||
|
private String iconUrl;
|
||||||
|
public String toJsonString(){
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("title", title);
|
||||||
|
jsonObject.addProperty("description", description);
|
||||||
|
jsonObject.addProperty("page_url", pageUrl);
|
||||||
|
jsonObject.addProperty("comment", comment);
|
||||||
|
jsonObject.addProperty("icon_url", iconUrl);
|
||||||
|
return jsonObject.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.shake;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||||
|
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxMpShakeAroundPageAddResult implements Serializable {
|
||||||
|
private Integer errorCode;
|
||||||
|
private String errorMsg;
|
||||||
|
private Integer pageId;
|
||||||
|
public static WxMpShakeAroundPageAddResult fromJson(String json) {
|
||||||
|
JsonObject jsonObject = WxMpGsonBuilder.INSTANCE.create().fromJson(json, JsonObject.class);
|
||||||
|
WxMpShakeAroundPageAddResult result = new WxMpShakeAroundPageAddResult();
|
||||||
|
result.setErrorCode(GsonHelper.getInteger(jsonObject, "errcode"));
|
||||||
|
result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg"));
|
||||||
|
jsonObject = jsonObject.getAsJsonObject("data");
|
||||||
|
if(jsonObject != null){
|
||||||
|
result.setPageId(GsonHelper.getInteger(jsonObject, "page_id"));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.shake;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxMpShakeAroundRelationSearchQuery implements Serializable {
|
||||||
|
private int type;
|
||||||
|
private Integer pageId;
|
||||||
|
private Integer begin;
|
||||||
|
private Integer count;
|
||||||
|
private WxMpDeviceIdentifier deviceIdentifier;
|
||||||
|
public String toJsonString(){
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("type", type);
|
||||||
|
switch (type){
|
||||||
|
case 1:
|
||||||
|
jsonObject.add("device_identifier", deviceIdentifier.toJsonObject());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
jsonObject.addProperty("page_id", pageId);
|
||||||
|
jsonObject.addProperty("begin", begin);
|
||||||
|
jsonObject.addProperty("count", count);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("type error");
|
||||||
|
}
|
||||||
|
return jsonObject.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.shake;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxMpShakeAroundRelationSearchResult implements Serializable {
|
||||||
|
private Integer errcode;
|
||||||
|
private String errmsg;
|
||||||
|
private WxMpShakeAcoundRelationSearch data;
|
||||||
|
public static WxMpShakeAroundRelationSearchResult fromJson(String json) {
|
||||||
|
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpShakeAroundRelationSearchResult.class);
|
||||||
|
}
|
||||||
|
@Data
|
||||||
|
public static class WxMpShakeAcoundRelationSearch implements Serializable{
|
||||||
|
private List<WxMpDeviceIdentifier> relations;
|
||||||
|
private Integer total_count;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user