Scan.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. * 扫一扫接入管理
  19. * Class Scan
  20. * @package WeChat
  21. */
  22. class Scan extends BasicWeChat
  23. {
  24. /**
  25. * 获取商户信息
  26. * @return array
  27. * @throws \WeChat\Exceptions\InvalidResponseException
  28. * @throws \WeChat\Exceptions\LocalCacheException
  29. */
  30. public function getMerchantInfo()
  31. {
  32. $url = "https://api.weixin.qq.com/scan/merchantinfo/get?access_token=ACCESS_TOKEN";
  33. $this->registerApi($url, __FUNCTION__, func_get_args());
  34. return $this->httpGetForJson($url);
  35. }
  36. /**
  37. * 创建商品
  38. * @param array $data
  39. * @return array
  40. * @throws \WeChat\Exceptions\InvalidResponseException
  41. * @throws \WeChat\Exceptions\LocalCacheException
  42. */
  43. public function addProduct(array $data)
  44. {
  45. $url = "https://api.weixin.qq.com/scan/product/create?access_token=ACCESS_TOKEN";
  46. $this->registerApi($url, __FUNCTION__, func_get_args());
  47. return $this->httpPostForJson($url, $data);
  48. }
  49. /**
  50. * 商品发布
  51. * @param string $keystandard 商品编码标准
  52. * @param string $keystr 商品编码内容
  53. * @param string $status 设置发布状态。on为提交审核,off为取消发布
  54. * @return array
  55. * @throws \WeChat\Exceptions\InvalidResponseException
  56. * @throws \WeChat\Exceptions\LocalCacheException
  57. */
  58. public function modProduct($keystandard, $keystr, $status = 'on')
  59. {
  60. $data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'status' => $status];
  61. $url = "https://api.weixin.qq.com/scan/product/modstatus?access_token=ACCESS_TOKEN";
  62. $this->registerApi($url, __FUNCTION__, func_get_args());
  63. return $this->httpPostForJson($url, $data);
  64. }
  65. /**
  66. * 设置测试人员白名单
  67. * @param array $openids 测试人员的openid列表
  68. * @param array $usernames 测试人员的微信号列表
  69. * @return array
  70. * @throws \WeChat\Exceptions\InvalidResponseException
  71. * @throws \WeChat\Exceptions\LocalCacheException
  72. */
  73. public function setTestWhiteList($openids = [], $usernames = [])
  74. {
  75. $data = ['openid' => $openids, 'username' => $usernames];
  76. $url = "https://api.weixin.qq.com/scan/product/modstatus?access_token=ACCESS_TOKEN";
  77. $this->registerApi($url, __FUNCTION__, func_get_args());
  78. return $this->httpPostForJson($url, $data);
  79. }
  80. /**
  81. * 获取商品二维码
  82. * @param string $keystandard
  83. * @param string $keystr
  84. * @param null|string $extinfo
  85. * @param integer $qrcode_size
  86. * @return array
  87. * @throws \WeChat\Exceptions\InvalidResponseException
  88. * @throws \WeChat\Exceptions\LocalCacheException
  89. */
  90. public function getQrc($keystandard, $keystr, $extinfo = null, $qrcode_size = 64)
  91. {
  92. $data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'qrcode_size' => $qrcode_size];
  93. is_null($extinfo) || $data['extinfo'] = $extinfo;
  94. $url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN";
  95. $this->registerApi($url, __FUNCTION__, func_get_args());
  96. return $this->httpPostForJson($url, $data);
  97. }
  98. /**
  99. * 查询商品信息
  100. * @param string $keystandard 商品编码标准
  101. * @param string $keystr 商品编码内容
  102. * @return array
  103. * @throws \WeChat\Exceptions\InvalidResponseException
  104. * @throws \WeChat\Exceptions\LocalCacheException
  105. */
  106. public function getProductInfo($keystandard, $keystr)
  107. {
  108. $url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN";
  109. $this->registerApi($url, __FUNCTION__, func_get_args());
  110. return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
  111. }
  112. /**
  113. * 批量查询商品信息
  114. * @param integer $offset 批量查询的起始位置,从0开始,包含该起始位置。
  115. * @param integer $limit 批量查询的数量。
  116. * @param string $status 支持按状态拉取。on为发布状态,off为未发布状态,check为审核中状态,reject为审核未通过状态,all为所有状态。
  117. * @param string $keystr 支持按部分编码内容拉取。填写该参数后,可将编码内容中包含所传参数的商品信息拉出。类似关键词搜索。
  118. * @return array
  119. * @throws \WeChat\Exceptions\InvalidResponseException
  120. * @throws \WeChat\Exceptions\LocalCacheException
  121. */
  122. public function getProductList($offset = 1, $limit = 10, $status = null, $keystr = null)
  123. {
  124. $data = ['offset' => $offset, 'limit' => $limit];
  125. is_null($status) || $data['status'] = $status;
  126. is_null($keystr) || $data['keystr'] = $keystr;
  127. $url = "https://api.weixin.qq.com/scan/product/getlist?access_token=ACCESS_TOKEN";
  128. $this->registerApi($url, __FUNCTION__, func_get_args());
  129. return $this->httpPostForJson($url, $data);
  130. }
  131. /**
  132. * 更新商品信息
  133. * @param array $data
  134. * @return array
  135. * @throws \WeChat\Exceptions\InvalidResponseException
  136. * @throws \WeChat\Exceptions\LocalCacheException
  137. */
  138. public function updateProduct(array $data)
  139. {
  140. $url = "https://api.weixin.qq.com/scan/product/update?access_token=ACCESS_TOKEN";
  141. $this->registerApi($url, __FUNCTION__, func_get_args());
  142. return $this->httpPostForJson($url, $data);
  143. }
  144. /**
  145. * 清除商品信息
  146. * @param string $keystandard 商品编码标准
  147. * @param string $keystr 商品编码内容
  148. * @return array
  149. * @throws \WeChat\Exceptions\InvalidResponseException
  150. * @throws \WeChat\Exceptions\LocalCacheException
  151. */
  152. public function clearProduct($keystandard, $keystr)
  153. {
  154. $url = "https://api.weixin.qq.com/scan/product/clear?access_token=ACCESS_TOKEN";
  155. $this->registerApi($url, __FUNCTION__, func_get_args());
  156. return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
  157. }
  158. /**
  159. * 检查wxticket参数
  160. * @param string $ticket
  161. * @return array
  162. * @throws \WeChat\Exceptions\InvalidResponseException
  163. * @throws \WeChat\Exceptions\LocalCacheException
  164. */
  165. public function checkTicket($ticket)
  166. {
  167. $url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
  168. $this->registerApi($url, __FUNCTION__, func_get_args());
  169. return $this->httpPostForJson($url, ['ticket' => $ticket]);
  170. }
  171. /**
  172. * 清除扫码记录
  173. * @param string $keystandard 商品编码标准
  174. * @param string $keystr 商品编码内容
  175. * @param string $extinfo 调用“获取商品二维码接口”时传入的extinfo,为标识参数
  176. * @return array
  177. * @throws \WeChat\Exceptions\InvalidResponseException
  178. * @throws \WeChat\Exceptions\LocalCacheException
  179. */
  180. public function clearScanTicket($keystandard, $keystr, $extinfo)
  181. {
  182. $url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
  183. $this->registerApi($url, __FUNCTION__, func_get_args());
  184. return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr, 'extinfo' => $extinfo]);
  185. }
  186. }