Пример #1
0
 /**
  * 获取颜色列表.
  *
  * @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'];
     });
 }
Пример #2
0
 /**
  * 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'];
     });
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * 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'];
     });
 }
Пример #5
0
 /**
  * 图片素材总数.
  *
  * @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;
 }
Пример #6
0
 /**
  * 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'];
     });
 }
Пример #7
0
 /**
  * Get stats of materials.
  *
  * @return array
  */
 public function stats()
 {
     return $this->http->get(self::API_STATS);
 }
Пример #8
0
 /**
  * Get current menus setting.
  *
  * @return array
  */
 public function current()
 {
     return $this->http->get(self::API_QUERY);
 }
Пример #9
0
 /**
  * Return media stream.
  *
  * @return string
  */
 public function getStream($mediaId)
 {
     return $this->http->get(self::API_GET, ['media_id' => $mediaId]);
 }
Пример #10
0
 /**
  * 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));
 }
Пример #11
0
 /**
  * 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);
 }
Пример #12
0
 /**
  * Delete a staff.
  *
  * @param string $email
  *
  * @return bool
  */
 public function delete($email)
 {
     $params = ['kf_account' => $email];
     return $this->http->get(self::API_DELETE, $params);
 }
Пример #13
0
 /**
  * List all groups.
  *
  * @return array
  */
 public function lists()
 {
     $response = $this->http->get(self::API_GET);
     return $response['groups'];
 }
Пример #14
0
 /**
  * List all online staffs.
  *
  * @return array
  */
 public function onlines()
 {
     $response = $this->http->get(self::API_ONLINE);
     return $response['kf_online_list'];
 }
Пример #15
0
 /**
  * 获取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);
 }
Пример #16
0
 /**
  * 获取菜单【查询接口,能获取到任意方式设置的菜单】.
  *
  * @return array
  */
 public function current()
 {
     $menus = $this->http->get(self::API_QUERY);
     return empty($menus) ? [] : $menus;
 }