/** * Send an voice message to a user * * @param integer $customer * @param integer $mediaId * @return void */ public function sendArticle($customer, $mediaId) { try { $this->httpService->request('POST', 'message/custom/send', ['form_params' => ['touser' => $customer, 'msgtype' => 'mpnews', 'mpnews' => ['media_id' => $mediaId]]]); } catch (\Exception $e) { $this->logError($e); } }
/** * Execute the console command. */ public function handle() { switch ($this->argument('action')) { case 'show': $this->runCommand(function () { return $this->service->request('GET', 'groups/get'); }, function ($resp) { $this->sayError($resp); collect($resp->get('groups'))->each(function ($item) { $this->info("{$item['name']}({$item['id']}) count: {$item['count']}"); }); }); break; case 'query': $openId = $this->ask('openid: '); $this->runCommand(function () use($openId) { return $this->service->request('POST', 'groups/getid', ['json' => ['openid' => $openId]]); }, function ($resp) { $this->sayError($resp); $this->info("Group Id is {$resp->get('groupid')}"); }); break; case 'rename': $id = $this->ask('group id [assigned by Weixin]: '); $name = $this->ask('new name: '); $this->runCommand(function () use($id, $name) { return $this->service->request('POST', 'groups/update', ['json' => ['group' => ['id' => $id, 'name' => $name]]]); }, function ($resp) { $this->sayError($resp); $this->info('Successfully rename a group'); }, function () use($id, $name) { DB::table('groups')->where('id', $id)->update(['name' => $name]); }); break; case 'delete': $id = $this->ask('group id [assigned by Weixin]: '); $this->runCommand(function () use($id) { return $this->service->request('POST', 'groups/delete', ['json' => ['group' => ['id' => $id]]]); }, function ($resp) { $this->sayError($resp); $this->info('Successfully delete a group'); }, function () use($id) { DB::table('groups')->where('id', $id)->delete(); }); break; case 'create': $name = $this->ask('name: '); $this->runCommand(function () use($name) { return $this->service->request('POST', 'groups/create', ['json' => ['group' => ['name' => $name]]]); }, function ($resp) use(&$id) { $this->sayError($resp); $id = $resp->get('group')['id']; $this->info("Create a group: {$resp->get('group')['id']} {$resp->get('group')['name']}"); }, function () use(&$id, $name) { DB::table('groups')->insert(['id' => $id, 'name' => $name]); }); break; default: $this->error('Unknown action: ' . $this->argument('action')); } }