fix
This commit is contained in:
parent
23d78471ab
commit
dfbc34a975
@ -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.
|
||||
|
||||
|
||||
@ -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, <<CommandType:8, EncCommand/binary>>}, 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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user