Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $accountId = $this->argument('account_id');
     /*
      * 1 获取Account
      */
     $account = $this->getAccount($accountId);
     $fanGroupModel = new FanGroupModel();
     /*
      * 2 初始化 SDK Config, 构建 SDK 对象
      */
     $groupService = new Group($account->app_id, $account->app_secret);
     $groups = $groupService->lists();
     if ($groups) {
         $insert = [];
         $this->output->progressStart(count($groups));
         foreach ($groups as $groupKey => $group) {
             $insert[$groupKey]['group_id'] = $group['id'];
             $insert[$groupKey]['account_id'] = $account->id;
             $insert[$groupKey]['title'] = $group['name'];
             $insert[$groupKey]['fan_count'] = $group['count'];
             $insert[$groupKey]['is_default'] = in_array($group['name'], ['默认组', '屏蔽组', '星标组']) ? 1 : 0;
             $this->info("\t{$group['name']} created!");
             $this->output->progressAdvance();
         }
         /*
          * clean
          */
         $fanGroupModel->where('account_id', $account->id)->forceDelete();
         $result = $fanGroupModel->insert($insert);
     }
     $this->output->progressFinish();
 }
 /**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function index()
 {
     $appId = config('wechat.app_id');
     $secret = config('wechat.secret');
     $encoding_key = config('wechat.encoding_key');
     //$card = new Card($appId, $secret);
     //		var_dump($card->lists());
     //exit;
     $group = new Group($appId, $secret);
     var_dump($group->lists());
     exit;
     return view('welcome');
 }
Exemplo n.º 3
0
 /**
  * 获取微信公众号用户分组列表
  *
  * @param Request $request POST请求
  *
  * @return JSON
  */
 public function getGroupList(Request $request)
 {
     if ($request->isMethod('post')) {
         $appId = $request->appId;
         $app = WechatApp::getAppById($appId);
         if (isset($app)) {
             $group = new Group($app['app_id'], $app['app_secret']);
             try {
                 $list = $group->lists();
                 return json_encode($list);
             } catch (\Exception $e) {
                 echo '获取用户分组列表失败:' . $e->getMessage();
             }
         }
     }
 }