Browse Source

SDK device authorization API.

sdk-team 5 years ago
parent
commit
7ef6eafff4

+ 3 - 0
CHANGELOG

@@ -1,3 +1,6 @@
+2021-05-11 Version: 1.36.724
+- SDK device authorization API.
+
 2021-05-10 Version: 1.36.723
 - Update RecognizeDriverLicense RecognizeLicensePlate.
 

+ 1 - 1
VERSION

@@ -1 +1 @@
-1.36.723
+1.36.724

+ 86 - 0
moguan-sdk/CMakeLists.txt

@@ -0,0 +1,86 @@
+#
+# Copyright 2009-2017 Alibaba Cloud All rights reserved.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#      http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set(public_header_dir ${CMAKE_CURRENT_SOURCE_DIR}/../include)
+
+set(moguan-sdk_public_header 
+	include/alibabacloud/moguan-sdk/Moguan_sdkClient.h
+	include/alibabacloud/moguan-sdk/Moguan_sdkExport.h )
+
+set(moguan-sdk_public_header_model 
+	include/alibabacloud/moguan-sdk/model/RegisterDeviceRequest.h
+	include/alibabacloud/moguan-sdk/model/RegisterDeviceResult.h )
+
+set(moguan-sdk_src 
+	src/Moguan-sdkClient.cc
+	src/model/RegisterDeviceRequest.cc
+	src/model/RegisterDeviceResult.cc )
+
+add_library(moguan-sdk ${LIB_TYPE}
+	${moguan-sdk_public_header}
+	${moguan-sdk_public_header_model}
+	${moguan-sdk_src})
+
+set_target_properties(moguan-sdk
+	PROPERTIES
+	LINKER_LANGUAGE CXX
+	ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
+	LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
+	RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
+	OUTPUT_NAME ${TARGET_OUTPUT_NAME_PREFIX}moguan-sdk
+	)
+
+if(${LIB_TYPE} STREQUAL "SHARED")
+	set_target_properties(moguan-sdk
+		PROPERTIES
+		DEFINE_SYMBOL ALIBABACLOUD_MOGUAN_SDK_LIBRARY)
+endif()
+
+target_include_directories(moguan-sdk
+	PRIVATE include
+		${CMAKE_SOURCE_DIR}/core/include
+	)
+target_link_libraries(moguan-sdk
+	core)
+
+if(CMAKE_HOST_WIN32)
+	ExternalProject_Get_Property(jsoncpp INSTALL_DIR)
+	set(jsoncpp_install_dir ${INSTALL_DIR})
+	add_dependencies(moguan-sdk
+		jsoncpp)
+	target_include_directories(moguan-sdk
+		PRIVATE	${jsoncpp_install_dir}/include)
+	target_link_libraries(moguan-sdk
+		${jsoncpp_install_dir}/lib/jsoncpp.lib)
+	set_target_properties(moguan-sdk
+    	PROPERTIES
+    		COMPILE_OPTIONS "/bigobj")
+else()
+	target_include_directories(moguan-sdk
+		PRIVATE /usr/include/jsoncpp)
+	target_link_libraries(moguan-sdk
+		jsoncpp)
+endif()
+
+install(FILES ${moguan-sdk_public_header}
+	DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/moguan-sdk)
+install(FILES ${moguan-sdk_public_header_model}
+	DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/moguan-sdk/model)
+install(TARGETS moguan-sdk
+	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+	)

+ 54 - 0
moguan-sdk/include/alibabacloud/moguan-sdk/Moguan_sdkClient.h

