fix donghuoliren
This commit is contained in:
parent
c8697631de
commit
ebf5c95f5e
@ -35,7 +35,7 @@
|
|||||||
-define(METHOD_FEEDBACK_RESULT, 16#06).
|
-define(METHOD_FEEDBACK_RESULT, 16#06).
|
||||||
-define(METHOD_EVENT, 16#07).
|
-define(METHOD_EVENT, 16#07).
|
||||||
%% ai识别的事件上报
|
%% ai识别的事件上报
|
||||||
-define(METHOD_AI_EVENT, 16#08).
|
-define(METHOD_AI_EVENT, 17#08).
|
||||||
|
|
||||||
%% 消息体类型
|
%% 消息体类型
|
||||||
-define(PACKET_REQUEST, 16#01).
|
-define(PACKET_REQUEST, 16#01).
|
||||||
|
|||||||
@ -99,21 +99,25 @@ handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params},
|
|||||||
State = #state{url = Url, token = Token, location_map = LocationMap, logger_pid = LoggerPid, succ_counter = SuccCounter, fail_counter = FailCounter}) ->
|
State = #state{url = Url, token = Token, location_map = LocationMap, logger_pid = LoggerPid, succ_counter = SuccCounter, fail_counter = FailCounter}) ->
|
||||||
|
|
||||||
Location = maps:get(LocationCode, LocationMap, <<"">>),
|
Location = maps:get(LocationCode, LocationMap, <<"">>),
|
||||||
Body = format_event(Location, DynamicLocationCode, EventType, Params),
|
case format_event(Location, DynamicLocationCode, EventType, Params) of
|
||||||
%% 签名信息
|
{ok, Body} ->
|
||||||
Sign = iot_util:md5(iolist_to_binary([Token, Body, Token])),
|
%% 签名信息
|
||||||
Url1 = Url ++ "?sign=" ++ binary_to_list(Sign),
|
Sign = iot_util:md5(iolist_to_binary([Token, Body, Token])),
|
||||||
|
Url1 = Url ++ "?sign=" ++ binary_to_list(Sign),
|
||||||
|
|
||||||
case do_post(Url1, Body) of
|
case do_post(Url1, Body) of
|
||||||
{ok, RespBody} ->
|
{ok, RespBody} ->
|
||||||
%% 记录日志
|
%% 记录日志
|
||||||
iot_logger:write(LoggerPid, [<<"OK">>, list_to_binary(Url1), Body, RespBody]),
|
iot_logger:write(LoggerPid, [<<"OK">>, list_to_binary(Url1), Body, RespBody]),
|
||||||
{noreply, State#state{succ_counter = SuccCounter + 1}};
|
{noreply, State#state{succ_counter = SuccCounter + 1}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
NReason = iolist_to_binary(io_lib:format("~p", [Reason])),
|
NReason = iolist_to_binary(io_lib:format("~p", [Reason])),
|
||||||
iot_logger:write(LoggerPid, [<<"ERROR">>, list_to_binary(Url1), Body, NReason]),
|
iot_logger:write(LoggerPid, [<<"ERROR">>, list_to_binary(Url1), Body, NReason]),
|
||||||
{noreply, State#state{fail_counter = FailCounter + 1}}
|
{noreply, State#state{fail_counter = FailCounter + 1}}
|
||||||
end.
|
end;
|
||||||
|
error ->
|
||||||
|
lager:notice("[iot_donghuoliren_endpoint] format_event error, message is: ~p", [Params])
|
||||||
|
end.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% @doc Handling all non call/cast messages
|
%% @doc Handling all non call/cast messages
|
||||||
@ -165,32 +169,48 @@ do_post(Url, Body) when is_binary(Body) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%% 格式话要发送的数据,避免多次格式化处理
|
%% 格式话要发送的数据,避免多次格式化处理
|
||||||
-spec format_event(LocationCode :: binary(), DynamicLocationCode :: binary(), EventType :: integer(), Params :: map()) -> Body :: binary().
|
-spec format_event(LocationCode :: binary(), DynamicLocationCode :: binary(), EventType :: integer(), Params :: map()) -> {ok, Body :: binary()} | error.
|
||||||
format_event(Location, DynamicLocationCode, EventType,
|
format_event(Location, DynamicLocationCode, EventType,
|
||||||
#{<<"datetime">> := Datetime, <<"attachments">> := Attachments0})
|
#{<<"datetime">> := Datetime, <<"rtsp">> := RTSPUrl, <<"attachments">> := Attachments0})
|
||||||
when is_binary(Location), is_binary(DynamicLocationCode), is_integer(EventType) ->
|
when is_binary(Location), is_binary(DynamicLocationCode), is_integer(EventType), is_binary(RTSPUrl) ->
|
||||||
|
|
||||||
%Attachments = lists:map(fun(#{<<"filename">> := Filename}) ->
|
Attachments = lists:map(fun(#{<<"filename">> := Filename, <<"type">> := Type}) ->
|
||||||
% {ok, FileUrl} = iot_util:file_uri(Filename),
|
{ok, FileUrl} = iot_util:file_uri(Filename),
|
||||||
% Name = filename:basename(FileUrl),
|
{Type, FileUrl}
|
||||||
% #{<<"name">> => Name, <<"url">> => FileUrl}
|
end, Attachments0),
|
||||||
% end, Attachments0),
|
|
||||||
|
|
||||||
Attachments = [
|
%% 查找视频信息
|
||||||
<<"https://lgsiot.njau.edu.cn/upload/2024/11/29/2024-11-29-1732842080-1732842100.mp4">>,
|
Videos = lists:filtermap(fun({Type, Url}) ->
|
||||||
<<"https://lgsiot.njau.edu.cn/upload/2024/11/29/2024-11-29-1732842080-1732842100.jpg">>
|
case Type =:= <<"video">> of
|
||||||
],
|
true ->
|
||||||
|
{true, Url};
|
||||||
|
false -> false
|
||||||
|
end
|
||||||
|
end, Attachments),
|
||||||
|
%% 查找附件信息
|
||||||
|
Thumbnails = lists:filtermap(fun({Type, Url}) ->
|
||||||
|
case Type =:= <<"thumbnail">> of
|
||||||
|
true ->
|
||||||
|
{true, Url};
|
||||||
|
false ->
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end, Attachments),
|
||||||
|
|
||||||
%% 对端有key的顺序限制
|
case length(Videos) > 0 andalso length(Thumbnails) > 0 of
|
||||||
Params = #{
|
true ->
|
||||||
<<"attachments">> => Attachments,
|
%% 对端有key的顺序限制
|
||||||
<<"eventLocation">> => Location,
|
Params = #{
|
||||||
<<"eventTime">> => Datetime,
|
<<"attachments">> => [hd(Videos), hd(Thumbnails)],
|
||||||
<<"eventType">> => <<"动火离人"/utf8>>,
|
<<"eventLocation">> => Location,
|
||||||
<<"videoJkAddr">> => <<"rtsp://admin:admin@123@192.168.111.147/cam/realmonitor?channel=1&subtype=0">>
|
<<"eventTime">> => Datetime,
|
||||||
},
|
<<"eventType">> => <<"动火离人"/utf8>>,
|
||||||
|
<<"videoJkAddr">> => RTSPUrl
|
||||||
iolist_to_binary(serialize(Params)).
|
},
|
||||||
|
{ok, iolist_to_binary(serialize(Params))};
|
||||||
|
false ->
|
||||||
|
error
|
||||||
|
end.
|
||||||
|
|
||||||
%% 简单的序列话函数,升序排列
|
%% 简单的序列话函数,升序排列
|
||||||
-spec serialize(M :: map()) -> JsonString :: binary().
|
-spec serialize(M :: map()) -> JsonString :: binary().
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user