国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
13KB

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