Wifi.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. namespace WeChat;
  16. use WeChat\Contracts\BasicWeChat;
  17. /**
  18. * 门店 WIFI 管理
  19. * Class Wifi
  20. * @package WeChat
  21. */
  22. class Wifi extends BasicWeChat
  23. {
  24. /**
  25. * 获取 Wi-Fi 门店列表
  26. * @param integer $pageindex 分页下标,默认从1开始
  27. * @param integer $pagesize 每页的个数,默认10个,最大20个
  28. * @return array
  29. * @throws Exceptions\InvalidResponseException
  30. * @throws Exceptions\LocalCacheException
  31. */
  32. public function getShopList($pageindex = 1, $pagesize = 2)
  33. {
  34. $url = 'https://api.weixin.qq.com/bizwifi/shop/list?access_token=ACCESS_TOKEN';
  35. $this->registerApi($url, __FUNCTION__, func_get_args());
  36. return $this->httpPostForJson($url, ['pageindex' => $pageindex, 'pagesize' => $pagesize]);
  37. }
  38. /**
  39. * 查询门店Wi-Fi信息
  40. * @param integer $shop_id 门店ID
  41. * @return array
  42. * @throws Exceptions\InvalidResponseException
  43. * @throws Exceptions\LocalCacheException
  44. */
  45. public function getShopWifi($shop_id)
  46. {
  47. $url = 'https://api.weixin.qq.com/bizwifi/shop/list?access_token=ACCESS_TOKEN';
  48. $this->registerApi($url, __FUNCTION__, func_get_args());
  49. return $this->httpPostForJson($url, ['shop_id' => $shop_id]);
  50. }
  51. /**
  52. * 修改门店网络信息
  53. * @param integer $shop_id 门店ID
  54. * @param string $old_ssid 旧的无线网络设备的ssid
  55. * @param string $ssid 新的无线网络设备的ssid
  56. * @param string $password 无线网络设备的密码(可选)
  57. * @return array
  58. * @throws Exceptions\InvalidResponseException
  59. * @throws Exceptions\LocalCacheException
  60. */
  61. public function upShopWifi($shop_id, $old_ssid, $ssid, $password = null)
  62. {
  63. $data = ['shop_id' => $shop_id, 'old_ssid' => $old_ssid, 'ssid' => $ssid];
  64. is_null($password) || $data['password'] = $password;
  65. $url = 'https://api.weixin.qq.com/bizwifi/shop/update?access_token=ACCESS_TOKEN';
  66. $this->registerApi($url, __FUNCTION__, func_get_args());
  67. return $this->httpPostForJson($url, $data);
  68. }
  69. /**
  70. * 清空门店网络及设备
  71. * @param integer $shop_id
  72. * @return array
  73. * @throws Exceptions\InvalidResponseException
  74. * @throws Exceptions\LocalCacheException
  75. */
  76. public function clearShopWifi($shop_id)
  77. {
  78. $url = 'https://api.weixin.qq.com/bizwifi/shop/clean?access_token=ACCESS_TOKEN';
  79. $this->registerApi($url, __FUNCTION__, func_get_args());
  80. return $this->httpPostForJson($url, ['shop_id' => $shop_id]);
  81. }
  82. /**
  83. * 添加密码型设备
  84. * @param integer $shop_id 门店ID
  85. * @param string $ssid 无线网络设备的ssid
  86. * @param null|string $password 无线网络设备的密码
  87. * @return array
  88. * @throws Exceptions\InvalidResponseException
  89. * @throws Exceptions\LocalCacheException
  90. */
  91. public function addShopWifi($shop_id, $ssid, $password = null)
  92. {
  93. $data = ['shop_id' => $shop_id, 'ssid' => $ssid, 'password' => $password];
  94. $url = 'https://api.weixin.qq.com/bizwifi/device/add?access_token=ACCESS_TOKEN';
  95. $this->registerApi($url, __FUNCTION__, func_get_args());
  96. return $this->httpPostForJson($url, $data);
  97. }
  98. /**
  99. * 添加portal型设备
  100. * @param integer $shop_id 门店ID
  101. * @param string $ssid 无线网络设备的ssid
  102. * @param bool $reset 重置secretkey,false-不重置,true-重置,默认为false
  103. * @return array
  104. * @throws Exceptions\InvalidResponseException
  105. * @throws Exceptions\LocalCacheException
  106. */
  107. public function addShopPortal($shop_id, $ssid, $reset = false)
  108. {
  109. $data = ['shop_id' => $shop_id, 'ssid' => $ssid, 'reset' => $reset];
  110. $url = 'https://api.weixin.qq.com/bizwifi/apportal/register?access_token=ACCESS_TOKEN';
  111. $this->registerApi($url, __FUNCTION__, func_get_args());
  112. return $this->httpPostForJson($url, $data);
  113. }
  114. /**
  115. * 查询设备
  116. * @param null|integer $shop_id 根据门店id查询
  117. * @param null|integer $pageindex 分页下标,默认从1开始
  118. * @param null|integer $pagesize 每页的个数,默认10个,最大20个
  119. * @return array
  120. * @throws Exceptions\InvalidResponseException
  121. * @throws Exceptions\LocalCacheException
  122. */
  123. public function queryShopWifi($shop_id = null, $pageindex = null, $pagesize = null)
  124. {
  125. $data = [];
  126. is_null($pagesize) || $data['pagesize'] = $pagesize;
  127. is_null($pageindex) || $data['pageindex'] = $pageindex;
  128. is_null($shop_id) || $data['shop_id'] = $shop_id;
  129. $url = 'https://api.weixin.qq.com/bizwifi/device/list?access_token=ACCESS_TOKEN';
  130. $this->registerApi($url, __FUNCTION__, func_get_args());
  131. return $this->httpPostForJson($url, $data);
  132. }
  133. /**
  134. * 删除设备
  135. * @param string $bssid 需要删除的无线网络设备无线mac地址,格式冒号分隔,字符长度17个,并且字母小写,例如:00:1f:7a:ad:5c:a8
  136. * @return array
  137. * @throws Exceptions\InvalidResponseException
  138. * @throws Exceptions\LocalCacheException
  139. */
  140. public function delShopWifi($bssid)
  141. {
  142. $url = 'https://api.weixin.qq.com/bizwifi/device/delete?access_token=ACCESS_TOKEN';
  143. $this->registerApi($url, __FUNCTION__, func_get_args());
  144. return $this->httpPostForJson($url, ['bssid' => $bssid]);
  145. }
  146. /**
  147. * 获取物料二维码
  148. * @param integer $shop_id 门店ID
  149. * @param string $ssid 已添加到门店下的无线网络名称
  150. * @param integer $img_id 物料样式编号:0-纯二维码,可用于自由设计宣传材料;1-二维码物料,155mm×215mm(宽×高),可直接张贴
  151. * @return array
  152. * @throws Exceptions\InvalidResponseException
  153. * @throws Exceptions\LocalCacheException
  154. */
  155. public function getQrc($shop_id, $ssid, $img_id = 1)
  156. {
  157. $url = 'https://api.weixin.qq.com/bizwifi/qrcode/get?access_token=ACCESS_TOKEN';
  158. $this->registerApi($url, __FUNCTION__, func_get_args());
  159. return $this->httpPostForJson($url, ['shop_id' => $shop_id, 'ssid' => $ssid, 'img_id' => $img_id]);
  160. }
  161. /**
  162. * 设置商家主页
  163. * @param integer $shop_id 门店ID
  164. * @param integer $template_id 模板ID,0-默认模板,1-自定义url
  165. * @param null|string $url 自定义链接,当template_id为1时必填
  166. * @return array
  167. * @throws Exceptions\InvalidResponseException
  168. * @throws Exceptions\LocalCacheException
  169. */
  170. public function setHomePage($shop_id, $template_id, $url = null)
  171. {
  172. $data = ['shop_id' => $shop_id, 'template_id' => $template_id];
  173. is_null($url) && $data['struct'] = ['url' => $url];
  174. $url = 'https://api.weixin.qq.com/bizwifi/homepage/set?access_token=ACCESS_TOKEN';
  175. $this->registerApi($url, __FUNCTION__, func_get_args());
  176. return $this->httpPostForJson($url, $data);
  177. }
  178. /**
  179. * 查询商家主页
  180. * @param integer $shop_id 查询的门店id
  181. * @return array
  182. * @throws Exceptions\InvalidResponseException
  183. * @throws Exceptions\LocalCacheException
  184. */
  185. public function getHomePage($shop_id)
  186. {
  187. $url = 'https://api.weixin.qq.com/bizwifi/homepage/get?access_token=ACCESS_TOKEN';
  188. $this->registerApi($url, __FUNCTION__, func_get_args());
  189. return $this->httpPostForJson($url, ['shop_id' => $shop_id]);
  190. }
  191. /**
  192. * 设置微信首页欢迎语
  193. * @param integer $shop_id 门店ID
  194. * @param integer $bar_type 微信首页欢迎语的文本内容:0--欢迎光临+公众号名称;1--欢迎光临+门店名称;2--已连接+公众号名称+WiFi;3--已连接+门店名称+Wi-Fi。
  195. * @return array
  196. * @throws Exceptions\InvalidResponseException
  197. * @throws Exceptions\LocalCacheException
  198. */
  199. public function setBar($shop_id, $bar_type = 1)
  200. {
  201. $url = 'https://api.weixin.qq.com/bizwifi/bar/set?access_token=ACCESS_TOKEN';
  202. $this->registerApi($url, __FUNCTION__, func_get_args());
  203. return $this->httpPostForJson($url, ['shop_id' => $shop_id, 'bar_type' => $bar_type]);
  204. }
  205. /**
  206. * 设置连网完成页
  207. * @param integer $shop_id 门店ID
  208. * @param string $finishpage_url 连网完成页URL
  209. * @return array
  210. * @throws Exceptions\InvalidResponseException
  211. * @throws Exceptions\LocalCacheException
  212. */
  213. public function setFinishPage($shop_id, $finishpage_url)
  214. {
  215. $url = 'https://api.weixin.qq.com/bizwifi/finishpage/set?access_token=ACCESS_TOKEN';
  216. $this->registerApi($url, __FUNCTION__, func_get_args());
  217. return $this->httpPostForJson($url, ['shop_id' => $shop_id, 'finishpage_url' => $finishpage_url]);
  218. }
  219. /**
  220. * Wi-Fi 数据统计
  221. * @param string $begin_date 起始日期时间,格式yyyy-mm-dd,最长时间跨度为30天
  222. * @param string $end_date 结束日期时间戳,格式yyyy-mm-dd,最长时间跨度为30天
  223. * @param integer $shop_id 按门店ID搜索,-1为总统计
  224. * @return array
  225. * @throws Exceptions\InvalidResponseException
  226. * @throws Exceptions\LocalCacheException
  227. */
  228. public function staticList($begin_date, $end_date, $shop_id = -1)
  229. {
  230. $url = 'https://api.weixin.qq.com/bizwifi/statistics/list?access_token=ACCESS_TOKEN';
  231. $this->registerApi($url, __FUNCTION__, func_get_args());
  232. return $this->httpPostForJson($url, ['shop_id' => $shop_id, 'begin_date' => $begin_date, 'end_date' => $end_date]);
  233. }
  234. /**
  235. * 设置门店卡券投放信息
  236. * @param integer $shop_id 门店ID,可设置为0,表示所有门店
  237. * @param integer $card_id 卡券ID
  238. * @param string $card_describe 卡券描述,不能超过18个字符
  239. * @param string $start_time 卡券投放开始时间(单位是秒)
  240. * @param string $end_time 卡券投放结束时间(单位是秒) 注:不能超过卡券的有效期时间
  241. * @return array
  242. * @throws Exceptions\InvalidResponseException
  243. * @throws Exceptions\LocalCacheException
  244. */
  245. public function setCouponput($shop_id, $card_id, $card_describe, $start_time, $end_time)
  246. {
  247. $data = ['shop_id' => $shop_id, 'card_id' => $card_id, 'card_describe' => $card_describe, 'start_time' => $start_time, 'end_time' => $end_time];
  248. $url = 'https://api.weixin.qq.com/bizwifi/couponput/set?access_token=ACCESS_TOKEN';
  249. $this->registerApi($url, __FUNCTION__, func_get_args());
  250. return $this->httpPostForJson($url, $data);
  251. }
  252. /**
  253. * 查询门店卡券投放信息
  254. * @param integer $shop_id 门店ID,可设置为0,表示所有门店
  255. * @return array
  256. * @throws Exceptions\InvalidResponseException
  257. * @throws Exceptions\LocalCacheException
  258. */
  259. public function getCouponput($shop_id)
  260. {
  261. $url = 'https://api.weixin.qq.com/bizwifi/couponput/get?access_token=ACCESS_TOKEN';
  262. $this->registerApi($url, __FUNCTION__, func_get_args());
  263. return $this->httpPostForJson($url, ['shop_id' => $shop_id]);
  264. }
  265. }