Shake.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. use WeChat\Contracts\Tools;
  18. /**
  19. * 揺一揺周边
  20. * Class Shake
  21. * @package WeChat
  22. */
  23. class Shake extends BasicWeChat
  24. {
  25. /**
  26. * 申请开通功能
  27. * @param array $data
  28. * @return array
  29. * @throws \WeChat\Exceptions\InvalidResponseException
  30. * @throws \WeChat\Exceptions\LocalCacheException
  31. */
  32. public function register(array $data)
  33. {
  34. $url = "https://api.weixin.qq.com/shakearound/account/register?access_token=ACCESS_TOKEN";
  35. $this->registerApi($url, __FUNCTION__, func_get_args());
  36. return $this->httpPostForJson($url, $data);
  37. }
  38. /**
  39. * 查询审核状态
  40. * @return array
  41. * @throws \WeChat\Exceptions\InvalidResponseException
  42. * @throws \WeChat\Exceptions\LocalCacheException
  43. */
  44. public function auditStatus()
  45. {
  46. $url = "https://api.weixin.qq.com/shakearound/account/auditstatus?access_token=ACCESS_TOKEN";
  47. $this->registerApi($url, __FUNCTION__, func_get_args());
  48. return $this->httpGetForJson($url);
  49. }
  50. /**
  51. * 申请设备ID
  52. * @param string $quantity 申请的设备ID的数量,单次新增设备超过500个,需走人工审核流程
  53. * @param string $apply_reason 申请理由,不超过100个汉字或200个英文字母
  54. * @param null|string $comment 备注,不超过15个汉字或30个英文字母
  55. * @param null|string $poi_id 设备关联的门店ID,关联门店后,在门店1KM的范围内有优先摇出信息的机会。
  56. * @return array
  57. * @throws \WeChat\Exceptions\InvalidResponseException
  58. * @throws \WeChat\Exceptions\LocalCacheException
  59. */
  60. public function createApply($quantity, $apply_reason, $comment = null, $poi_id = null)
  61. {
  62. $data = ['quantity' => $quantity, 'apply_reason' => $apply_reason];
  63. is_null($poi_id) || $data['poi_id'] = $poi_id;
  64. is_null($comment) || $data['comment'] = $comment;
  65. $url = "https://api.weixin.qq.com/shakearound/device/applyid?access_token=ACCESS_TOKEN";
  66. $this->registerApi($url, __FUNCTION__, func_get_args());
  67. return $this->httpPostForJson($url, $data);
  68. }
  69. /**
  70. * 查询设备ID申请审核状态
  71. * @param integer $applyId 批次ID,申请设备ID时所返回的批次ID
  72. * @return array
  73. * @throws \WeChat\Exceptions\InvalidResponseException
  74. * @throws \WeChat\Exceptions\LocalCacheException
  75. */
  76. public function getApplyStatus($applyId)
  77. {
  78. $url = "https://api.weixin.qq.com/shakearound/device/applyid?access_token=ACCESS_TOKEN";
  79. $this->registerApi($url, __FUNCTION__, func_get_args());
  80. return $this->httpPostForJson($url, ['apply_id' => $applyId]);
  81. }
  82. /**
  83. * 编辑设备信息
  84. * @param array $data
  85. * @return array
  86. * @throws \WeChat\Exceptions\InvalidResponseException
  87. * @throws \WeChat\Exceptions\LocalCacheException
  88. */
  89. public function updateApply(array $data)
  90. {
  91. $url = "https://api.weixin.qq.com/shakearound/device/update?access_token=ACCESS_TOKEN";
  92. $this->registerApi($url, __FUNCTION__, func_get_args());
  93. return $this->httpPostForJson($url, $data);
  94. }
  95. /**
  96. * 配置设备与门店的关联关系
  97. * @param array $data
  98. * @return array
  99. * @throws \WeChat\Exceptions\InvalidResponseException
  100. * @throws \WeChat\Exceptions\LocalCacheException
  101. */
  102. public function bindLocation(array $data)
  103. {
  104. $url = "https://api.weixin.qq.com/shakearound/device/bindlocation?access_token=ACCESS_TOKEN";
  105. $this->registerApi($url, __FUNCTION__, func_get_args());
  106. return $this->httpPostForJson($url, $data);
  107. }
  108. /**
  109. * 查询设备列表
  110. * @param array $data
  111. * @return array
  112. * @throws \WeChat\Exceptions\InvalidResponseException
  113. * @throws \WeChat\Exceptions\LocalCacheException
  114. */
  115. public function search(array $data)
  116. {
  117. $url = "https://api.weixin.qq.com/shakearound/device/search?access_token=ACCESS_TOKEN";
  118. $this->registerApi($url, __FUNCTION__, func_get_args());
  119. return $this->httpPostForJson($url, $data);
  120. }
  121. /**
  122. * 页面管理
  123. * @param array $data
  124. * @return array
  125. * @throws \WeChat\Exceptions\InvalidResponseException
  126. * @throws \WeChat\Exceptions\LocalCacheException
  127. */
  128. public function createPage(array $data)
  129. {
  130. $url = "https://api.weixin.qq.com/shakearound/page/add?access_token=ACCESS_TOKEN";
  131. $this->registerApi($url, __FUNCTION__, func_get_args());
  132. return $this->httpPostForJson($url, $data);
  133. }
  134. /**
  135. * 编辑页面信息
  136. * @param array $data
  137. * @return array
  138. * @throws \WeChat\Exceptions\InvalidResponseException
  139. * @throws \WeChat\Exceptions\LocalCacheException
  140. */
  141. public function updatePage(array $data)
  142. {
  143. $url = "https://api.weixin.qq.com/shakearound/page/update?access_token=ACCESS_TOKEN";
  144. $this->registerApi($url, __FUNCTION__, func_get_args());
  145. return $this->httpPostForJson($url, $data);
  146. }
  147. /**
  148. * 查询页面列表
  149. * @param array $data
  150. * @return array
  151. * @throws \WeChat\Exceptions\InvalidResponseException
  152. * @throws \WeChat\Exceptions\LocalCacheException
  153. */
  154. public function searchPage(array $data)
  155. {
  156. $url = "https://api.weixin.qq.com/shakearound/page/search?access_token=ACCESS_TOKEN";
  157. $this->registerApi($url, __FUNCTION__, func_get_args());
  158. return $this->httpPostForJson($url, $data);
  159. }
  160. /**
  161. * 删除页面
  162. * @param integer $page_id 指定页面的id
  163. * @return array
  164. * @throws \WeChat\Exceptions\InvalidResponseException
  165. * @throws \WeChat\Exceptions\LocalCacheException
  166. */
  167. public function deletePage($page_id)
  168. {
  169. $url = "https://api.weixin.qq.com/shakearound/page/delete?access_token=ACCESS_TOKEN";
  170. $this->registerApi($url, __FUNCTION__, func_get_args());
  171. return $this->httpPostForJson($url, ['page_id' => $page_id]);
  172. }
  173. /**
  174. * 上传图片素材
  175. * @param string $filename 图片名字
  176. * @param string $type Icon:摇一摇页面展示的icon图;License:申请开通摇一摇周边功能时需上传的资质文件;若不传type,则默认type=icon
  177. * @return array
  178. * @throws \WeChat\Exceptions\InvalidResponseException
  179. * @throws \WeChat\Exceptions\LocalCacheException
  180. */
  181. public function upload($filename, $type = 'icon')
  182. {
  183. $url = "https://api.weixin.qq.com/shakearound/material/add?access_token=ACCESS_TOKEN&type={$type}";
  184. $this->registerApi($url, __FUNCTION__, func_get_args());
  185. return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($filename)]);
  186. }
  187. /**
  188. * 配置设备与页面的关联关系
  189. * @param array $data
  190. * @return array
  191. * @throws \WeChat\Exceptions\InvalidResponseException
  192. * @throws \WeChat\Exceptions\LocalCacheException
  193. */
  194. public function bindPage(array $data)
  195. {
  196. $url = "https://api.weixin.qq.com/shakearound/device/bindpage?access_token=ACCESS_TOKEN";
  197. $this->registerApi($url, __FUNCTION__, func_get_args());
  198. return $this->httpPostForJson($url, $data);
  199. }
  200. /**
  201. * 查询设备与页面的关联关系
  202. * @param array $data
  203. * @return array
  204. * @throws \WeChat\Exceptions\InvalidResponseException
  205. * @throws \WeChat\Exceptions\LocalCacheException
  206. */
  207. public function queryPage(array $data)
  208. {
  209. $url = "https://api.weixin.qq.com/shakearound/relation/search?access_token=ACCESS_TOKEN";
  210. $this->registerApi($url, __FUNCTION__, func_get_args());
  211. return $this->httpPostForJson($url, $data);
  212. }
  213. /**
  214. * 以设备为维度的数据统计接口
  215. * @param array $data
  216. * @return array
  217. * @throws \WeChat\Exceptions\InvalidResponseException
  218. * @throws \WeChat\Exceptions\LocalCacheException
  219. */
  220. public function totalDevice(array $data)
  221. {
  222. $url = "https://api.weixin.qq.com/shakearound/statistics/device?access_token=ACCESS_TOKEN";
  223. $this->registerApi($url, __FUNCTION__, func_get_args());
  224. return $this->httpPostForJson($url, $data);
  225. }
  226. /**
  227. * 批量查询设备统计数据接口
  228. * @param integer $date 指定查询日期时间戳,单位为秒
  229. * @param integer $page_index 指定查询的结果页序号;返回结果按摇周边人数降序排序,每50条记录为一页
  230. * @return array
  231. * @throws \WeChat\Exceptions\InvalidResponseException
  232. * @throws \WeChat\Exceptions\LocalCacheException
  233. */
  234. public function totalDeviceList($date, $page_index = 1)
  235. {
  236. $url = "https://api.weixin.qq.com/shakearound/statistics/devicelist?access_token=ACCESS_TOKEN";
  237. $this->registerApi($url, __FUNCTION__, func_get_args());
  238. return $this->httpPostForJson($url, ['date' => $date, 'page_index' => $page_index]);
  239. }
  240. /**
  241. * 以页面为维度的数据统计接口
  242. * @param integer $page_id 指定页面的设备ID
  243. * @param integer $begin_date 起始日期时间戳,最长时间跨度为30天,单位为秒
  244. * @param integer $end_date 结束日期时间戳,最长时间跨度为30天,单位为秒
  245. * @return array
  246. * @throws \WeChat\Exceptions\InvalidResponseException
  247. * @throws \WeChat\Exceptions\LocalCacheException
  248. */
  249. public function totalPage($page_id, $begin_date, $end_date)
  250. {
  251. $url = "https://api.weixin.qq.com/shakearound/statistics/page?access_token=ACCESS_TOKEN";
  252. $this->registerApi($url, __FUNCTION__, func_get_args());
  253. return $this->httpPostForJson($url, ['page_id' => $page_id, 'begin_date' => $begin_date, 'end_date' => $end_date]);
  254. }
  255. /**
  256. * 编辑分组信息
  257. * @param integer $group_id 分组唯一标识,全局唯一
  258. * @param string $group_name 分组名称,不超过100汉字或200个英文字母
  259. * @return array
  260. * @throws \WeChat\Exceptions\InvalidResponseException
  261. * @throws \WeChat\Exceptions\LocalCacheException
  262. */
  263. public function updateGroup($group_id, $group_name)
  264. {
  265. $url = "https://api.weixin.qq.com/shakearound/device/group/update?access_token=ACCESS_TOKEN";
  266. $this->registerApi($url, __FUNCTION__, func_get_args());
  267. return $this->httpPostForJson($url, ['group_id' => $group_id, 'group_name' => $group_name]);
  268. }
  269. /**
  270. * 删除分组
  271. * @param integer $group_id 分组唯一标识,全局唯一
  272. * @return array
  273. * @throws \WeChat\Exceptions\InvalidResponseException
  274. * @throws \WeChat\Exceptions\LocalCacheException
  275. */
  276. public function deleteGroup($group_id)
  277. {
  278. $url = "https://api.weixin.qq.com/shakearound/device/group/delete?access_token=ACCESS_TOKEN";
  279. $this->registerApi($url, __FUNCTION__, func_get_args());
  280. return $this->httpPostForJson($url, ['group_id' => $group_id]);
  281. }
  282. /**
  283. * 查询分组列表
  284. * @param integer $begin 分组列表的起始索引值
  285. * @param integer $count 待查询的分组数量,不能超过1000个
  286. * @return array
  287. * @throws \WeChat\Exceptions\InvalidResponseException
  288. * @throws \WeChat\Exceptions\LocalCacheException
  289. */
  290. public function getGroupList($begin = 0, $count = 10)
  291. {
  292. $url = "https://api.weixin.qq.com/shakearound/device/group/getlist?access_token=ACCESS_TOKEN";
  293. $this->registerApi($url, __FUNCTION__, func_get_args());
  294. return $this->httpPostForJson($url, ['begin' => $begin, 'count' => $count]);
  295. }
  296. /**
  297. * 查询分组详情
  298. * @param integer $group_id 分组唯一标识,全局唯一
  299. * @param integer $begin 分组里设备的起始索引值
  300. * @param integer $count 待查询的分组里设备的数量,不能超过1000个
  301. * @return array
  302. * @throws \WeChat\Exceptions\InvalidResponseException
  303. * @throws \WeChat\Exceptions\LocalCacheException
  304. */
  305. public function getGroupDetail($group_id, $begin = 0, $count = 100)
  306. {
  307. $url = "https://api.weixin.qq.com/shakearound/device/group/getdetail?access_token=ACCESS_TOKEN";
  308. $this->registerApi($url, __FUNCTION__, func_get_args());
  309. return $this->httpPostForJson($url, ['group_id' => $group_id, 'begin' => $begin, 'count' => $count]);
  310. }
  311. /**
  312. * 添加设备到分组
  313. * @param array $data
  314. * @return array
  315. * @throws \WeChat\Exceptions\InvalidResponseException
  316. * @throws \WeChat\Exceptions\LocalCacheException
  317. */
  318. public function addDeviceGroup(array $data)
  319. {
  320. $url = "https://api.weixin.qq.com/shakearound/device/group/adddevice?access_token=ACCESS_TOKEN";
  321. $this->registerApi($url, __FUNCTION__, func_get_args());
  322. return $this->httpPostForJson($url, $data);
  323. }
  324. /**
  325. * 从分组中移除设备
  326. * @param array $data
  327. * @return array
  328. * @throws \WeChat\Exceptions\InvalidResponseException
  329. * @throws \WeChat\Exceptions\LocalCacheException
  330. */
  331. public function deleteDeviceGroup(array $data)
  332. {
  333. $url = "https://api.weixin.qq.com/shakearound/device/group/deletedevice?access_token=ACCESS_TOKEN";
  334. $this->registerApi($url, __FUNCTION__, func_get_args());
  335. return $this->httpPostForJson($url, $data);
  336. }
  337. }