From 7f59936e0e36c6bb75169f12474bc3651abab876 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Fri, 13 Dec 2024 18:14:15 +0800 Subject: [PATCH] add log --- .../endpoint/iot_donghuoliren_endpoint.erl | 19 ++++++++++--------- apps/iot/src/iot_ai_router.erl | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/iot/src/endpoint/iot_donghuoliren_endpoint.erl b/apps/iot/src/endpoint/iot_donghuoliren_endpoint.erl index 9303df6..dfbdd01 100644 --- a/apps/iot/src/endpoint/iot_donghuoliren_endpoint.erl +++ b/apps/iot/src/endpoint/iot_donghuoliren_endpoint.erl @@ -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), diff --git a/apps/iot/src/iot_ai_router.erl b/apps/iot/src/iot_ai_router.erl index 689a22c..b242405 100644 --- a/apps/iot/src/iot_ai_router.erl +++ b/apps/iot/src/iot_ai_router.erl @@ -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);