Ikoula Corporate
Espace client
Support
Blog
Wiki
Site web Ikoula
查看“如何使用Ikoula的API”的源代码
←
如何使用Ikoula的API
Jump to navigation
Jump to search
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
<span data-link_translate_en_title="How to use the Ikoula API" data-link_translate_en_url="How+to+use+the+Ikoula+API"></span>[[:en:How to use the Ikoula API]][[en:How to use the Ikoula API]] <span data-link_translate_fr_title="Comment utiliser l'API d’Ikoula" data-link_translate_fr_url="Comment+utiliser+l'API+d’Ikoula"></span>[[:fr:Comment utiliser l'API d’Ikoula]][[fr:Comment utiliser l'API d’Ikoula]] <span data-link_translate_es_title="Cómo utilizar la API de Ikoula" data-link_translate_es_url="Cómo+utilizar+la+API+de+Ikoula"></span>[[:es:Cómo utilizar la API de Ikoula]][[es:Cómo utilizar la API de Ikoula]] <span data-link_translate_nl_title="Hoe de Ikoula API te gebruiken?" data-link_translate_nl_url="Hoe+de+Ikoula+API+te+gebruiken?"></span>[[:nl:Hoe de Ikoula API te gebruiken?]][[nl:Hoe de Ikoula API te gebruiken?]] <span data-link_translate_it_title="Come utilizzare l'API Ikoula" data-link_translate_it_url="Come+utilizzare+l'API+Ikoula"></span>[[:it:Come utilizzare l'API Ikoula]][[it:Come utilizzare l'API Ikoula]] == Introduction == Ikoula的API产品,可让您操作及管理您帐户中的产品。 这是API URL https://api.ikoula.com 我们每个产品都有提供文档。 == 说明 == 由于安全考量,Ikoula 的API需要使用用户名,密码和签名进行身份验证。 <br /> * 用户名是用于连接到您的Ikoula帐户或Extranet的电子邮件地址,也是您 <span class="notranslate">'''login'''</span>的传递参数名称; * 必须使用Ikoula提供的公钥 <span class="notranslate">'''crypted_password'''</span> 参数) 和base64_encode通过特定功能对密码进行加密 * 根据API提供的参数生成签名。 * 必须始终在GET中将这些参数传递给API! '''注意''' 例如,对于您的API测试,您可以使用测试的临时用户。 在任何生产环境或非短期环境中,使用带有Ikoula公钥的密码加密都是不可少的。 如果要通过脚本或程序使用API调用,建议您为此目的创建一个专用用户,而不要使用传统的Extranet用户。 您有两种选择: * 直接在Extranet帐户的主页上创建子用户(请参阅下面的WIKI,以创建子用户: [[如何创建一个子账户?]]). * 如有必要,请联系我们创建Extranet用户 请注意提供使用者所需服务的权利。 == 加密金钥 == 加密公钥的密码位于: https://api.ikoula.com/downloads/Ikoula.API.RSAKeyPub.pem == Wrapper PHP == <syntaxhighlight lang="php"> <?php // ################################################# // #### ..:: Ikoula Hosting Services ::.. ### // #### Wrapper for https://api.ikoula.com ### // ################################################# class IkoulaAPI { /** * Email of Ikoula account * @var string Email account */ private static $email = "EMAIL_ACCOUNT_IKOULA"; /** * Password of Ikoula account * @var string Password account */ private static $password = "PASSWORD_ACCOUNT_IKOULA"; /** * Ikoula API URI * @var string Password account */ private static $urlApi = "https://api.ikoula.com/"; /** Public key path for encrypt data * @var string Path of public key * @see https://api.ikoula.com/downloads/Ikoula.API.RSAKeyPub.pem */ private static $publicKeyPath = "/path/to/ikoula/public/key/Ikoula.API.RSAKeyPub.pem"; /** Fonction for request Ikoula API * @param string $webservice Webservice for data * @param string $format JSON or XML * @param string $type HTTP Type (GET/POST) * @param array $params Params to add for request */ public static function requestApi($webservice, $format, $type, $params = []) { // Add connexion information $params['login'] = self::$email; $params['crypted_password'] = base64_encode(self::opensslEncryptPublic(self::$password)); $params['format'] = $format; // Generate signature $signature = self::createSignature($params); // Add signature for call $params['signature'] = $signature; // Curl init $ch = curl_init(); if($ch) { // Create API URI $url = self::$urlApi.$webservice; // Add type request curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); // If parameters, we encode his if(is_array($params) && count($params) > 0) $params_str = http_build_query($params); // If we use post, fix params if(strcasecmp("POST", $type) == 0) { // Fix POST data curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_POSTFIELDS, $params_str); } else $url .= (strpos($url,'?') === false ? '?' : '&').$params_str; // Create curl info curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, false); // Exec request $data = curl_exec($ch); // Close curl object curl_close($ch); // Return response return($data); } return null; } /** Create signature with params * @param array $params Params to add for request * @return string Signature encoded */ private static function createSignature($params = []) { // Signature to send $signature = null; // Verify parameters if (count($params) > 0) { // Sort params ksort($params); // Encode params $query = http_build_query($params); // Encode "plus "+" $query = str_replace("+", "%20", $query); // Transform in lowercase $query = strtolower($query); $public_key = ""; // Verify if key file is present if (file_exists(self::$publicKeyPath)) { // Get public key $public_key = trim( str_replace( array("\n", '-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----'), array('', '', ''), file_get_contents(self::$publicKeyPath) ) ); } // SHA1 hash $hash = hash_hmac("SHA1", $query, $public_key, true); // base64 encode $signature = base64_encode($hash); } return $signature; } /** Fonction for crypt Ikoula password * @param string $password Ikoula account password * @return mixed Ikoula password encrypted, null if error */ private static function opensslEncryptPublic($password) { // Verify if key file exist if(file_exists(self::$publicKeyPath)) { // Verify if password is not empty if(!empty($password)) { // Get file content $publicKey = openssl_pkey_get_public('file://'.realpath(self::$publicKeyPath)); // If we get file content without error if ($publicKey !== FALSE) { // Encrypt password if(openssl_public_encrypt($password, $crypted, $publicKey) === TRUE) return $crypted; else return NULL; } else return NULL; } else return NULL; } else return NULL; } } </syntaxhighlight> == 使用例 == <syntaxhighlight lang="php"> // Fix JSON header header("Content-type: application/json"); // Get Exch schema for prestation echo IkoulaAPI::requestApi("wsexch/schema-subscr", "json", "GET", ['subscr_id' => 999999999]); // Get Flex VM for Ikoula Account echo IkoulaAPI::requestApi("wsflex/list", "json", "GET", []); // Get Flex VM for Ikoula Account echo IkoulaAPI::requestApi("wsflex/list", "json", "GET", []); // Get Platform list echo IkoulaAPI::requestApi("wsplatform/list", "json", "GET", []); // Get Platform dossiers echo IkoulaAPI::requestApi("wsplatform/dossiers", "json", "GET", ['platform_id' => 999999999]); // Get Billing conso for CloudStack prestation echo IkoulaAPI::requestApi("wscs/conso-for-billing", "json", "GET", ['subscr_id' => '999999999', 'billing_id' => '1']); // Reboot server echo IkoulaAPI::requestApi("wsds/reboot-apc-request", "json", "GET", ['server_ip' => 'XXX.XXX.XXX.XXX', 'tempo' => '3']); </syntaxhighlight> == 增加功能 == 如果有功能要求,请联系技术支持。
返回至
如何使用Ikoula的API
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息
投稿
fr-wiki.ikoula.com
en-wiki.ikoula.com
es-wiki.ikoula.com
it-wiki.ikoula.com
nl-wiki.ikoula.com
de-wiki.ikoula.com
pt-wiki.ikoula.com
ru-wiki.ikoula.com
pl-wiki.ikoula.com
ro-wiki.ikoula.com
ja-wiki.ikoula.com
zh-wiki.ikoula.com
he-wiki.ikoula.com
ar-wiki.ikoula.com