fix donghuoliren locations
This commit is contained in:
parent
e6cabce4f0
commit
c8697631de
@ -25,6 +25,8 @@
|
|||||||
%% 签名用的token值
|
%% 签名用的token值
|
||||||
token :: binary(),
|
token :: binary(),
|
||||||
url :: string(),
|
url :: string(),
|
||||||
|
%% 保存了 #{location_code => "具体地址信息"}, 配置时是字符串,需要转换成binary
|
||||||
|
location_map :: #{},
|
||||||
succ_counter = 0,
|
succ_counter = 0,
|
||||||
fail_counter = 0,
|
fail_counter = 0,
|
||||||
logger_pid :: pid()
|
logger_pid :: pid()
|
||||||
@ -67,10 +69,12 @@ init([]) ->
|
|||||||
{ok, Props} = application:get_env(iot, donghuoliren),
|
{ok, Props} = application:get_env(iot, donghuoliren),
|
||||||
Token = proplists:get_value(token, Props),
|
Token = proplists:get_value(token, Props),
|
||||||
Url = proplists:get_value(url, 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, 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
|
%% @private
|
||||||
%% @doc Handling call messages
|
%% @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} |
|
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params},
|
handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params},
|
||||||
State = #state{url = Url, token = Token, 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}) ->
|
||||||
|
|
||||||
Body = format_event(LocationCode, DynamicLocationCode, EventType, Params),
|
|
||||||
|
|
||||||
|
Location = maps:get(LocationCode, LocationMap, <<"">>),
|
||||||
|
Body = format_event(Location, DynamicLocationCode, EventType, Params),
|
||||||
%% 签名信息
|
%% 签名信息
|
||||||
Sign = iot_util:md5(iolist_to_binary([Token, Body, Token])),
|
Sign = iot_util:md5(iolist_to_binary([Token, Body, Token])),
|
||||||
Url1 = Url ++ "?sign=" ++ binary_to_list(Sign),
|
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().
|
-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})
|
#{<<"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}) ->
|
%Attachments = lists:map(fun(#{<<"filename">> := Filename}) ->
|
||||||
% {ok, FileUrl} = iot_util:file_uri(Filename),
|
% {ok, FileUrl} = iot_util:file_uri(Filename),
|
||||||
@ -180,7 +184,7 @@ format_event(LocationCode, DynamicLocationCode, EventType,
|
|||||||
%% 对端有key的顺序限制
|
%% 对端有key的顺序限制
|
||||||
Params = #{
|
Params = #{
|
||||||
<<"attachments">> => Attachments,
|
<<"attachments">> => Attachments,
|
||||||
<<"eventLocation">> => <<"事件地点测试值"/utf8>>,
|
<<"eventLocation">> => Location,
|
||||||
<<"eventTime">> => Datetime,
|
<<"eventTime">> => Datetime,
|
||||||
<<"eventType">> => <<"动火离人"/utf8>>,
|
<<"eventType">> => <<"动火离人"/utf8>>,
|
||||||
<<"videoJkAddr">> => <<"rtsp://admin:admin@123@192.168.111.147/cam/realmonitor?channel=1&subtype=0">>
|
<<"videoJkAddr">> => <<"rtsp://admin:admin@123@192.168.111.147/cam/realmonitor?channel=1&subtype=0">>
|
||||||
|
|||||||
@ -89,7 +89,11 @@
|
|||||||
%% 智慧监控平台
|
%% 智慧监控平台
|
||||||
{donghuoliren, [
|
{donghuoliren, [
|
||||||
{url, "https://xsdc.njau.edu.cn/hq-cyaqjg/rest/rgkSmart/push"},
|
{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, [
|
{pools, [
|
||||||
|
|||||||
@ -66,7 +66,11 @@
|
|||||||
%% 智慧监控平台
|
%% 智慧监控平台
|
||||||
{donghuoliren, [
|
{donghuoliren, [
|
||||||
{url, "https://xsdc.njau.edu.cn/hq-cyaqjg/rest/rgkSmart/push"},
|
{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数据库配置
|
%% influxdb数据库配置
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user