src/AccessToken.php
public function token() {
        $key = 'WeChatToken'.$this->get('appid');
        if (Factory::cache()->has($key)) {
            return Factory::cache()->get($key);
        }
        $args = $this->getToken()->json();
        if (!is_array($args)) {
            throw new Exception('HTTP ERROR!');
        }
        if (!array_key_exists('access_token', $args)) {
            throw new Exception(isset($args['errmsg']) ?
                $args['errmsg'] : 'GET ACCESS TOKEN ERROR!');
        }
        Factory::cache()->set($key, $args['access_token'], $args['expires_in']);
        return $args['access_token'];
    }
public function token() {
        $key = 'WeChatToken'.$this->get('appid');
        if (Factory::cache()->has($key)) {
            return Factory::cache()->get($key);
        }
        $args = $this->getToken()->json();
        if (!is_array($args)) {
            throw new Exception('HTTP ERROR!');
        }
        if (!array_key_exists('access_token', $args)) {
            throw new Exception(isset($args['errmsg']) ?
                $args['errmsg'] : 'GET ACCESS TOKEN ERROR!');
        }
        Factory::cache()->set($key, $args['access_token'], $args['expires_in']);
        return $args['access_token'];
    }
public function token ( ) { $ key = 'WeChatToken' . $ this -> get ( 'appid' ) ; if ( Factory :: cache ( ) -> has ( $ key ) ) { return Factory :: cache ( ) -> get ( $ key ) ; } $ args = $ this -> getToken ( ) -> json ( ) ; if ( ! is_array ( $ args ) ) { throw new Exception ( 'HTTP ERROR!' ) ; } if ( ! array_key_exists ( 'access_token' , $ args ) ) { throw new Exception ( isset ( $ args [ 'errmsg' ] ) ? $ args [ 'errmsg' ] : 'GET ACCESS TOKEN ERROR!' ) ; } Factory :: cache ( ) -> set ( $ key , $ args [ 'access_token' ] , $ args [ 'expires_in' ] ) ; return $ args [ 'access_token' ] ; }
GET ACCESS TOKEN AND SAVE CACHE
@return string
@throws \Exception
GET ACCESS TOKEN AND SAVE CACHE