This commit is contained in:
anlicheng 2025-04-16 14:38:58 +08:00
parent 03ba9ced25
commit ed5c6bc3cf
3 changed files with 13 additions and 11 deletions

View File

@ -89,7 +89,7 @@ read_body(Req, AccData) ->
handle_request("POST", "/api/device_token", _, #{<<"user_id">> := UserId, <<"token">> := Token}) ->
case mnesia_device_token:insert(UserId, Token, dimension_utils:current_time()) of
ok ->
{ok, 200, dimension_utils:json_data(<<"OK">>)};
{ok, 200, dimension_utils:json_data(<<"success">>)};
{error, Reason} ->
lager:notice("[api_handler] insert user_id: ~p, token: ~p, error: ~p", [UserId, Token, Reason]),
{ok, 200, dimension_utils:json_error(-1, <<"更新token失败"/utf8>>)}
@ -98,7 +98,7 @@ handle_request("POST", "/api/device_token", _, #{<<"user_id">> := UserId, <<"tok
%%
handle_request("POST", "/api/push", _, PushList) ->
{ok, 200, dimension_utils:json_data(<<"OK">>)};
{ok, 200, dimension_utils:json_data(<<"success">>)};
handle_request(_, Path, _, _) ->
Path1 = list_to_binary(Path),

View File

@ -30,21 +30,18 @@
%%%===================================================================
test() ->
UserId = <<"ed1021b3-d88c-4016-aaf2-340793b16ebf">>,
DeviceToken = <<"7fd3df4063670d945490cdaf511dedff8c56679c5c504af946806f78d002e8cf">>,
Title = <<"动物狂响曲"/utf8>>,
Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>,
push([
#{
<<"user_id">> => UserId,
<<"title">> => Title,
<<"body">> => Body
}
]).
push_with_token(DeviceToken, Title, Body).
-spec push(NotificationList :: list()) -> no_return().
push(NotificationList) when is_list(NotificationList) ->
gen_server:cast(?SERVER, {push, NotificationList}).
push_with_token(DeviceToken, Title, Body) when is_binary(DeviceToken), is_binary(Title), is_binary(Body) ->
gen_server:cast(?SERVER, {push_with_token, DeviceToken, Title, Body}).
%% @doc Spawns the server and registers the local name (unique)
-spec(start_link() ->
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
@ -91,6 +88,11 @@ handle_call(_Request, _From, State = #state{}) ->
{stop, Reason :: term(), NewState :: #state{}}).
handle_cast({push, NotificationList}, State = #state{task_pids = TaskPids}) ->
dispatch(NotificationList, TaskPids),
{noreply, State};
handle_cast({push_with_token, DeviceToken, Title, Body}, State = #state{task_pids = [TaskPid|_]}) ->
dimension_task:submit(TaskPid, fun() ->
poolboy:transaction(apns_pool, fun(WorkerPid) -> dimension_apn_worker:push(WorkerPid, DeviceToken, Title, Body) end)
end),
{noreply, State}.
%% @private

View File

@ -3,7 +3,7 @@
%% http服务器
{http_server, [
{port, 18080},
{port, 18084},
{acceptors, 500},
{max_connections, 10240},
{backlog, 10240}