fix donghuoliren locations

This commit is contained in:
anlicheng 2024-12-16 10:46:35 +08:00
parent e6cabce4f0
commit c8697631de
3 changed files with 21 additions and 9 deletions

View File

@ -25,6 +25,8 @@
%% token值
token :: binary(),
url :: string(),
%% #{location_code => "具体地址信息"}, binary
location_map :: #{},
succ_counter = 0,
fail_counter = 0,
logger_pid :: pid()
@ -67,10 +69,12 @@ init([]) ->
{ok, Props} = application:get_env(iot, donghuoliren),
Token = proplists:get_value(token, Props),
Url = proplists:get_value(url, Props),
Locations0 = proplists:get_value(locations, Props),
Locations = lists:map(fun({K, V}) -> {list_to_binary(K), unicode:characters_to_binary(V)} end, Locations0),
{ok, LoggerPid} = iot_logger:start_link("donghuoliren_data"),
{ok, #state{token = Token, url = Url, logger_pid = LoggerPid}}.
{ok, #state{token = Token, url = Url, location_map = maps:from_list(Locations), logger_pid = LoggerPid}}.
%% @private
%% @doc Handling call messages
@ -92,10 +96,10 @@ handle_call(get_status, _From, State = #state{succ_counter = SuccCounter, fail_c
{noreply, NewState :: #state{}, timeout() | hibernate} |
{stop, Reason :: term(), NewState :: #state{}}).
handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params},
State = #state{url = Url, token = Token, logger_pid = LoggerPid, succ_counter = SuccCounter, fail_counter = FailCounter}) ->
Body = format_event(LocationCode, DynamicLocationCode, EventType, Params),
State = #state{url = Url, token = Token, location_map = LocationMap, logger_pid = LoggerPid, succ_counter = SuccCounter, fail_counter = FailCounter}) ->
Location = maps:get(LocationCode, LocationMap, <<"">>),
Body = format_event(Location, DynamicLocationCode, EventType, Params),
%%
Sign = iot_util:md5(iolist_to_binary([Token, Body, Token])),
Url1 = Url ++ "?sign=" ++ binary_to_list(Sign),
@ -162,9 +166,9 @@ do_post(Url, Body) when is_binary(Body) ->
%%
-spec format_event(LocationCode :: binary(), DynamicLocationCode :: binary(), EventType :: integer(), Params :: map()) -> Body :: binary().
format_event(LocationCode, DynamicLocationCode, EventType,
format_event(Location, DynamicLocationCode, EventType,
#{<<"datetime">> := Datetime, <<"attachments">> := Attachments0})
when is_binary(LocationCode), is_binary(DynamicLocationCode), is_integer(EventType) ->
when is_binary(Location), is_binary(DynamicLocationCode), is_integer(EventType) ->
%Attachments = lists:map(fun(#{<<"filename">> := Filename}) ->
% {ok, FileUrl} = iot_util:file_uri(Filename),
@ -180,7 +184,7 @@ format_event(LocationCode, DynamicLocationCode, EventType,
%% key的顺序限制
Params = #{
<<"attachments">> => Attachments,
<<"eventLocation">> => <<"事件地点测试值"/utf8>>,
<<"eventLocation">> => Location,
<<"eventTime">> => Datetime,
<<"eventType">> => <<"动火离人"/utf8>>,
<<"videoJkAddr">> => <<"rtsp://admin:admin@123@192.168.111.147/cam/realmonitor?channel=1&subtype=0">>

View File

@ -89,7 +89,11 @@
%% 智慧监控平台
{donghuoliren, [
{url, "https://xsdc.njau.edu.cn/hq-cyaqjg/rest/rgkSmart/push"},
{token, <<"aB3$dEfGhiJkLmNoPqRsTuVwXyZ!@#4f5e6d7c8b9a0f1e2d">>}
{token, <<"aB3$dEfGhiJkLmNoPqRsTuVwXyZ!@#4f5e6d7c8b9a0f1e2d">>},
{locations, [
{"32981253076969472017320929999562", "诚苑餐厅一楼1F"},
{"32981271601113088017320930441218", "诚苑餐厅一楼1F"}
]}
]},
{pools, [

View File

@ -66,7 +66,11 @@
%% 智慧监控平台
{donghuoliren, [
{url, "https://xsdc.njau.edu.cn/hq-cyaqjg/rest/rgkSmart/push"},
{token, <<"aB3$dEfGhiJkLmNoPqRsTuVwXyZ!@#4f5e6d7c8b9a0f1e2d">>}
{token, <<"aB3$dEfGhiJkLmNoPqRsTuVwXyZ!@#4f5e6d7c8b9a0f1e2d">>},
{locations, [
{"32981253076969472017320929999562", "诚苑餐厅一楼1F"},
{"32981271601113088017320930441218", "诚苑餐厅一楼1F"}
]}
]},
%% influxdb数据库配置