mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	| @ -409,6 +409,12 @@ public interface WxMpService { | ||||
|    */ | ||||
|   WxMpDeviceService getDeviceService(); | ||||
|  | ||||
|   /** | ||||
|    * 返回摇一摇周边相关接口方法的实现类对象,以方便调用其各个接口 | ||||
|    * | ||||
|    * @return WxMpShakeService | ||||
|    */ | ||||
|   WxMpShakeService getShakeService(); | ||||
|  | ||||
|   /** | ||||
|    * 初始化http请求对象 | ||||
|  | ||||
| @ -0,0 +1,27 @@ | ||||
| package me.chanjar.weixin.mp.api; | ||||
|  | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; | ||||
| import me.chanjar.weixin.mp.bean.WxMpShakeQuery; | ||||
|  | ||||
| /** | ||||
|  * 摇一摇周边的相关接口 | ||||
|  * | ||||
|  * @author rememberber | ||||
|  */ | ||||
| public interface WxMpShakeService { | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 获取设备及用户信息<br/> | ||||
|    * 获取设备信息,包括UUID、major、minor,以及距离、openID等信息。 | ||||
|    * 详情请见: https://mp.weixin.qq.com/wiki?action=doc&id=mp1443447963 | ||||
|    * http请求方式: POST(请使用https协议) | ||||
|    * 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param wxMpShakeQuery 查询参数 | ||||
|    */ | ||||
|   WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException; | ||||
|  | ||||
| } | ||||
| @ -41,6 +41,7 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ | ||||
|   private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this); | ||||
|   private WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this); | ||||
|   private WxMpDeviceService deviceService = new WxMpDeviceServiceImpl(this); | ||||
|   private WxMpShakeService shakeService = new WxMpShakeServiceImpl(this); | ||||
|  | ||||
|   private int retrySleepMillis = 1000; | ||||
|   private int maxRetryTimes = 5; | ||||
| @ -394,4 +395,9 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ | ||||
|   public WxMpDeviceService getDeviceService() { | ||||
|     return this.deviceService; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WxMpShakeService getShakeService(){ | ||||
|     return this.shakeService; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,39 @@ | ||||
| package me.chanjar.weixin.mp.api.impl; | ||||
|  | ||||
| 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; | ||||
|  | ||||
| /** | ||||
|  * Created by rememberber on 2017/6/5. | ||||
|  * @author rememberber | ||||
|  */ | ||||
| public class WxMpShakeServiceImpl implements WxMpShakeService { | ||||
|  | ||||
|   private WxMpService wxMpService; | ||||
|  | ||||
|   public WxMpShakeServiceImpl(WxMpService wxMpService) { | ||||
|     this.wxMpService = wxMpService; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 获取设备及用户信息<br/> | ||||
|    * 获取设备信息,包括UUID、major、minor,以及距离、openID等信息。 | ||||
|    * 详情请见: https://mp.weixin.qq.com/wiki?action=doc&id=mp1443447963 | ||||
|    * http请求方式: POST(请使用https协议) | ||||
|    * 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param wxMpShakeQuery  查询参数 | ||||
|    */ | ||||
|   @Override | ||||
|   public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException { | ||||
|     String url = "https://api.weixin.qq.com/shakearound/user/getshakeinfo"; | ||||
|     String postData = wxMpShakeQuery.toJsonString(); | ||||
|     String responseContent = this.wxMpService.post(url, postData); | ||||
|     return WxMpShakeInfoResult.fromJson(responseContent); | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,164 @@ | ||||
| package me.chanjar.weixin.mp.bean; | ||||
|  | ||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| /** | ||||
|  * 摇一摇周边:获取设备及用户信息接口返回JSON数据接收类 | ||||
|  * Created by rememberber on 2017/6/5. | ||||
|  * | ||||
|  * @author rememberber | ||||
|  */ | ||||
| public class WxMpShakeInfoResult implements Serializable { | ||||
|  | ||||
|   private Integer errcode; | ||||
|  | ||||
|   private String errmsg; | ||||
|  | ||||
|   private Data data; | ||||
|  | ||||
|   public static WxMpShakeInfoResult fromJson(String json) { | ||||
|     return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpShakeInfoResult.class); | ||||
|   } | ||||
|  | ||||
|   public class Data { | ||||
|  | ||||
|     private String page_id; | ||||
|  | ||||
|     private String openid; | ||||
|  | ||||
|     private String poi_id; | ||||
|  | ||||
|     private String brand_userame; | ||||
|  | ||||
|     private BeaconInfo beacon_info; | ||||
|  | ||||
|     public class BeaconInfo { | ||||
|  | ||||
|       private double distance; | ||||
|  | ||||
|       private Integer major; | ||||
|  | ||||
|       private Integer measure_power; | ||||
|  | ||||
|       private Integer minor; | ||||
|  | ||||
|       private Integer rssi; | ||||
|  | ||||
|       private String uuid; | ||||
|  | ||||
|       public double getDistance() { | ||||
|         return distance; | ||||
|       } | ||||
|  | ||||
|       public void setDistance(double distance) { | ||||
|         this.distance = distance; | ||||
|       } | ||||
|  | ||||
|       public Integer getMajor() { | ||||
|         return major; | ||||
|       } | ||||
|  | ||||
|       public void setMajor(Integer major) { | ||||
|         this.major = major; | ||||
|       } | ||||
|  | ||||
|       public Integer getMeasure_power() { | ||||
|         return measure_power; | ||||
|       } | ||||
|  | ||||
|       public void setMeasure_power(Integer measure_power) { | ||||
|         this.measure_power = measure_power; | ||||
|       } | ||||
|  | ||||
|       public Integer getMinor() { | ||||
|         return minor; | ||||
|       } | ||||
|  | ||||
|       public void setMinor(Integer minor) { | ||||
|         this.minor = minor; | ||||
|       } | ||||
|  | ||||
|       public Integer getRssi() { | ||||
|         return rssi; | ||||
|       } | ||||
|  | ||||
|       public void setRssi(Integer rssi) { | ||||
|         this.rssi = rssi; | ||||
|       } | ||||
|  | ||||
|       public String getUuid() { | ||||
|         return uuid; | ||||
|       } | ||||
|  | ||||
|       public void setUuid(String uuid) { | ||||
|         this.uuid = uuid; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     public String getPage_id() { | ||||
|       return page_id; | ||||
|     } | ||||
|  | ||||
|     public void setPage_id(String page_id) { | ||||
|       this.page_id = page_id; | ||||
|     } | ||||
|  | ||||
|     public String getOpenid() { | ||||
|       return openid; | ||||
|     } | ||||
|  | ||||
|     public void setOpenid(String openid) { | ||||
|       this.openid = openid; | ||||
|     } | ||||
|  | ||||
|     public String getPoi_id() { | ||||
|       return poi_id; | ||||
|     } | ||||
|  | ||||
|     public void setPoi_id(String poi_id) { | ||||
|       this.poi_id = poi_id; | ||||
|     } | ||||
|  | ||||
|     public BeaconInfo getBeacon_info() { | ||||
|       return beacon_info; | ||||
|     } | ||||
|  | ||||
|     public void setBeacon_info(BeaconInfo beacon_info) { | ||||
|       this.beacon_info = beacon_info; | ||||
|     } | ||||
|  | ||||
|     public String getBrand_userame() { | ||||
|       return brand_userame; | ||||
|     } | ||||
|  | ||||
|     public void setBrand_userame(String brand_userame) { | ||||
|       this.brand_userame = brand_userame; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   public Integer getErrcode() { | ||||
|     return errcode; | ||||
|   } | ||||
|  | ||||
|   public void setErrcode(Integer errcode) { | ||||
|     this.errcode = errcode; | ||||
|   } | ||||
|  | ||||
|   public String getErrmsg() { | ||||
|     return errmsg; | ||||
|   } | ||||
|  | ||||
|   public void setErrmsg(String errmsg) { | ||||
|     this.errmsg = errmsg; | ||||
|   } | ||||
|  | ||||
|   public Data getData() { | ||||
|     return data; | ||||
|   } | ||||
|  | ||||
|   public void setData(Data data) { | ||||
|     this.data = data; | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,41 @@ | ||||
| package me.chanjar.weixin.mp.bean; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
|  | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| /** | ||||
|  * Created by rememberber on 2017/6/5. | ||||
|  * | ||||
|  * @author rememberber | ||||
|  */ | ||||
| public class WxMpShakeQuery { | ||||
|  | ||||
|   private String ticket; | ||||
|  | ||||
|   private int needPoi; | ||||
|  | ||||
|   public String toJsonString() { | ||||
|     Map<String, Object> map = new HashMap<>(); | ||||
|     map.put("ticket", this.ticket); | ||||
|     map.put("need_poi", this.needPoi); | ||||
|     return new Gson().toJson(map); | ||||
|   } | ||||
|  | ||||
|   public String getTicket() { | ||||
|     return ticket; | ||||
|   } | ||||
|  | ||||
|   public void setTicket(String ticket) { | ||||
|     this.ticket = ticket; | ||||
|   } | ||||
|  | ||||
|   public int getNeedPoi() { | ||||
|     return needPoi; | ||||
|   } | ||||
|  | ||||
|   public void setNeedPoi(int needPoi) { | ||||
|     this.needPoi = needPoi; | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,31 @@ | ||||
| package me.chanjar.weixin.mp.api.impl; | ||||
|  | ||||
| import com.google.inject.Inject; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
| import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; | ||||
| import me.chanjar.weixin.mp.bean.WxMpShakeQuery; | ||||
| import org.testng.annotations.Guice; | ||||
| import org.testng.annotations.Test; | ||||
|  | ||||
| /** | ||||
|  * 测试摇一摇周边相关的接口 | ||||
|  * | ||||
|  * @author rememberber | ||||
|  */ | ||||
| @Test(groups = "userAPI") | ||||
| @Guice(modules = ApiTestModule.class) | ||||
| public class WxMpShakeServiceImplTest { | ||||
|   @Inject | ||||
|   private WxMpService wxService; | ||||
|  | ||||
|   public void testGetShakeInfo() throws Exception { | ||||
|     WxMpShakeQuery wxMpShakeQuery = new WxMpShakeQuery(); | ||||
|     wxMpShakeQuery.setTicket("b87db7df490e5cbe4f598272f77f46be"); | ||||
|     wxMpShakeQuery.setNeedPoi(1); | ||||
|     WxMpShakeInfoResult wxMpShakeInfoResult = this.wxService.getShakeService().getShakeInfo(wxMpShakeQuery); | ||||
|  | ||||
|     System.out.println(); | ||||
|   } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Bob
					Bob