fix
This commit is contained in:
parent
03ba9ced25
commit
ed5c6bc3cf
@ -89,7 +89,7 @@ read_body(Req, AccData) ->
|
|||||||
handle_request("POST", "/api/device_token", _, #{<<"user_id">> := UserId, <<"token">> := Token}) ->
|
handle_request("POST", "/api/device_token", _, #{<<"user_id">> := UserId, <<"token">> := Token}) ->
|
||||||
case mnesia_device_token:insert(UserId, Token, dimension_utils:current_time()) of
|
case mnesia_device_token:insert(UserId, Token, dimension_utils:current_time()) of
|
||||||
ok ->
|
ok ->
|
||||||
{ok, 200, dimension_utils:json_data(<<"OK">>)};
|
{ok, 200, dimension_utils:json_data(<<"success">>)};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:notice("[api_handler] insert user_id: ~p, token: ~p, error: ~p", [UserId, Token, 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>>)}
|
{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) ->
|
handle_request("POST", "/api/push", _, PushList) ->
|
||||||
|
|
||||||
{ok, 200, dimension_utils:json_data(<<"OK">>)};
|
{ok, 200, dimension_utils:json_data(<<"success">>)};
|
||||||
|
|
||||||
handle_request(_, Path, _, _) ->
|
handle_request(_, Path, _, _) ->
|
||||||
Path1 = list_to_binary(Path),
|
Path1 = list_to_binary(Path),
|
||||||
|
|||||||
@ -30,21 +30,18 @@
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
test() ->
|
test() ->
|
||||||
UserId = <<"ed1021b3-d88c-4016-aaf2-340793b16ebf">>,
|
DeviceToken = <<"7fd3df4063670d945490cdaf511dedff8c56679c5c504af946806f78d002e8cf">>,
|
||||||
Title = <<"动物狂响曲"/utf8>>,
|
Title = <<"动物狂响曲"/utf8>>,
|
||||||
Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>,
|
Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>,
|
||||||
push([
|
push_with_token(DeviceToken, Title, Body).
|
||||||
#{
|
|
||||||
<<"user_id">> => UserId,
|
|
||||||
<<"title">> => Title,
|
|
||||||
<<"body">> => Body
|
|
||||||
}
|
|
||||||
]).
|
|
||||||
|
|
||||||
-spec push(NotificationList :: list()) -> no_return().
|
-spec push(NotificationList :: list()) -> no_return().
|
||||||
push(NotificationList) when is_list(NotificationList) ->
|
push(NotificationList) when is_list(NotificationList) ->
|
||||||
gen_server:cast(?SERVER, {push, 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)
|
%% @doc Spawns the server and registers the local name (unique)
|
||||||
-spec(start_link() ->
|
-spec(start_link() ->
|
||||||
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
||||||
@ -91,6 +88,11 @@ handle_call(_Request, _From, State = #state{}) ->
|
|||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
handle_cast({push, NotificationList}, State = #state{task_pids = TaskPids}) ->
|
handle_cast({push, NotificationList}, State = #state{task_pids = TaskPids}) ->
|
||||||
dispatch(NotificationList, 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}.
|
{noreply, State}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
%% http服务器
|
%% http服务器
|
||||||
{http_server, [
|
{http_server, [
|
||||||
{port, 18080},
|
{port, 18084},
|
||||||
{acceptors, 500},
|
{acceptors, 500},
|
||||||
{max_connections, 10240},
|
{max_connections, 10240},
|
||||||
{backlog, 10240}
|
{backlog, 10240}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user