LiveClient.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services\wechat\live;
  12. use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
  13. use EasyWeChat\Kernel\Support\Collection;
  14. use EasyWeChat\MiniProgram\Live\Client;
  15. use GuzzleHttp\Exception\GuzzleException;
  16. use Psr\Http\Message\ResponseInterface;
  17. /**
  18. * 小程序直播间服务
  19. * Class LiveClient
  20. * @package crmeb\services\wechat\live
  21. */
  22. class LiveClient extends Client
  23. {
  24. //创建直播间
  25. const CREATE_LIVE_ROOM = 'wxaapi/broadcast/room/create';
  26. //直播间导入商品
  27. const LIVE_ROOM_ADD_GOODS = 'wxaapi/broadcast/room/addgoods';
  28. //获取商品列表信息
  29. const GOODS_LIST = 'wxaapi/broadcast/goods/getapproved';
  30. //商品添加并审核
  31. const GOODS_ADD = 'wxaapi/broadcast/goods/add';
  32. //撤回审核
  33. const GOODS_RESET_AUDIT = 'wxaapi/broadcast/goods/resetaudit';
  34. //重新提交审核
  35. const GOODS_AUDIT = 'wxaapi/broadcast/goods/autdit';
  36. //删除商品
  37. const GOODS_DELETE = 'wxaapi/broadcast/goods/delete';
  38. //更新商品
  39. const GOODS_UPDATE = 'wxaapi/broadcast/goods/update';
  40. //获取商品状态
  41. const GOODS_INFO = 'wxa/business/getgoodswarehouse';
  42. //获取成员列表
  43. const ROLE_LIST = 'wxaapi/broadcast/role/getrolelist';
  44. /**
  45. * 添加直播间参数
  46. * @var array
  47. */
  48. protected $create_data = [
  49. 'name' => '', // 房间名字
  50. 'coverImg' => '', // 通过 uploadfile 上传,填写 mediaID
  51. 'startTime' => 0, // 开始时间
  52. 'endTime' => 0, // 结束时间
  53. 'anchorName' => '', // 主播昵称
  54. 'anchorWechat' => '', // 主播微信号
  55. 'shareImg' => '', //通过 uploadfile 上传,填写 mediaID
  56. 'feedsImg' => '', //通过 uploadfile 上传,填写 mediaID
  57. 'isFeedsPublic' => 1, // 是否开启官方收录,1 开启,0 关闭
  58. 'type' => 1, // 直播类型,1 推流 0 手机直播
  59. 'screenType' => 0, // 1:横屏 0:竖屏
  60. 'closeLike' => 0, // 是否 关闭点赞 1 关闭
  61. 'closeGoods' => 0, // 是否 关闭商品货架,1:关闭
  62. 'closeComment' => 0, // 是否开启评论,1:关闭
  63. 'closeReplay' => 1, // 是否关闭回放 1 关闭
  64. 'closeShare' => 0, // 是否关闭分享 1 关闭
  65. 'closeKf' => 0 // 是否关闭客服,1 关闭
  66. ];
  67. /**
  68. * 创建直播间
  69. * @param array $data
  70. * @return array|Collection|object|ResponseInterface|string
  71. * @throws InvalidConfigException
  72. * @throws GuzzleException
  73. */
  74. public function createRoom(array $data)
  75. {
  76. $params = array_merge($this->create_data, $data);
  77. return $this->httpPostJson(self::CREATE_LIVE_ROOM, $params);
  78. }
  79. /**
  80. * 直播间导入商品
  81. * @param int $room_id
  82. * @param $ids
  83. * @return array|Collection|object|ResponseInterface|string
  84. * @throws GuzzleException
  85. * @throws InvalidConfigException
  86. */
  87. public function roomAddGoods(int $room_id, $ids)
  88. {
  89. $params = [
  90. 'ids' => $ids,
  91. 'roomId' => $room_id
  92. ];
  93. return $this->httpPostJson(self::LIVE_ROOM_ADD_GOODS, $params);
  94. }
  95. /**
  96. * 获取商品列表
  97. * @param $status
  98. * @param int $page
  99. * @param int $limit
  100. * @return array|Collection|object|ResponseInterface|string
  101. * @throws GuzzleException
  102. * @throws InvalidConfigException
  103. */
  104. public function getGoodsList($status, int $page = 0, $limit = 30)
  105. {
  106. $params = [
  107. 'offset' => $page * $limit,
  108. 'limit' => $limit,
  109. 'status' => $status
  110. ];
  111. return $this->httpGet(self::GOODS_LIST, $params);
  112. }
  113. /**
  114. * 获取商品详情
  115. * @param $ids
  116. * @return array|Collection|object|ResponseInterface|string
  117. * @throws GuzzleException
  118. * @throws InvalidConfigException
  119. */
  120. public function getGooodsInfo($ids)
  121. {
  122. $params = [
  123. 'goods_ids' => $ids
  124. ];
  125. return $this->httpPostJson(self::GOODS_INFO, $params);
  126. }
  127. /**
  128. * 添加商品
  129. * @param string $coverImgUrl
  130. * @param string $name
  131. * @param int $priceType
  132. * @param string $url
  133. * @param $price
  134. * @param string $price2
  135. * @return array|Collection|object|ResponseInterface|string
  136. * @throws GuzzleException
  137. * @throws InvalidConfigException
  138. */
  139. public function addGoods(string $coverImgUrl, string $name, int $priceType, string $url, $price, $price2 = '')
  140. {
  141. $params = [
  142. 'goodsInfo' => [
  143. 'coverImgUrl' => $coverImgUrl,
  144. 'name' => $name,
  145. 'priceType' => $priceType,
  146. 'price' => $price,
  147. 'url' => $url
  148. ]
  149. ];
  150. if ($priceType != 1) $params['goodsInfo']['price2'] = $price2;
  151. return $this->httpPostJson(self::GOODS_ADD, $params);
  152. }
  153. /**
  154. * 商品撤回审核
  155. * @param int $goodsId
  156. * @param int $auditId
  157. * @return array|Collection|object|ResponseInterface|string
  158. * @throws GuzzleException
  159. * @throws InvalidConfigException
  160. */
  161. public function resetauditGoods(int $goodsId, int $auditId)
  162. {
  163. $params = [
  164. 'goodsId' => $goodsId,
  165. 'auditId' => $auditId
  166. ];
  167. return $this->httpPostJson(self::GOODS_RESET_AUDIT, $params);
  168. }
  169. /**
  170. * 商品重新提交审核
  171. * @param int $goodsId
  172. * @return array|Collection|object|ResponseInterface|string
  173. * @throws GuzzleException
  174. * @throws InvalidConfigException
  175. */
  176. public function auditGoods(int $goodsId)
  177. {
  178. $params = [
  179. 'goodsId' => $goodsId
  180. ];
  181. return $this->httpPostJson(self::GOODS_AUDIT, $params);
  182. }
  183. /**
  184. * 删除商品
  185. * @param int $goodsId
  186. * @return array|Collection|object|ResponseInterface|string
  187. * @throws GuzzleException
  188. * @throws InvalidConfigException
  189. */
  190. public function deleteGoods(int $goodsId)
  191. {
  192. $params = [
  193. 'goodsId' => $goodsId
  194. ];
  195. return $this->httpPostJson(self::GOODS_DELETE, $params);
  196. }
  197. /**
  198. * 更新商品
  199. * @param int $goodsId
  200. * @param string $coverImgUrl
  201. * @param string $name
  202. * @param int $priceType
  203. * @param string $url
  204. * @param $price
  205. * @param string $price2
  206. * @return array|Collection|object|ResponseInterface|string
  207. * @throws GuzzleException
  208. * @throws InvalidConfigException
  209. */
  210. public function updateGoods(int $goodsId, string $coverImgUrl, string $name, int $priceType, string $url, $price, $price2 = '')
  211. {
  212. $params = ['goodsInfo' => [
  213. 'goodsId' => $goodsId,
  214. 'coverImgUrl' => $coverImgUrl,
  215. 'name' => $name,
  216. 'priceType' => $priceType,
  217. 'price' => $price,
  218. 'url' => $url
  219. ]];
  220. if ($priceType != 1) $params['goodsInfo']['price2'] = $price2;
  221. return $this->httpPostJson(self::GOODS_UPDATE, $params);
  222. }
  223. /**
  224. * 获取成员列表
  225. * @param int $role
  226. * @param int $page
  227. * @param int $limit
  228. * @param string $keyword
  229. * @return array|Collection|object|ResponseInterface|string
  230. * @throws GuzzleException
  231. * @throws InvalidConfigException
  232. */
  233. public function getRoleList($role = 2, int $page = 0, $limit = 30, $keyword = '')
  234. {
  235. $params = [
  236. 'role' => $role,
  237. 'offset' => $page * $limit,
  238. 'limit' => $limit,
  239. 'keyword' => $keyword
  240. ];
  241. return $this->httpGet(self::ROLE_LIST, $params);
  242. }
  243. }