setError() public static method

Set the gloable error number and error message.
public static setError ( integer $errno, string $errmsg )
$errno integer Error code
$errmsg string Error message
Ejemplo n.º 1
0
 public function getLoggedInUser($access_token)
 {
     $result = BaiduUtils::request(self::$BD_OAUTH2_ENDPOINTS['getLoginUser'], array('access_token' => $access_token, 'redirect_uri' => $this->redirectUri), 'GET');
     if ($result) {
         $result = json_decode($result, true);
         if (isset($result['error_msg'])) {
             BaiduUtils::setError($result['error_code'], $result['error_msg']);
             return false;
         }
         return $result;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Call a file upload api.
  * 
  * @param string $uri Uri for the api, it could be the whole url,
  * like 'https://openapi.baidu.com/file/2.0/cloudalbum/picture/upload',
  * or just api method only, like 'cloudalbum/picture/upload', if the api
  * is provided under the domain of openapi.baidu.com.
  * @param $params Api specific parameters.
  * @return Returns an array if success, or false if failed.
  */
 public function upload($uri, $params = array())
 {
     $params = array_merge(array('access_token' => $this->getAccessToken()), $params);
     if (substr($uri, 0, 8) === 'https://' || substr($uri, 0, 7) === 'http://') {
         //do nothing
     } elseif (substr($uri, 0, 6) === '/file/') {
         $uri = self::$BD_OPENAPI_DEFAULT_DOMAINS['file'] . $uri;
     } else {
         $uri = self::$BD_OPENAPI_DEFAULT_PREFIXS['file'] . $uri;
     }
     $result = BaiduUtils::request($uri, $params, 'POST', true);
     if ($result !== false) {
         $result = $this->converJson2Array($result);
         if (is_array($result) && isset($result['error_code'])) {
             BaiduUtils::setError(-1, 'failed to call baidu openapi: error_code[' . $result['error_code'] . '] error_msg[' . $result['error_msg'] . ']');
             return false;
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Make an oauth access token request
  * 
  * The parameters:
  * - client_id: The client identifier, just use api key
  * - response_type: 'token' or 'code'
  * - redirect_uri: the url to go to after a successful login
  * - scope: The scope of the access request expressed as a list of space-delimited, case sensitive strings.
  * - state: An opaque value used by the client to maintain state between the request and callback.
  * - display: login page style, 'page', 'popup', 'touch' or 'mobile'
  * 
  * @param array $params	oauth request parameters
  * @return mixed returns access token info if success, or false if failed
  */
 public function makeAccessTokenRequest($params)
 {
     $result = BaiduUtils::request(self::$BD_OAUTH2_ENDPOINTS['token'], $params, 'POST');
     if ($result) {
         $result = json_decode($result, true);
         if (isset($result['error_description'])) {
             BaiduUtils::setError($result['error'], $result['error_description']);
             return false;
         }
         return $result;
     }
     return false;
 }