| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace crmeb\services\easywechat\broadcast;
- use EasyWeChat\Core\Exceptions\HttpException;
- use EasyWeChat\MiniProgram\Core\AbstractMiniProgram;
- /**
- * Class Client.
- *
- * @author Abbotton <uctoo@foxmail.com>
- */
- class Client extends AbstractMiniProgram
- {
- const MSG_CODE = [
- '1' => '未创建直播间',
- '1003' => '商品id不存在',
- '47001' => '入参格式不符合规范',
- '200002' => '入参错误',
- '300001' => '禁止创建/更新商品 或 禁止编辑&更新房间',
- '300002' => '名称长度不符合规则',
- '300006' => '图片上传失败',
- '300022' => '此房间号不存在',
- '300023' => '房间状态 拦截',
- '300024' => '商品不存在',
- '300025' => '商品审核未通过',
- '300026' => '房间商品数量已经满额',
- '300027' => '导入商品失败',
- '300028' => '房间名称违规',
- '300029' => '主播昵称违规',
- '300030' => '主播微信号不合法',
- '300031' => '直播间封面图不合规',
- '300032' => '直播间分享图违规',
- '300033' => '添加商品超过直播间上限',
- '300034' => '主播微信昵称长度不符合要求',
- '300035' => '主播微信号不存在',
- '300003' => '价格输入不合规',
- '300004' => '商品名称存在违规违法内容',
- '300005' => '商品图片存在违规违法内容',
- '300007' => '线上小程序版本不存在该链接',
- '300008' => '添加商品失败',
- '300009' => '商品审核撤回失败',
- '300010' => '商品审核状态不对',
- '300011' => '操作非法',
- '300012' => '没有提审额度',
- '300013' => '提审失败',
- '300014' => '审核中,无法删除',
- '300017' => '商品未提审',
- '300018' => '图片尺寸不符合要求',
- '300021' => '商品添加成功,审核失败',
- '300036' => '请先在微信直播小程序中实名认证',
- '300038' => '请先在小程序后台配置直播客服',
- '-1' => '系统错误',
- ];
- const API = 'https://api.weixin.qq.com/';
- /**
- * @param $api
- * @param $params
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- protected function httpPostJson($api, $params)
- {
- try {
- return $this->parseJSON('json', [self::API . $api, $params]);
- } catch (HttpException $e) {
- $code = $e->getCode();
- throw new HttpException("接口异常[$code]" . (self::MSG_CODE[$code] ?? $e->getMessage()), $code);
- }
- }
- /**
- * @param $api
- * @param $params
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- protected function httpPost($api, $params)
- {
- try {
- return $this->parseJSON('post', [self::API . $api, $params]);
- } catch (HttpException $e) {
- $code = $e->getCode();
- throw new HttpException("接口异常[$code]" . (self::MSG_CODE[$code] ?? $e->getMessage()), $code);
- }
- }
- /**
- * @param $api
- * @param $params
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- protected function httpGet($api, $params)
- {
- try {
- return $this->parseJSON('get', [self::API . $api, $params]);
- } catch (HttpException $e) {
- $code = $e->getCode();
- throw new HttpException("接口异常[$code]" . (self::MSG_CODE[$code] ?? $e->getMessage()), $code);
- }
- }
- /**
- * Add broadcast goods.
- *
- * @param array $goodsInfo
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function create(array $goodsInfo)
- {
- $params = [
- 'goodsInfo' => $goodsInfo,
- ];
- return $this->httpPostJson('wxaapi/broadcast/goods/add', $params);
- }
- /**
- * Reset audit.
- *
- * @param int $auditId
- * @param int $goodsId
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function resetAudit(int $auditId, int $goodsId)
- {
- $params = [
- 'auditId' => $auditId,
- 'goodsId' => $goodsId,
- ];
- return $this->httpPostJson('wxaapi/broadcast/goods/resetaudit', $params);
- }
- /**
- * Resubmit audit goods.
- *
- * @param int $goodsId
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function resubmitAudit(int $goodsId)
- {
- $params = [
- 'goodsId' => $goodsId,
- ];
- return $this->httpPostJson('wxaapi/broadcast/goods/audit', $params);
- }
- /**
- * Delete broadcast goods.
- *
- * @param int $goodsId
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function delete(int $goodsId)
- {
- $params = [
- 'goodsId' => $goodsId,
- ];
- try{
- return $this->httpPostJson('wxaapi/broadcast/goods/delete', $params);
- } catch (HttpException $exception) {
- if ($exception->getCode() == 300015) return ;
- }
- }
- /**
- * Update goods info.
- *
- * @param array $goodsInfo
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function update(array $goodsInfo)
- {
- $params = [
- 'goodsInfo' => $goodsInfo,
- ];
- return $this->httpPostJson('wxaapi/broadcast/goods/update', $params);
- }
- /**
- * Get goods information and review status.
- *
- * @param array $goodsIdArray
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function getGoodsWarehouse(array $goodsIdArray)
- {
- $params = [
- 'goods_ids' => $goodsIdArray,
- ];
- return $this->httpPostJson('wxa/business/getgoodswarehouse', $params);
- }
- /**
- * Get goods list based on status
- *
- * @param array $params
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function getApproved(array $params)
- {
- return $this->httpGet('wxaapi/broadcast/goods/getapproved', $params);
- }
- /**
- * Add goods to the designated live room.
- *
- * @param array $params
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function addGoods(array $params)
- {
- return $this->httpPost('wxaapi/broadcast/room/addgoods', $params);
- }
- /**
- * Get Room List.
- *
- * @param int $start
- * @param int $limit
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function getRooms(int $start = 0, int $limit = 10)
- {
- $params = [
- 'start' => $start,
- 'limit' => $limit,
- ];
- return $this->httpPostJson('wxa/business/getliveinfo', $params);
- }
- /**
- * Get Playback List.
- *
- * @param int $roomId
- * @param int $start
- * @param int $limit
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function getPlaybacks(int $roomId, int $start = 0, int $limit = 10)
- {
- $params = [
- 'action' => 'get_replay',
- 'room_id' => $roomId,
- 'start' => $start,
- 'limit' => $limit,
- ];
- return $this->httpPostJson('wxa/business/getliveinfo', $params);
- }
- /**
- * Create a live room.
- *
- * @param array $params
- * @return \EasyWeChat\Support\Collection|null
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- */
- public function createLiveRoom(array $params)
- {
- return $this->httpPostJson('wxaapi/broadcast/room/create', $params);
- }
- /**
- *
- * @param int $roomId
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/22/21
- */
- public function getPushUrl(int $roomId)
- {
- $params = [
- 'roomId' => $roomId,
- ];
- return $this->httpGet('wxaapi/broadcast/room/getpushurl', $params);
- }
- /**
- * 是否关闭客服 【0:开启,1:关闭】
- * @param int $roomId
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/22/21
- */
- public function closeKf(int $roomId,int $status)
- {
- $params = [
- 'roomId' => $roomId,
- 'closeKf' => $status ? 1 : 0,
- ];
- return $this->httpPostJson('wxaapi/broadcast/room/updatekf', $params);
- }
- /**
- * 1-禁言,0-取消禁言
- * @param int $roomId
- * @param int $type
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/22/21
- */
- public function banComment(int $roomId, int $status)
- {
- $params = [
- 'roomId' => $roomId,
- 'banComment' => $status ? 1 : 0,
- ];
- return $this->httpPostJson('wxaapi/broadcast/room/updatecomment', $params);
- }
- /**
- * 添加助手
- * @param array $params
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/25/21
- */
- public function addAssistant(array $params)
- {
- return $this->httpPostJson('wxaapi/broadcast/room/addassistant', $params);
- }
- /**
- * 删除助手
- * @param array $params
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/25/21
- */
- public function removeAssistant(int $roomId, string $username)
- {
- $params = [
- 'roomId' => $roomId,
- 'username' => $username,
- ];
- return $this->httpPostJson('wxaapi/broadcast/room/removeassistant', $params);
- }
- /**
- * 修改小助手
- * @param array $params
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/25/21
- */
- public function modifyAssistant(array $params)
- {
- return $this->httpPostJson('wxaapi/broadcast/room/modifyassistant', $params);
- }
- /**
- * 助手列表
- * @param int $roomId
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/25/21
- * wxa/business/get_wxa_followers?access_token=
- */
- public function getAssistantList(int $roomId)
- {
- $params = [
- 'roomId' => $roomId,
- ];
- return $this->httpGet('wxaapi/broadcast/room/getassistantlist', $params);
- }
- /**
- * 获取长期订阅用户
- * @param int $roomId
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/25/21
- */
- public function getFollowers(string $page, int $limit = 2000)
- {
- $params['limit'] = $limit;
- if ($page) $params['page_break'] = $page;
- return $this->httpPostJson('wxa/business/get_wxa_followers', $params);
- }
- /**
- * 群发发送订阅
- * @param int $roomId
- * @param array $data
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/25/21
- */
- public function pushMessage(int $roomId, array $data)
- {
- $params = [
- 'room_id' => $roomId,
- 'user_openid' => $data,
- ];
- return $this->httpPostJson('wxa/business/push_message', $params);
- }
- /**
- * 更新官方收录
- * @param int $roomId
- * @param int $status
- * @return \EasyWeChat\Support\Collection|null
- * @author Qinii
- * @day 10/30/21
- */
- public function updateFeedPublic(int $roomId, int $status)
- {
- $params = [
- 'roomId' => $roomId,
- 'isFeedsPublic' => $status ? 1 : 0,
- ];
- return $this->httpPostJson('wxaapi/broadcast/room/updatefeedpublic', $params);
- }
- public function goodsOnsale(int $roomId, int $goodsId, int $status)
- {
- $params = [
- 'roomId' => $roomId,
- 'goodsId' => $goodsId,
- 'onSale' => $status ? 1 : 0,
- ];
- return $this->httpPostJson('wxaapi/broadcast/goods/onsale', $params);
- }
- }
|