From dfbc34a975916500d3c56363b1257f3658aeeefb Mon Sep 17 00:00:00 2001 From: anlicheng Date: Thu, 15 Jun 2023 17:25:46 +0800 Subject: [PATCH] fix --- apps/iot/src/http_handler/http_protocol.erl | 1 - apps/iot/src/iot_host.erl | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/iot/src/http_handler/http_protocol.erl b/apps/iot/src/http_handler/http_protocol.erl index 4b1d927..18d3f18 100644 --- a/apps/iot/src/http_handler/http_protocol.erl +++ b/apps/iot/src/http_handler/http_protocol.erl @@ -72,7 +72,6 @@ parse_body(Req0) -> PostParams = maps:from_list(PostParams0), {ok, PostParams, Req1}; _ -> - lager:warning("[http_handler] unsupport content-type is: ~p", [ContentType]), {ok, #{}, Req0} end. diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index 063792c..200a2dd 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -172,8 +172,8 @@ handle_call(has_session, _From, State = #state{has_session = HasSession}) -> %% 实现rsa加密 %% 基于rsa加密的指令都是不需要会话存在的 -handle_call({rsa_encode, _, _}, _From, State = #state{has_session = false}) -> - {reply, {error, <<"会话未建立,发送命令失败"/utf8>>}, State}; +handle_call({rsa_encode, _, _}, _From, State = #state{pub_key = <<>>}) -> + {reply, {error, <<"会话未建立"/utf8>>}, State}; handle_call({rsa_encode, CommandType, PlainText}, _From, State = #state{pub_key = PubKey}) -> Reply = iot_cipher_rsa:encode(PlainText, PubKey), @@ -210,13 +210,13 @@ handle_call({activate, Auth}, _From, State = #state{uuid = UUID, is_activated = %% 创建命令 handle_call({aes_encode, _, _}, _From, State = #state{has_session = false}) -> - {reply, {error, <<"会话未建立,发送命令失败"/utf8>>}, State}; -handle_call({aes_encode, CommandType, Command}, _From, State = #state{aes = AES, uuid = UUID, has_session = true}) -> + {reply, {error, <<"会话未建立"/utf8>>}, State}; +handle_call({aes_encode, CommandType, Command}, _From, State = #state{aes = AES, has_session = true}) -> EncCommand = iot_cipher_aes:encrypt(AES, Command), {reply, {ok, <>}, State}; -handle_call(Info, _From, State = #state{}) -> +handle_call(Info, _From, State) -> lager:debug("[iot_host] handle info: ~p", [Info]), {reply, ok, State}. @@ -299,7 +299,7 @@ handle_message(Payload, State) when is_binary(Payload) -> lager:debug("[iot_host] get message: ~p", [Message]), handle_message(Message, State); -%% create_session操作 +%% create_session操作, 需要等待mqtt服务的响应 handle_message(#{<<"method">> := <<"create_session">>, <<"params">> := #{<<"pub_key">> := PubKey}}, State = #state{is_activated = IsActivated, uuid = UUID, aes = Aes}) -> @@ -322,15 +322,15 @@ handle_message(#{<<"method">> := <<"create_session">>, <<"params">> := #{<<"pub_ State end; -%% 数据上传, TODO 数据格式需要重新约定 +%% 数据上传 handle_message(#{<<"method">> := <<"data">>, <<"params">> := Data}, State = #state{has_session = true, aes = AES, uuid = UUID}) -> PlainData = iot_cipher_aes:decrypt(AES, base64:decode(Data)), case catch jiffy:decode(PlainData, [return_maps]) of Infos when is_list(Infos) -> lager:debug("[iot_host] the data is: ~p", [Infos]), insert_metrics(UUID, Infos); - _ -> - lager:debug("[iot_message_handler] the metric is invalid json") + Other -> + lager:debug("[iot_message_handler] the metric is invalid json: ~p", [Other]) end, State;