Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
增加 摇周边部分接口
  • Loading branch information
007gzs authored and 刘毅杰 committed Nov 14, 2017
commit 85c0f11a0fec1fddfc85582700ffb001824bb8d8
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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.mp.bean.WxMpShakeInfoResult;
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
import me.chanjar.weixin.mp.bean.shake.*;

/**
* 摇一摇周边的相关接口
Expand All @@ -24,4 +26,36 @@ public interface WxMpShakeService {
*/
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;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpShakeService;
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
import me.chanjar.weixin.mp.bean.shake.*;

/**
* Created by rememberber on 2017/6/5.
*
* @author rememberber
*/
public class WxMpShakeServiceImpl implements WxMpShakeService {
Expand All @@ -27,7 +30,7 @@ public WxMpShakeServiceImpl(WxMpService wxMpService) {
* 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE
* </pre>
*
* @param wxMpShakeQuery 查询参数
* @param wxMpShakeQuery 查询参数
*/
@Override
public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException {
Expand All @@ -36,4 +39,28 @@ public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws Wx
String responseContent = this.wxMpService.post(url, postData);
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 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;
}
}
Original file line number Diff line number Diff line change
@@ -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.List;

@Data
public class WxMpShakeAroundDeviceBindPageQuery {
private WxMpDeviceIdentifier deviceIdentifier;
private List<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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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;
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;
}
}