mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-11-01 03:25:35 +08:00 
			
		
		
		
	#516 增加获取Wi-Fi门店列表接口
This commit is contained in:
		| @ -415,6 +415,13 @@ public interface WxMpService { | ||||
|    */ | ||||
|   WxMpAiOpenService getAiOpenService(); | ||||
|  | ||||
|   /** | ||||
|    * 返回WIFI接口方法的实现类对象,以方便调用其各个接口 | ||||
|    * | ||||
|    * @return WxMpWifiService | ||||
|    */ | ||||
|   WxMpWifiService getWifiService(); | ||||
|  | ||||
|   void setKefuService(WxMpKefuService kefuService); | ||||
|  | ||||
|   void setMaterialService(WxMpMaterialService materialService); | ||||
|  | ||||
| @ -0,0 +1,28 @@ | ||||
| package me.chanjar.weixin.mp.api; | ||||
|  | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | ||||
|  | ||||
| /** | ||||
|  * <pre> | ||||
|  *  微信连接WI-FI接口. | ||||
|  *  Created by BinaryWang on 2018/6/10. | ||||
|  * </pre> | ||||
|  * | ||||
|  * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
|  */ | ||||
| public interface WxMpWifiService { | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 获取Wi-Fi门店列表. | ||||
|    * 通过此接口获取WiFi的门店列表,该列表包括公众平台的门店信息、以及添加设备后的WiFi相关信息。创建门店方法请参考“微信门店接口”。 | ||||
|    * 注:微信连Wi-Fi下的所有接口中的shop_id,必需先通过此接口获取。 | ||||
|    * | ||||
|    * http请求方式: POST | ||||
|    * 请求URL:https://api.weixin.qq.com/bizwifi/shop/list?access_token=ACCESS_TOKEN | ||||
|    * </pre> | ||||
|    *  @param pageIndex 分页下标,默认从1开始 | ||||
|    * @param pageSize  每页的个数,默认10个,最大20个 | ||||
|    */ | ||||
|   WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException; | ||||
| } | ||||
| @ -53,6 +53,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | ||||
|   private WxMpMemberCardService memberCardService = new WxMpMemberCardServiceImpl(this); | ||||
|   private WxMpMassMessageService massMessageService = new WxMpMassMessageServiceImpl(this); | ||||
|   private WxMpAiOpenService aiOpenService = new WxMpAiOpenServiceImpl(this); | ||||
|   private WxMpWifiService wifiService = new WxMpWifiServiceImpl(this); | ||||
|  | ||||
|   private int retrySleepMillis = 1000; | ||||
|   private int maxRetryTimes = 5; | ||||
| @ -501,4 +502,9 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | ||||
|   public void setAiOpenService(WxMpAiOpenService aiOpenService) { | ||||
|     this.aiOpenService = aiOpenService; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WxMpWifiService getWifiService() { | ||||
|     return this.wifiService; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,31 @@ | ||||
| package me.chanjar.weixin.mp.api.impl; | ||||
|  | ||||
| import com.google.gson.JsonObject; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.WxMpWifiService; | ||||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | ||||
|  | ||||
| /** | ||||
|  * <pre> | ||||
|  *  Created by BinaryWang on 2018/6/10. | ||||
|  * </pre> | ||||
|  * | ||||
|  * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
|  */ | ||||
| public class WxMpWifiServiceImpl implements WxMpWifiService { | ||||
|   private WxMpService wxMpService; | ||||
|  | ||||
|   public WxMpWifiServiceImpl(WxMpService wxMpService) { | ||||
|     this.wxMpService = wxMpService; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException { | ||||
|     JsonObject json = new JsonObject(); | ||||
|     json.addProperty("pageindex", pageIndex); | ||||
|     json.addProperty("pagesize", pageSize); | ||||
|     final String result = this.wxMpService.post("https://api.weixin.qq.com/bizwifi/shop/list", json.toString()); | ||||
|     return WxMpWifiShopListResult.fromJson(result); | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,90 @@ | ||||
| package me.chanjar.weixin.mp.bean.wifi; | ||||
|  | ||||
| import com.google.gson.JsonParser; | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * <pre> | ||||
|  *  Created by BinaryWang on 2018/6/10. | ||||
|  * </pre> | ||||
|  * | ||||
|  * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
|  */ | ||||
| @Data | ||||
| public class WxMpWifiShopListResult { | ||||
|   public static WxMpWifiShopListResult fromJson(String json) { | ||||
|     return WxMpGsonBuilder.create().fromJson( | ||||
|       new JsonParser().parse(json).getAsJsonObject().get("data"), | ||||
|       WxMpWifiShopListResult.class); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 总数 | ||||
|    */ | ||||
|   @SerializedName("totalcount") | ||||
|   private int totalCount; | ||||
|  | ||||
|   /** | ||||
|    * 分页下标 | ||||
|    */ | ||||
|   @SerializedName("pageindex") | ||||
|   private int pageIndex; | ||||
|  | ||||
|   /** | ||||
|    * 分页页数 | ||||
|    */ | ||||
|   @SerializedName("pagecount") | ||||
|   private int pageCount; | ||||
|  | ||||
|   private List<Record> records; | ||||
|  | ||||
|   @Data | ||||
|   public static class Record { | ||||
|  | ||||
|     /** | ||||
|      * 门店ID(适用于微信连Wi-Fi业务) | ||||
|      */ | ||||
|     @SerializedName("shop_id") | ||||
|     private Integer shopId; | ||||
|  | ||||
|     /** | ||||
|      * 门店名称 | ||||
|      */ | ||||
|     @SerializedName("shop_name") | ||||
|     private String shopName; | ||||
|  | ||||
|     /** | ||||
|      * 无线网络设备的ssid,未添加设备为空,多个ssid时显示第一个 | ||||
|      */ | ||||
|     @SerializedName("ssid") | ||||
|     private String ssid; | ||||
|  | ||||
|     /** | ||||
|      * 无线网络设备的ssid列表,返回数组格式 | ||||
|      */ | ||||
|     @SerializedName("ssid_list") | ||||
|     private List<String> ssidList; | ||||
|  | ||||
|     /** | ||||
|      * 门店内设备的设备类型,0-未添加设备,1-专业型设备,4-密码型设备,5-portal自助型设备,31-portal改造型设备 | ||||
|      */ | ||||
|     @SerializedName("protocol_type") | ||||
|     private Integer protocolType; | ||||
|  | ||||
|     /** | ||||
|      * 商户自己的id,与门店poi_id对应关系,建议在添加门店时候建立关联关系,具体请参考“微信门店接口” | ||||
|      */ | ||||
|     @SerializedName("sid") | ||||
|     private String sid; | ||||
|  | ||||
|     /** | ||||
|      * 门店ID(适用于微信卡券、微信门店业务),具体定义参考微信门店,与shop_id一一对应 | ||||
|      */ | ||||
|     @SerializedName("poi_id") | ||||
|     private String poiId; | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,31 @@ | ||||
| package me.chanjar.weixin.mp.api.impl; | ||||
|  | ||||
| import com.google.inject.Inject; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | ||||
| import org.testng.annotations.Guice; | ||||
| import org.testng.annotations.Test; | ||||
|  | ||||
| import static org.testng.Assert.*; | ||||
|  | ||||
| /** | ||||
|  * <pre> | ||||
|  *  Created by BinaryWang on 2018/6/10. | ||||
|  * </pre> | ||||
|  * | ||||
|  * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
|  */ | ||||
| @Test | ||||
| @Guice(modules = ApiTestModule.class) | ||||
| public class WxMpWifiServiceImplTest { | ||||
|   @Inject | ||||
|   private WxMpService wxService; | ||||
|  | ||||
|   @Test | ||||
|   public void testListShop() throws WxErrorException { | ||||
|     final WxMpWifiShopListResult result = this.wxService.getWifiService().listShop(1, 2); | ||||
|     System.out.println(result); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang