This commit is contained in:
anlicheng 2024-12-13 18:14:15 +08:00
parent fb3f21411c
commit 7f59936e0e
2 changed files with 11 additions and 10 deletions

View File

@ -95,14 +95,18 @@ 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),
case do_post(Url, Token, Body) of
%%
Sign = iot_util:md5(iolist_to_binary([Token, Body, Token])),
Url1 = Url ++ "?sign=" ++ binary_to_list(Sign),
case do_post(Url1, Body) of
{ok, RespBody} ->
%%
iot_logger:write(LoggerPid, [<<"OK">>, Body, RespBody]),
iot_logger:write(LoggerPid, [<<"OK">>, list_to_binary(Url1), Body, RespBody]),
{noreply, State#state{succ_counter = SuccCounter + 1}};
{error, Reason} ->
NReason = iolist_to_binary(io_lib:format("~p", Reason)),
iot_logger:write(LoggerPid, [<<"ERROR">>, Body, NReason]),
iot_logger:write(LoggerPid, [<<"ERROR">>, list_to_binary(Url1), Body, NReason]),
{noreply, State#state{fail_counter = FailCounter + 1}}
end.
@ -137,15 +141,12 @@ code_change(_OldVsn, State = #state{}, _Extra) ->
%%% Internal functions
%%%===================================================================
-spec do_post(Url :: string(), Token :: binary(), Body :: binary()) -> {ok, Resp :: binary()} | {error, any()}.
do_post(Url, Token, Body) when is_binary(Body) ->
-spec do_post(Url :: string(), Body :: binary()) -> {ok, Resp :: binary()} | {error, any()}.
do_post(Url, Body) when is_binary(Body) ->
Headers = [
{<<"content-type">>, <<"application/json">>}
],
Sign = iot_util:md5(iolist_to_binary([Token, Body, Token])),
Url1 = Url ++ "?sign=" ++ binary_to_list(Sign),
case hackney:request(post, Url1, Headers, Body) of
case hackney:request(post, Url, Headers, Body) of
{ok, 200, _, ClientRef} ->
{ok, RespBody} = hackney:body(ClientRef),
hackney:close(ClientRef),

View File

@ -19,7 +19,7 @@ route_uuid(RouterUUID, EventType, Params) when is_binary(RouterUUID), is_integer
case redis_client:hgetall(RouterUUID) of
{ok, #{<<"location_code">> := LocationCode, <<"dynamic_location_code">> := DynamicLocationCode}} when is_binary(LocationCode), is_binary(DynamicLocationCode) ->
%% 2024-12-02
case lists:member(EventType, [17]) of
case lists:member(EventType, [15]) of
true ->
lager:debug("[iot_ai_router] donghuoliren: ~p", [RouterUUID]);
%iot_donghuoliren_endpoint:forward(LocationCode, DynamicLocationCode, EventType, Params);