# aliyun-openapi-cpp-sdk **Repository Path**: muzao/aliyun-openapi-cpp-sdk ## Basic Information - **Project Name**: aliyun-openapi-cpp-sdk - **Description**: 阿里云OpenAPI的C++语言SDK - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2015-10-24 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ##aliyun-openapi-cpp-sdk## ##概述 ####简介 通过调用[**阿里云OpenAPI**](http://develop.aliyun.com/api)来实现对产品、应用、资源和数据进行统一入口的管理,实现更灵活的部署、更快速的操作、更精确的使用、更及时的监控。 本项目用于实现`阿里云OpenAPI`的`C++`语言SDK,包括的系统功能:API Core、对应产品的API为(ECS、OCS、SLB、CDN、Opensearch、KVStore、BatchCompute、RDS、OTS、ONS、YUNDUN) ####项目代码结构
aliyun-openapi-cpp-sdk
+ aliyun-openapi-cpp-sdk
|--+ api-metadata
|--+ bin
| # 由api-metadata生成cpp代码工程,由Python开发
|--+ json2code
|--+ __init__.py
|--+ code_template.py # cpp代码模板
|--+ comm_setting.py # 通用设置
|--+ comm_utils.py # 通用工具
|--# 执行此文件,会根据api-metadata/endpoints.xml生成src/meta/product_config.h
|--+ gen_cfg.py
|--# 执行此文件,会遍历整个api-metadata目录树,生成src/meta下所有的对应头文件
|--+ main.py
|--+ lib
|--+ src
|--+ core
|--+ meta
|--+ aliyun_client.h
|--+ main.cpp # 用于测试的cpp文件
|--+ aliyun-openapi-cpp-sdk.cbp
|--+ aliyun-openapi-cpp-sdk.depend
|--+ aliyun-openapi-cpp-sdk.layout
+ dependency #依赖库及其说明
+ LICENSE
+ README.md
####其他实现
其他语言的`阿里云OpenAPI`实现详见:
[Java](https://github.com/aliyun/aliyun-openapi-java-sdk),
[Python](https://github.com/aliyun/aliyun-openapi-python-sdk),
[PHP](https://github.com/aliyun/aliyun-openapi-php-sdk)
###环境搭建
####Windows下使用Code::Block IDE
请到[Code::Block官方下载网站](http://www.codeblocks.org/downloads/26), 下载 [**codeblocks-13.12mingw-setup.exe**](http://sourceforge.net/projects/codeblocks/files/Binaries/13.12/Windows/codeblocks-13.12mingw-setup.exe) 。
这个版本是自带Mingw的版本,安装完毕之后,使用Code::Block直接打开工程中的aliyun-openapi-cpp-sdk.cbp,编译代码即可。
说明: 1. 为什么使用Code::Block? 因为Code::Blocks是一个免费,开源,跨平台的C/C++ IDE。 windows版的Code::Blocks可以内置mingw,它是gcc的windows版。 在Linux(Ubuntu, Debian, RedHat/CentOS, SUSE),Mac和Windows下Code::Blocks保持了一致性。 并可以利用其插件生成makefile。 在开发时间不足,且需要多平台支持的情况下,选择完全遵从gcc标准进行开发,使用Code::Blocks保持多平台IDE一致是必须的选择。####Ubuntu(Linux)下使用Code::Block IDE 这里直接上命令吧:
1.安装编译环境 $sudo apt-get install build-essential $sudo apt-get install gdb $sudo apt-get install uuid-dev $sudo apt-get install curl libcurl3 libcurl3-dev $sudo apt-get install libiconv-hook-dev 2.安装codeblock $sudo apt-get install codeblocks $sudo apt-get install codeblocks-dbg $sudo apt-get install wxformbuilder 3.修改平台编译宏定义 src/core/gobal_setting.h中 ... #define OS_LINUX_EN 1 #define OS_WINDOWS_EN 0 #define OS_APPLE_MAC_EN 0 ...启动Code::Block直接打开工程中的`aliyun-openapi-cpp-sdk.cbp`之后,在工程目录上右键然后选择 --> Build Options --> 再选择Linker settings标签 --> 在 Other linker options: 中修改配置如下:
-luuid -lcurl再将 Link libraries: 中的配置清空,之后点击确定即可。 接下来你就可以运行例子了。 ###入门实例 以`src/main.cpp`为例
#include <iostream>
#include <cstdio>
// 引入头文件
#include "aliyun_client.h"
#include "meta/aliyunecs/20140526/api/all_aliyunecs.h"
int main(){
// id就是你的AccessKeyId
// key就是你的AccessKeySecret
// AccessKeyId和AccessKeySecret请在阿里云自行申请
// 这里将域ID写死为"cn-hangzhou",仅为测试
ALiYunClient aliyun_client(id, key, "cn-hangzhou");
aliyunecs_20140526::DescribeRegionsRequest dr_req;
aliyun_client.SetRequestParams(dr_req);
std::string data = aliyun_client.DoAction();
std::cout << data << std::endl;
aliyunecs_20140526::DescribeRegionsResponse dr_res(data);
for(std::vector::iterator itor = dr_res.regions.begin();
itor != dr_res.regions.end();
++itor)
{
std::cout << itor->regionid << std::endl;
}
return 0;
}
===============================================================================
##aliyun-openapi-cpp-sdk##
##Overview
####Brief
The [**Aliyun OpenApi**](http://develop.aliyun.com/api) is a interfaces of API. It is a entry of product, application, resource and data. It can help you using Aliyun service better!
This project is `C++` SDK of `Aliyun OpenApi`. It includes API Core, ECS, OCS, SLB, CDN, Opensearch, KVStore, BatchCompute, RDS, OTS, ONS, YUNDUN.
####Project Source Code Structure
aliyun-openapi-cpp-sdk
+ aliyun-openapi-cpp-sdk
|--+ api-metadata
|--+ bin
| # for api-metadata generating cpp source code, by Python development
|--+ json2code
|--+ __init__.py
|--+ code_template.py # cpp source code template
|--+ comm_setting.py # common setting
|--+ comm_utils.py # common tools
|--# executing it, generating src/meta/product_config.h by api-metadata/endpoints.xml
|--+ gen_cfg.py
|--# executing: it will walk all files(depth-first) in api-metadata directory,
|--# then it generating all .h files in src/meta directory.
|--+ main.py
|--+ lib
|--+ src
|--+ core
|--+ meta
|--+ aliyun_client.h
|--+ main.cpp # example
|--+ aliyun-openapi-cpp-sdk.cbp
|--+ aliyun-openapi-cpp-sdk.depend
|--+ aliyun-openapi-cpp-sdk.layout
+ dependency
+ LICENSE
+ README.md
####Other Development Language
[Java](https://github.com/aliyun/aliyun-openapi-java-sdk),
[Python](https://github.com/aliyun/aliyun-openapi-python-sdk),
[PHP](https://github.com/aliyun/aliyun-openapi-php-sdk)
###Development Environment
####Using Code::Block IDE on Windows
go [Code::Block](http://www.codeblocks.org/downloads/26), download [**codeblocks-13.12mingw-setup.exe**](http://sourceforge.net/projects/codeblocks/files/Binaries/13.12/Windows/codeblocks-13.12mingw-setup.exe).
This version includes the GCC compiler and GDB debugger.
After installing, please open `aliyun-openapi-cpp-sdk.cbp` file by Code::Block.
####Using Code::Block IDE on Ubuntu(Linux)
1.installing libraries $sudo apt-get install build-essential $sudo apt-get install gdb $sudo apt-get install uuid-dev $sudo apt-get install curl libcurl3 libcurl3-dev $sudo apt-get install libiconv-hook-dev 2.installing code::blocks $sudo apt-get install codeblocks $sudo apt-get install codeblocks-dbg $sudo apt-get install wxformbuilder 3.modify macro of platform src/core/gobal_setting.h ... #define OS_LINUX_EN 1 #define OS_WINDOWS_EN 0 #define OS_APPLE_MAC_EN 0 ...opening `aliyun-openapi-cpp-sdk.cbp` by code::blocks, selecting project (right-click), Build Options --> Linker settings --> Other linker options, modifying as follows:
-luuid -lcurland clearing up `Link libraries` content ok! ###Quick Start Guide example: `src/main.cpp`
#include <iostream>
#include <cstdio>
#include "aliyun_client.h"
#include "meta/aliyunecs/20140526/api/all_aliyunecs.h"
int main(){
// id is your AccessKeyId
// key is your AccessKeySecret
// AccessKeyId and AccessKeySecret by Aliyun
// domain is "cn-hangzhou", for testing
ALiYunClient aliyun_client(id, key, "cn-hangzhou");
aliyunecs_20140526::DescribeRegionsRequest dr_req;
aliyun_client.SetRequestParams(dr_req);
std::string data = aliyun_client.DoAction();
std::cout << data << std::endl;
aliyunecs_20140526::DescribeRegionsResponse dr_res(data);
for(std::vector::iterator itor = dr_res.regions.begin();
itor != dr_res.regions.end();
++itor)
{
std::cout << itor->regionid << std::endl;
}
return 0;
}