Product.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 Product
  20. * @package WeChat
  21. */
  22. class Product extends BasicWeChat
  23. {
  24. /**
  25. * 提交审核/取消发布商品
  26. * @param string $keystandard 商品编码标准
  27. * @param string $keystr 商品编码内容
  28. * @param string $status 设置发布状态。on为提交审核,off为取消发布
  29. * @return array
  30. * @throws \WeChat\Exceptions\InvalidResponseException
  31. * @throws \WeChat\Exceptions\LocalCacheException
  32. */
  33. public function modStatus($keystandard, $keystr, $status = 'on')
  34. {
  35. $data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'status' => $status];
  36. $url = "https://api.weixin.qq.com/scan/product/modstatus?access_token=ACCESS_TOKEN";
  37. $this->registerApi($url, __FUNCTION__, func_get_args());
  38. return $this->httpPostForJson($url, $data);
  39. }
  40. /**
  41. * 设置测试人员白名单
  42. * @param array $openids 测试人员的openid列表
  43. * @param array $usernames 测试人员的微信号列表
  44. * @return array
  45. * @throws \WeChat\Exceptions\InvalidResponseException
  46. * @throws \WeChat\Exceptions\LocalCacheException
  47. */
  48. public function setTestWhiteList(array $openids = [], array $usernames = [])
  49. {
  50. $data = ['openid' => $openids, 'username' => $usernames];
  51. $url = "https://api.weixin.qq.com/scan/testwhitelist/set?access_token=ACCESS_TOKEN";
  52. $this->registerApi($url, __FUNCTION__, func_get_args());
  53. return $this->httpPostForJson($url, $data);
  54. }
  55. /**
  56. * 获取商品二维码
  57. * @param string $keystandard 商品编码标准
  58. * @param string $keystr 商品编码内容
  59. * @param integer $qrcode_size 二维码的尺寸(整型),数值代表边长像素数,不填写默认值为100
  60. * @param array $extinfo 由商户自定义传入,建议仅使用大小写字母、数字及-_().*这6个常用字符
  61. * @return array
  62. * @throws \WeChat\Exceptions\InvalidResponseException
  63. * @throws \WeChat\Exceptions\LocalCacheException
  64. */
  65. public function getQrcode($keystandard, $keystr, $qrcode_size, $extinfo = [])
  66. {
  67. $data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'qrcode_size' => $qrcode_size];
  68. empty($extinfo) || $data['extinfo'] = $extinfo;
  69. $url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN";
  70. $this->registerApi($url, __FUNCTION__, func_get_args());
  71. return $this->httpPostForJson($url, $data);
  72. }
  73. /**
  74. * 查询商品信息
  75. * @param string $keystandard 商品编码标准
  76. * @param string $keystr 商品编码内容
  77. * @return array
  78. * @throws \WeChat\Exceptions\InvalidResponseException
  79. * @throws \WeChat\Exceptions\LocalCacheException
  80. */
  81. public function getProduct($keystandard, $keystr)
  82. {
  83. $data = ['keystandard' => $keystandard, 'keystr' => $keystr];
  84. empty($extinfo) || $data['extinfo'] = $extinfo;
  85. $url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN";
  86. $this->registerApi($url, __FUNCTION__, func_get_args());
  87. return $this->httpPostForJson($url, $data);
  88. }
  89. /**
  90. * 批量查询商品信息
  91. * @param integer $offset 批量查询的起始位置,从0开始,包含该起始位置
  92. * @param integer $limit 批量查询的数量
  93. * @param null|string $status 支持按状态拉取。on为发布状态,off为未发布状态,check为审核中状态,reject为审核未通过状态,all为所有状态
  94. * @param string $keystr 支持按部分编码内容拉取。填写该参数后,可将编码内容中包含所传参数的商品信息拉出。类似关键词搜索
  95. * @return array
  96. * @throws \WeChat\Exceptions\InvalidResponseException
  97. * @throws \WeChat\Exceptions\LocalCacheException
  98. */
  99. public function getProductList($offset, $limit = 10, $status = null, $keystr = '')
  100. {
  101. $data = ['offset' => $offset, 'limit' => $limit];
  102. is_null($status) || $data['status'] = $status;
  103. empty($keystr) || $data['keystr'] = $keystr;
  104. $url = "https://api.weixin.qq.com/scan/product/get?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 updateProduct(array $data)
  116. {
  117. $url = "https://api.weixin.qq.com/scan/product/update?access_token=ACCESS_TOKEN";
  118. $this->registerApi($url, __FUNCTION__, func_get_args());
  119. return $this->httpPostForJson($url, $data);
  120. }
  121. /**
  122. * 清除商品信息
  123. * @param string $keystandard 商品编码标准
  124. * @param string $keystr 商品编码内容
  125. * @return array
  126. * @throws \WeChat\Exceptions\InvalidResponseException
  127. * @throws \WeChat\Exceptions\LocalCacheException
  128. */
  129. public function clearProduct($keystandard, $keystr)
  130. {
  131. $url = "https://api.weixin.qq.com/scan/product/clear?access_token=ACCESS_TOKEN";
  132. $this->registerApi($url, __FUNCTION__, func_get_args());
  133. return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
  134. }
  135. /**
  136. * 检查wxticket参数
  137. * @param string $ticket
  138. * @return array
  139. * @throws \WeChat\Exceptions\InvalidResponseException
  140. * @throws \WeChat\Exceptions\LocalCacheException
  141. */
  142. public function scanTicketCheck($ticket)
  143. {
  144. $url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
  145. $this->registerApi($url, __FUNCTION__, func_get_args());
  146. return $this->httpPostForJson($url, ['ticket' => $ticket]);
  147. }
  148. /**
  149. * 清除扫码记录
  150. * @param string $keystandard 商品编码标准
  151. * @param string $keystr 商品编码内容
  152. * @param string $extinfo 调用“获取商品二维码接口”时传入的extinfo,为标识参数
  153. * @return array
  154. * @throws \WeChat\Exceptions\InvalidResponseException
  155. * @throws \WeChat\Exceptions\LocalCacheException
  156. */
  157. public function clearScanticket($keystandard, $keystr, $extinfo)
  158. {
  159. $data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'extinfo' => $extinfo];
  160. $url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
  161. $this->registerApi($url, __FUNCTION__, func_get_args());
  162. return $this->httpPostForJson($url, $data);
  163. }
  164. }