* Fix error of comment.

This commit is contained in:
zhaoke
2023-08-01 17:49:52 +08:00
parent 69c6c9285d
commit c64e004f13
5 changed files with 85 additions and 3 deletions
+70
View File
@@ -3667,6 +3667,76 @@ EOF;
return static::apiError($result);
}
/**
* Post method of API.
*
* @param string $url
* @param array|object $data
* @param array $headers example: array("key1:value1", "key2:value2")
* @access public
* @return object
*/
public static function apiPost($url, $data, $headers = array())
{
$result = json_decode(commonModel::http($url, $data, array(CURLOPT_CUSTOMREQUEST => 'POST'), $headers, 'json'));
if($result && $result->code == 200) return $result;
return static::apiError($result);
}
/**
* Put method of API.
*
* @param string $url
* @param array|object $data
* @param array $headers example: array("key1:value1", "key2:value2")
* @access public
* @return object
*/
public static function apiPut($url, $data, $headers = array())
{
$result = json_decode(commonModel::http($url, $data, array(CURLOPT_CUSTOMREQUEST => 'PUT'), $headers, 'json'));
if($result && $result->code == 200) return $result;
return static::apiError($result);
}
/**
* Delete method of API.
*
* @param string $url
* @param array|object $data
* @param array $headers example: array("key1:value1", "key2:value2")
* @access public
* @return object
*/
public static function apiDelete($url, $data, $headers = array())
{
$result = json_decode(commonModel::http($url, $data, array(CURLOPT_CUSTOMREQUEST => 'DELETE'), $headers, 'json'));
if($result && $result->code == 200) return $result;
return static::apiError($result);
}
/**
* Return error object of api server.
*
* @param object|null $result
* @access protected
* @return object
*/
protected static function apiError($result)
{
global $lang;
if($result && $result->code) return $result;
$error = new stdclass;
$error->code = 600;
$error->message = $lang->error->httpServerError;
return $error;
}
/**
* Check object priv.
*