/** * 获取颜色列表. * * @return array */ public function lists() { $key = 'overtrue.wechat.colors'; return $this->cache->get($key, function ($key) { $result = $this->http->get(self::API_LIST); $this->cache->set($key, $result['colors'], 86400); // 1 day return $result['colors']; }); }
/** * Get token from WeChat API. * * @return string */ public function getToken() { $cacheKey = $this->prefix . $this->appId; return $this->cache->get($cacheKey, function ($cacheKey) { $params = ['appid' => $this->appId, 'secret' => $this->secret, 'grant_type' => 'client_credential']; $token = $this->http->get(self::API_TOKEN_GET, $params); $this->cache->set($cacheKey, $token['access_token'], $token['expires_in'] - 100); return $token['access_token']; }); }
/** * Download temporary material. * * @param string $mediaId * @param string $directory * @param string $filename * * @return string * * @throws InvalidArgumentException */ public function download($mediaId, $directory, $filename = '') { if (!is_dir($directory) || !is_writable($directory)) { throw new InvalidArgumentException("Directory does not exist or is not writable: '{$directory}'."); } $filename = $filename ?: $mediaId; $stream = $this->http->get(self::API_GET, ['media_id' => $mediaId]); $ext = File::getStreamExt($stream); file_put_contents($directory . '/' . $filename . '.' . $ext, $stream); return $filename . '.' . $ext; }
/** * Get jsticket. * * @return string */ public function ticket() { $key = self::TICKET_CACHE_PREFIX . $this->appId; return $this->cache->get($key, function ($key) { $result = $this->http->get(self::API_TICKET); $this->cache->set($key, $result['ticket'], $result['expires_in'] - 500); return $result['ticket']; }); }
/** * 图片素材总数. * * @param string $type * * @return array|int */ public function stats($type = null) { $response = $this->http->get(self::API_FOREVER_COUNT); $response['voice'] = $response['voice_count']; $response['image'] = $response['image_count']; $response['video'] = $response['video_count']; $response['news'] = $response['news_count']; $response = new Collection($response); return $type ? $response->get($type) : $response; }
/** * Get JSSDK ticket. * * @return string */ public function getTicket() { if ($this->ticket) { return $this->ticket; } $key = 'overtrue.wechat.card.api_ticket'; return $this->ticket = $this->cache->get($key, function ($key) { $result = $this->http->get(self::API_TICKET); $this->cache->set($key, $result['ticket'], $result['expires_in']); return $result['ticket']; }); }
/** * Get stats of materials. * * @return array */ public function stats() { return $this->http->get(self::API_STATS); }
/** * Get current menus setting. * * @return array */ public function current() { return $this->http->get(self::API_QUERY); }
/** * Return media stream. * * @return string */ public function getStream($mediaId) { return $this->http->get(self::API_GET, ['media_id' => $mediaId]); }
/** * List users. * * @param string $nextOpenId * * @return Collection */ public function lists($nextOpenId = null) { $params = ['next_openid' => $nextOpenId]; return new Collection($this->http->get(self::API_LIST, $params)); }
/** * Get User by access token. * * @param string $openId * @param string $accessToken * * @return Collection */ public function getUserByAccessToken($openId, $accessToken) { $queries = $this->getUserFields($openId, $accessToken); return $this->http->get(self::USER_URL, $queries); }
/** * Delete a staff. * * @param string $email * * @return bool */ public function delete($email) { $params = ['kf_account' => $email]; return $this->http->get(self::API_DELETE, $params); }
/** * List all groups. * * @return array */ public function lists() { $response = $this->http->get(self::API_GET); return $response['groups']; }
/** * List all online staffs. * * @return array */ public function onlines() { $response = $this->http->get(self::API_ONLINE); return $response['kf_online_list']; }
/** * 获取access token. * * @param string $code * * @return string */ public function getAccessPermission($code) { $params = ['appid' => $this->appId, 'secret' => $this->appSecret, 'code' => $code, 'grant_type' => 'authorization_code']; return $this->lastPermission = $this->http->get(self::API_TOKEN_GET, $params); }
/** * 获取菜单【查询接口,能获取到任意方式设置的菜单】. * * @return array */ public function current() { $menus = $this->http->get(self::API_QUERY); return empty($menus) ? [] : $menus; }