access_token->getToken()['access_token']; $params = ['access_token'=>$accessToken,'status'=>$type,'offset'=>$limitOffset-1,'limit'=>$limitLength]; $result = $app->broadcast->getApproved($params); if (0 != $result['errcode']) { throw new WechatException( $result['errmsg'],$result['errcode'] ); } $goodsList = []; foreach ($result['goods'] as $goods){ $goodsList[] = [ 'goods_id' => $goods['goodsId'], 'name' => $goods['name'], 'image' => $goods['coverImgUrl'], 'price_type' => $goods['priceType'], 'url' => $goods['url'], 'price' => $goods['price'], 'price2' => $goods['price2'], ]; } $list = [ 'lists' => $goodsList, 'count' => $result['total'], 'page_no' => $limitOffset, 'page_size' => $limitLength, ]; return $list; }catch (Exception $e){ return $e->getMessage(); } } /** * @notes 添加直播商品 * @param array $post * @return bool|string * @author cjhao * @date 2021/11/23 16:25 */ public function add(array $post) { try { $data = [ 'coverImgUrl' => $post['image'], 'name' => $post['name'], 'priceType' => $post['price_type'], 'price' => $post['price'], 'price2' => $post['price2'], 'url' => $post['url'], ]; $config = WeChatConfigService::getMnpConfig(); $app = Factory::miniProgram($config); $result = $app->broadcast->create($data); if (0 != $result['errcode']) { throw new WechatException($result['errmsg'],$result['errcode']); } return true; } catch (\Exception $e) { return $e->getMessage(); } } /** * @notes 删除直播商品 * @param int $goods_id * @author cjhao * @date 2021/11/23 18:02 */ public function del(int $goodsId) { try { $config = WeChatConfigService::getMnpConfig(); $app = Factory::miniProgram($config); $result = $app->broadcast->delete($goodsId); if (0 != $result['errcode']) { throw new WechatException($result['errmsg'],$result['errcode']); } return true; } catch (Exception $e) { return $e->getMessage(); } } }