/** * 获取jsticket * * @return string */ public function getTicket() { $key = 'overtrue.wechat.card.api_ticket'; return $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']; }); }
/** * 图片素材总数 * * @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 Bag($response); return $type ? $response->get($type) : $response; }
/** * 获取jsticket * * @return string */ public function getTicket() { $key = 'overtrue.wechat.jsapi_ticket.' . $this->appId; // for php 5.3 $appId = $this->appId; $appSecret = $this->appSecret; $cache = $this->cache; $apiTicket = self::API_TICKET; return $this->cache->get($key, function ($key) use($appId, $appSecret, $cache, $apiTicket) { $http = new Http(new AccessToken($appId, $appSecret)); $result = $http->get($apiTicket); $cache->set($key, $result['ticket'], $result['expires_in']); return $result['ticket']; }); }
/** * 获取菜单【查询接口,能获取到任意方式设置的菜单】. * * @return array */ public function current() { $menus = $this->http->get(self::API_QUERY); return empty($menus) ? array() : $menus; }
/** * 获取access token. * * @param string $code * * @return string */ public function getAccessPermission($code) { $params = array('appid' => $this->appId, 'secret' => $this->appSecret, 'code' => $code, 'grant_type' => 'authorization_code'); return $this->lastPermission = $this->http->get(self::API_TOKEN_GET, $params); }
/** * 获取用户列表 * * @param string $nextOpenId * * @return Bag */ public function lists($nextOpenId = null) { $params = array('next_openid' => $nextOpenId); return new Bag($this->http->get(self::API_LIST, $params)); }
/** * 获取所有在线的 * * @return array */ public function onlines() { $response = $this->http->get(self::API_GET); return $response['kf_online_list']; }
/** * 删除客服账号. * * @param string $email * * @return bool */ public function delete($email) { return $this->http->get(self::API_DELETE, array('kf_account' => $email)); }
/** * 删除菜单 * * @return bool */ public function delete() { $this->http->get(self::API_DELETE); return true; }
/** * 删除客服账号 * * @param string $email * @param string $nickname * @param string $password * * @return bool */ public function delete($email, $nickname, $password) { $params = array('kf_account' => $email); return $this->http->get(self::API_DELETE, $params); }
/** * Get the access token from WeChat server. * * @param string $cacheKey * * @return array|bool */ protected function getTokenFromServer() { $http = new Http(); $params = array('corpid' => $this->appId, 'corpsecret' => $this->appSecret); $token = $http->get(self::API_TOKEN_GET, $params); Logger::info('AccessToken', 'token : ' . $token); return $token; }
/** * 获取用户信息 * * @param string $openId * @param string $accessToken * * @return array */ protected function getUser($openId, $accessToken) { $queries = array('access_token' => $accessToken, 'openid' => $openId, 'lang' => 'zh_CN'); $url = self::API_USER . '?' . http_build_query($queries); return new Bag($this->http->get($url)); }