BG
This commit is contained in:
35
.gitignore
vendored
Executable file
35
.gitignore
vendored
Executable file
@@ -0,0 +1,35 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
/build
|
||||
/.vs
|
||||
/out/build/x64-Debug
|
||||
65
.vscode/settings.json
vendored
Normal file
65
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"chrono": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"map": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"future": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp"
|
||||
}
|
||||
}
|
||||
67
CMakeLists.txt
Executable file
67
CMakeLists.txt
Executable file
@@ -0,0 +1,67 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(MODULE_NAME "aliyunsdk")
|
||||
# 设置项目名为当前目录名
|
||||
project(${MODULE_NAME})
|
||||
|
||||
# 搜索源文件和头文件
|
||||
file(GLOB_RECURSE SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")
|
||||
file(GLOB_RECURSE HEADER_FILES
|
||||
"${PROJECT_SOURCE_DIR}/src/*.h"
|
||||
)
|
||||
|
||||
# 将源文件分配到 Source Files 文件夹
|
||||
foreach(source IN LISTS SOURCE_FILES)
|
||||
get_filename_component(source_path "${source}" PATH)
|
||||
file(RELATIVE_PATH source_path_rel "${PROJECT_SOURCE_DIR}" "${source_path}")
|
||||
string(REPLACE "/" "\\" source_path_rel_win "${source_path_rel}")
|
||||
source_group("Source Files\\${source_path_rel_win}" FILES "${source}")
|
||||
endforeach()
|
||||
|
||||
# 将头文件分配到 Header Files 文件夹
|
||||
foreach(header IN LISTS HEADER_FILES)
|
||||
get_filename_component(header_path "${header}" PATH)
|
||||
file(RELATIVE_PATH header_path_rel "${PROJECT_SOURCE_DIR}" "${header_path}")
|
||||
string(REPLACE "/" "\\" header_path_rel_win "${header_path_rel}")
|
||||
source_group("Header Files\\${header_path_rel_win}" FILES "${header}")
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
# 安装复制
|
||||
set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
|
||||
|
||||
set(YLIB ${CMAKE_INSTALL_PREFIX}/../ylib)
|
||||
set(FASTWEB ${CMAKE_INSTALL_PREFIX}/../fastweb)
|
||||
|
||||
# 包含路径
|
||||
if(MSVC)
|
||||
|
||||
else()
|
||||
include_directories(
|
||||
/usr/local/include/ylib
|
||||
/usr/local/include/fastweb
|
||||
/opt/lua54/include
|
||||
/usr/local/include)
|
||||
add_definitions(-DfPIC)
|
||||
endif()
|
||||
|
||||
# 添加共享库
|
||||
add_library(${MODULE_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
|
||||
|
||||
if(MSVC)
|
||||
|
||||
else()
|
||||
target_link_libraries(${MODULE_NAME}
|
||||
hpsocket
|
||||
ylib
|
||||
crypto
|
||||
/opt/lua54/lib/liblua.a
|
||||
pthread
|
||||
/usr/lib/x86_64-linux-gnu/libalibabacloud-sdk-core.so
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
install(TARGETS ${MODULE_NAME} DESTINATION $<IF:$<CONFIG:Debug>,${FASTWEB}/bin/debug/module/${MODULE_NAME},${FASTWEB}/bin/release/module/${MODULE_NAME}>)
|
||||
23
LICENSE
Executable file
23
LICENSE
Executable file
@@ -0,0 +1,23 @@
|
||||
Software License
|
||||
|
||||
Copyright (C) 2024 [liuyingjie]
|
||||
|
||||
License Terms
|
||||
|
||||
Usage Rights
|
||||
|
||||
1. Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
|
||||
2. If the source code is modified, the modifications must be open-sourced under the same license. This means that the modifications must be disclosed and accompanied by a copy of this license.
|
||||
|
||||
Future Versions Updates
|
||||
|
||||
1. From this version onwards, all future releases will be governed by the terms of the latest version of the license. This license will automatically be nullified and replaced by the new version.
|
||||
2. Users must comply with the terms of the new license issued in future releases.
|
||||
|
||||
Liability and Disclaimer
|
||||
|
||||
This software is provided "as is", without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
|
||||
|
||||
Contact Information
|
||||
|
||||
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
|
||||
6
README.md
Normal file → Executable file
6
README.md
Normal file → Executable file
@@ -1,2 +1,4 @@
|
||||
# module-aliyun_cloud_sdk
|
||||
ALIYUN SDK
|
||||
# module-module-aliyun_cloud_sdk
|
||||
|
||||
FastWeb - 阿里云SDK
|
||||
|
||||
|
||||
9
build.sh
Executable file
9
build.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
cp -f libaliyunsdk.so ../target
|
||||
93
src/aliyunsdk.cpp
Executable file
93
src/aliyunsdk.cpp
Executable file
@@ -0,0 +1,93 @@
|
||||
#include "aliyunsdk.h"
|
||||
#include "dll_interface.h"
|
||||
#include <alibabacloud/core/AlibabaCloud.h>
|
||||
#include <alibabacloud/core/CommonRequest.h>
|
||||
#include <alibabacloud/core/CommonClient.h>
|
||||
#include <alibabacloud/core/CommonResponse.h>
|
||||
extern "C" {
|
||||
#ifdef _WIN32
|
||||
DLL_EXPORT
|
||||
#endif
|
||||
int fastweb_module_regist(void* sol2, void* lua)
|
||||
{
|
||||
sol::state* state = static_cast<sol::state*>(sol2);
|
||||
module::aliyun_sdk::regist(state);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
module::aliyun_sdk::aliyun_sdk()
|
||||
{
|
||||
AlibabaCloud::InitializeSdk();
|
||||
}
|
||||
|
||||
module::aliyun_sdk::~aliyun_sdk()
|
||||
{
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
}
|
||||
|
||||
void module::aliyun_sdk::set(const std::string& access_key_id,const std::string& access_key_secret)
|
||||
{
|
||||
m_access_key_id = access_key_id;
|
||||
m_access_key_secret = access_key_secret;
|
||||
}
|
||||
|
||||
|
||||
std::tuple<bool,std::string> module::aliyun_sdk::exec(const std::string& domain,const std::string& version,sol::table parameter)
|
||||
{
|
||||
AlibabaCloud::ClientConfiguration configuration( "cn-qingdao" );
|
||||
configuration.setConnectTimeout(1500);
|
||||
configuration.setReadTimeout(4000);
|
||||
AlibabaCloud::Credentials credential(m_access_key_id, m_access_key_secret );
|
||||
|
||||
AlibabaCloud::CommonClient client( credential, configuration );
|
||||
AlibabaCloud::CommonRequest request(AlibabaCloud::CommonRequest::RequestPattern::RpcPattern);
|
||||
request.setHttpMethod(AlibabaCloud::HttpRequest::Method::Post);
|
||||
request.setDomain(domain);
|
||||
request.setVersion(version);
|
||||
|
||||
for (const auto& pair : parameter) {
|
||||
sol::object key = pair.first;
|
||||
sol::object value = pair.second;
|
||||
|
||||
std::string key_str;
|
||||
std::string value_str;
|
||||
if (key.is<std::string>()) {
|
||||
key_str = key.as<std::string>();
|
||||
} else if (key.is<int>()) {
|
||||
key_str = std::to_string(key.as<int>());
|
||||
} else {
|
||||
throw std::string("unsupported key type");
|
||||
}
|
||||
|
||||
if (value.is<std::string>()) {
|
||||
value_str = value.as<std::string>();
|
||||
} else if (value.is<int>()) {
|
||||
value_str = std::to_string(value.as<int>());
|
||||
} else if (value.is<bool>()) {
|
||||
value_str = (value.as<bool>() ? "true" : "false");
|
||||
} else {
|
||||
throw std::string("unsupported value type");
|
||||
}
|
||||
request.setQueryParameter(key_str, value_str);
|
||||
}
|
||||
auto response = client.commonResponse(request);
|
||||
if (response.isSuccess())
|
||||
return std::make_tuple(true, response.result().payload());
|
||||
return std::make_tuple(false, response.error().errorMessage());
|
||||
}
|
||||
|
||||
void module::aliyun_sdk::regist(sol::state* lua)
|
||||
{
|
||||
lua->new_usertype<module::aliyun_sdk>("fw_aliyunsdk",
|
||||
"new", sol::constructors<module::aliyun_sdk()>(),
|
||||
"set", &module::aliyun_sdk::set,
|
||||
"exec", &module::aliyun_sdk::exec
|
||||
);
|
||||
}
|
||||
|
||||
void module::aliyun_sdk::regist_global(const char* name, sol::state* lua)
|
||||
{
|
||||
lua->registry()[name] = this;
|
||||
(*lua)[name] = this;
|
||||
}
|
||||
29
src/aliyunsdk.h
Executable file
29
src/aliyunsdk.h
Executable file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "basemodule.h"
|
||||
namespace module
|
||||
{
|
||||
/// <summary>
|
||||
/// AliyunSDK
|
||||
/// </summary>
|
||||
class aliyun_sdk :public module::base {
|
||||
public:
|
||||
aliyun_sdk();
|
||||
~aliyun_sdk() override;
|
||||
|
||||
|
||||
void set(const std::string& access_key_id,const std::string& access_key_secret);
|
||||
|
||||
std::tuple<bool,std::string> exec(const std::string& domain,const std::string& version,sol::table parameter);
|
||||
|
||||
static void regist(sol::state* lua);
|
||||
private:
|
||||
// 通过 imodule 继承
|
||||
virtual void regist_global(const char* name, sol::state* lua);
|
||||
virtual void delete_global() { delete this; }
|
||||
private:
|
||||
std::string m_access_key_id;
|
||||
std::string m_access_key_secret;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
27
target/aliyunsdk.lua
Executable file
27
target/aliyunsdk.lua
Executable file
@@ -0,0 +1,27 @@
|
||||
local aliyun_sdk = {}
|
||||
aliyun_sdk.__index = aliyun_sdk
|
||||
|
||||
--[[
|
||||
创建一个新的 fw_aliyun_sdk 对象
|
||||
@return 返回一个新的 fw_aliyun_sdk 对象
|
||||
]]
|
||||
function aliyun_sdk.new(db)
|
||||
local instance = setmetatable({}, aliyun_sdk)
|
||||
if db == nil then
|
||||
instance.module = fw_aliyun_sdk.new()
|
||||
else
|
||||
instance.module = db
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
function aliyun_sdk:set(access_key_id, access_key_secret)
|
||||
return self.module:set(access_key_id, access_key_secret)
|
||||
end
|
||||
|
||||
function aliyun_sdk:exec(domain, version, parameter)
|
||||
return self.module:exec(domain, version, parameter)
|
||||
end
|
||||
|
||||
return aliyun_sdk
|
||||
Reference in New Issue
Block a user