@@ -0,0 +1,54 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_MOGUAN_SDK_MOGUAN_SDKCLIENT_H_
+#define ALIBABACLOUD_MOGUAN_SDK_MOGUAN_SDKCLIENT_H_
+
+#include <future>
+#include <alibabacloud/core/AsyncCallerContext.h>
+#include <alibabacloud/core/EndpointProvider.h>
+#include <alibabacloud/core/RpcServiceClient.h>
+#include "Moguan_sdkExport.h"
+#include "model/RegisterDeviceRequest.h"
+#include "model/RegisterDeviceResult.h"
+
+
+namespace AlibabaCloud
+{
+	namespace Moguan_sdk
+	{
+		class ALIBABACLOUD_MOGUAN_SDK_EXPORT Moguan_sdkClient : public RpcServiceClient
+		{
+		public:
+			typedef Outcome<Error, Model::RegisterDeviceResult> RegisterDeviceOutcome;
+			typedef std::future<RegisterDeviceOutcome> RegisterDeviceOutcomeCallable;
+			typedef std::function<void(const Moguan_sdkClient*, const Model::RegisterDeviceRequest&, const RegisterDeviceOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> RegisterDeviceAsyncHandler;
+
+			Moguan_sdkClient(const Credentials &credentials, const ClientConfiguration &configuration);
+			Moguan_sdkClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
+			Moguan_sdkClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
+			~Moguan_sdkClient();
+			RegisterDeviceOutcome registerDevice(const Model::RegisterDeviceRequest &request)const;
+			void registerDeviceAsync(const Model::RegisterDeviceRequest& request, const RegisterDeviceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
+			RegisterDeviceOutcomeCallable registerDeviceCallable(const Model::RegisterDeviceRequest& request) const;
+	
+		private:
+			std::shared_ptr<EndpointProvider> endpointProvider_;
+		};
+	}
+}
+
+#endif // !ALIBABACLOUD_MOGUAN_SDK_MOGUAN_SDKCLIENT_H_

+ 32 - 0
moguan-sdk/include/alibabacloud/moguan-sdk/Moguan_sdkExport.h

@@ -0,0 +1,32 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_MOGUAN_SDK_MOGUAN_SDKEXPORT_H_
+#define ALIBABACLOUD_MOGUAN_SDK_MOGUAN_SDKEXPORT_H_
+
+#include <alibabacloud/core/Global.h>
+
+#if defined(ALIBABACLOUD_SHARED)
+#	if defined(ALIBABACLOUD_MOGUAN_SDK_LIBRARY)
+#		define ALIBABACLOUD_MOGUAN_SDK_EXPORT ALIBABACLOUD_DECL_EXPORT
+#	else
+#		define ALIBABACLOUD_MOGUAN_SDK_EXPORT ALIBABACLOUD_DECL_IMPORT
+#	endif
+#else
+#	define ALIBABACLOUD_MOGUAN_SDK_EXPORT
+#endif
+
+#endif // !ALIBABACLOUD_MOGUAN_SDK_MOGUAN_SDKEXPORT_H_

+ 60 - 0
moguan-sdk/include/alibabacloud/moguan-sdk/model/RegisterDeviceRequest.h

@@ -0,0 +1,60 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_MOGUAN_SDK_MODEL_REGISTERDEVICEREQUEST_H_
+#define ALIBABACLOUD_MOGUAN_SDK_MODEL_REGISTERDEVICEREQUEST_H_
+
+#include <string>
+#include <vector>
+#include <alibabacloud/core/RpcServiceRequest.h>
+#include <alibabacloud/moguan-sdk/Moguan_sdkExport.h>
+
+namespace AlibabaCloud
+{
+	namespace Moguan_sdk
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_MOGUAN_SDK_EXPORT RegisterDeviceRequest : public RpcServiceRequest
+			{
+
+			public:
+				RegisterDeviceRequest();
+				~RegisterDeviceRequest();
+
+				std::string getUserDeviceId()const;
+				void setUserDeviceId(const std::string& userDeviceId);
+				std::string getExtend()const;
+				void setExtend(const std::string& extend);
+				std::string getSdkCode()const;
+				void setSdkCode(const std::string& sdkCode);
+				std::string getAppKey()const;
+				void setAppKey(const std::string& appKey);
+				std::string getDeviceId()const;
+				void setDeviceId(const std::string& deviceId);
+
+            private:
+				std::string userDeviceId_;
+				std::string extend_;
+				std::string sdkCode_;
+				std::string appKey_;
+				std::string deviceId_;
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_MOGUAN_SDK_MODEL_REGISTERDEVICEREQUEST_H_

+ 61 - 0
moguan-sdk/include/alibabacloud/moguan-sdk/model/RegisterDeviceResult.h

@@ -0,0 +1,61 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_MOGUAN_SDK_MODEL_REGISTERDEVICERESULT_H_
+#define ALIBABACLOUD_MOGUAN_SDK_MODEL_REGISTERDEVICERESULT_H_
+
+#include <string>
+#include <vector>
+#include <utility>
+#include <alibabacloud/core/ServiceResult.h>
+#include <alibabacloud/moguan-sdk/Moguan_sdkExport.h>
+
+namespace AlibabaCloud
+{
+	namespace Moguan_sdk
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_MOGUAN_SDK_EXPORT RegisterDeviceResult : public ServiceResult
+			{
+			public:
+				struct Data
+				{
+					std::string rid;
+				};
+
+
+				RegisterDeviceResult();
+				explicit RegisterDeviceResult(const std::string &payload);
+				~RegisterDeviceResult();
+				std::string getMessage()const;
+				Data getData()const;
+				int getErrorCode()const;
+				std::string getErrorMessage()const;
+
+			protected:
+				void parse(const std::string &payload);
+			private:
+				std::string message_;
+				Data data_;
+				int errorCode_;
+				std::string errorMessage_;
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_MOGUAN_SDK_MODEL_REGISTERDEVICERESULT_H_

+ 89 - 0
moguan-sdk/src/Moguan-sdkClient.cc

@@ -0,0 +1,89 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <alibabacloud/moguan-sdk/Moguan_sdkClient.h>
+#include <alibabacloud/core/SimpleCredentialsProvider.h>
+
+using namespace AlibabaCloud;
+using namespace AlibabaCloud::Location;
+using namespace AlibabaCloud::Moguan_sdk;
+using namespace AlibabaCloud::Moguan_sdk::Model;
+
+namespace
+{
+	const std::string SERVICE_NAME = "moguan-sdk";
+}
+
+Moguan_sdkClient::Moguan_sdkClient(const Credentials &credentials, const ClientConfiguration &configuration) :
+	RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
+{
+	auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "visionai");
+}
+
+Moguan_sdkClient::Moguan_sdkClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
+	RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
+{
+	auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "visionai");
+}
+
+Moguan_sdkClient::Moguan_sdkClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
+	RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
+{
+	auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "visionai");
+}
+
+Moguan_sdkClient::~Moguan_sdkClient()
+{}
+
+Moguan_sdkClient::RegisterDeviceOutcome Moguan_sdkClient::registerDevice(const RegisterDeviceRequest &request) const
+{
+	auto endpointOutcome = endpointProvider_->getEndpoint();
+	if (!endpointOutcome.isSuccess())
+		return RegisterDeviceOutcome(endpointOutcome.error());
+
+	auto outcome = makeRequest(endpointOutcome.result(), request);
+
+	if (outcome.isSuccess())
+		return RegisterDeviceOutcome(RegisterDeviceResult(outcome.result()));
+	else
+		return RegisterDeviceOutcome(outcome.error());
+}
+
+void Moguan_sdkClient::registerDeviceAsync(const RegisterDeviceRequest& request, const RegisterDeviceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
+{
+	auto fn = [this, request, handler, context]()
+	{
+		handler(this, request, registerDevice(request), context);
+	};
+
+	asyncExecute(new Runnable(fn));
+}
+
+Moguan_sdkClient::RegisterDeviceOutcomeCallable Moguan_sdkClient::registerDeviceCallable(const RegisterDeviceRequest &request) const
+{
+	auto task = std::make_shared<std::packaged_task<RegisterDeviceOutcome()>>(
+			[this, request]()
+			{
+			return this->registerDevice(request);
+			});
+
+	asyncExecute(new Runnable([task]() { (*task)(); }));
+	return task->get_future();
+}
+

+ 84 - 0
moguan-sdk/src/model/RegisterDeviceRequest.cc

@@ -0,0 +1,84 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <alibabacloud/moguan-sdk/model/RegisterDeviceRequest.h>
+
+using AlibabaCloud::Moguan_sdk::Model::RegisterDeviceRequest;
+
+RegisterDeviceRequest::RegisterDeviceRequest() :
+	RpcServiceRequest("moguan-sdk", "2021-04-15", "RegisterDevice")
+{
+	setMethod(HttpRequest::Method::Post);
+}
+
+RegisterDeviceRequest::~RegisterDeviceRequest()
+{}
+
+std::string RegisterDeviceRequest::getUserDeviceId()const
+{
+	return userDeviceId_;
+}
+
+void RegisterDeviceRequest::setUserDeviceId(const std::string& userDeviceId)
+{
+	userDeviceId_ = userDeviceId;
+	setBodyParameter("UserDeviceId", userDeviceId);
+}
+
+std::string RegisterDeviceRequest::getExtend()const
+{
+	return extend_;
+}
+
+void RegisterDeviceRequest::setExtend(const std::string& extend)
+{
+	extend_ = extend;
+	setBodyParameter("Extend", extend);
+}
+
+std::string RegisterDeviceRequest::getSdkCode()const
+{
+	return sdkCode_;
+}
+
+void RegisterDeviceRequest::setSdkCode(const std::string& sdkCode)
+{
+	sdkCode_ = sdkCode;
+	setBodyParameter("SdkCode", sdkCode);
+}
+
+std::string RegisterDeviceRequest::getAppKey()const
+{
+	return appKey_;
+}
+
+void RegisterDeviceRequest::setAppKey(const std::string& appKey)
+{
+	appKey_ = appKey;
+	setBodyParameter("AppKey", appKey);
+}
+
+std::string RegisterDeviceRequest::getDeviceId()const
+{
+	return deviceId_;
+}
+
+void RegisterDeviceRequest::setDeviceId(const std::string& deviceId)
+{
+	deviceId_ = deviceId;
+	setBodyParameter("DeviceId", deviceId);
+}
+

+ 73 - 0
moguan-sdk/src/model/RegisterDeviceResult.cc

@@ -0,0 +1,73 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <alibabacloud/moguan-sdk/model/RegisterDeviceResult.h>
+#include <json/json.h>
+
+using namespace AlibabaCloud::Moguan_sdk;
+using namespace AlibabaCloud::Moguan_sdk::Model;
+
+RegisterDeviceResult::RegisterDeviceResult() :
+	ServiceResult()
+{}
+
+RegisterDeviceResult::RegisterDeviceResult(const std::string &payload) :
+	ServiceResult()
+{
+	parse(payload);
+}
+
+RegisterDeviceResult::~RegisterDeviceResult()
+{}
+
+void RegisterDeviceResult::parse(const std::string &payload)
+{
+	Json::Reader reader;
+	Json::Value value;
+	reader.parse(payload, value);
+	setRequestId(value["RequestId"].asString());
+	auto dataNode = value["Data"];
+	if(!dataNode["Rid"].isNull())
+		data_.rid = dataNode["Rid"].asString();
+	if(!value["Message"].isNull())
+		message_ = value["Message"].asString();
+	if(!value["ErrorCode"].isNull())
+		errorCode_ = std::stoi(value["ErrorCode"].asString());
+	if(!value["ErrorMessage"].isNull())
+		errorMessage_ = value["ErrorMessage"].asString();
+
+}
+
+std::string RegisterDeviceResult::getMessage()const
+{
+	return message_;
+}
+
+RegisterDeviceResult::Data RegisterDeviceResult::getData()const
+{
+	return data_;
+}
+
+int RegisterDeviceResult::getErrorCode()const
+{
+	return errorCode_;
+}
+
+std::string RegisterDeviceResult::getErrorMessage()const
+{
+	return errorMessage_;
+}
+