区分环境

This commit is contained in:
anlicheng 2025-08-04 16:34:29 +08:00
parent 774bf79897
commit ff98b783df
3 changed files with 32 additions and 9 deletions

View File

@ -86,8 +86,14 @@ read_body(Req, AccData) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%
handle_request("POST", "/api/prod_push", _, Notifications) ->
{ok, Pid} = dimension_apn_worker:start_link(apns_prod),
dimension_apn_worker:push(Pid, Notifications),
{ok, 200, dimension_utils:json_data(<<"success">>)};
handle_request("POST", "/api/push", _, Notifications) -> handle_request("POST", "/api/push", _, Notifications) ->
{ok, Pid} = dimension_apn_worker:start_link(), {ok, Pid} = dimension_apn_worker:start_link(apns_dev),
dimension_apn_worker:push(Pid, Notifications), dimension_apn_worker:push(Pid, Notifications),
{ok, 200, dimension_utils:json_data(<<"success">>)}; {ok, 200, dimension_utils:json_data(<<"success">>)};

View File

@ -12,7 +12,7 @@
-behaviour(gen_server). -behaviour(gen_server).
%% API %% API
-export([start_link/0]). -export([start_link/1]).
-export([push/2]). -export([push/2]).
-export([test/0]). -export([test/0]).
@ -31,7 +31,7 @@
%%%=================================================================== %%%===================================================================
test() -> test() ->
{ok, Pid} = start_link(), {ok, Pid} = start_link(apns_dev),
DeviceToken = <<"b48b911e85874b403ce80cbb33864e8ed6f06455e80310b0f6b95e672a3e39dc">>, DeviceToken = <<"b48b911e85874b403ce80cbb33864e8ed6f06455e80310b0f6b95e672a3e39dc">>,
Title = <<"动物狂响曲"/utf8>>, Title = <<"动物狂响曲"/utf8>>,
Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>, Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>,
@ -54,10 +54,10 @@ push(Pid, Notifications) when is_pid(Pid), is_list(Notifications) ->
gen_server:cast(Pid, {push, Notifications}). gen_server:cast(Pid, {push, Notifications}).
%% @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(Profile :: atom()) ->
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}). {ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
start_link() -> start_link(Profile) when is_atom(Profile) ->
gen_server:start_link(?MODULE, [], []). gen_server:start_link(?MODULE, [Profile], []).
%%%=================================================================== %%%===================================================================
%%% gen_server callbacks %%% gen_server callbacks
@ -68,8 +68,8 @@ start_link() ->
-spec(init(Args :: term()) -> -spec(init(Args :: term()) ->
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} | {ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
{stop, Reason :: term()} | ignore). {stop, Reason :: term()} | ignore).
init([]) -> init([Profile]) ->
{ok, Props} = application:get_env(dimension_apn, apns), {ok, Props} = application:get_env(dimension_apn, Profile),
ConnectionOpts0 = proplists:get_value(connection_opts, Props), ConnectionOpts0 = proplists:get_value(connection_opts, Props),
Headers0 = proplists:get_value(headers, Props), Headers0 = proplists:get_value(headers, Props),

View File

@ -10,7 +10,7 @@
]}, ]},
%% 推送配置 %% 推送配置
{apns, [ {apns_dev, [
{connection_opts, [ {connection_opts, [
{apple_host, "api.sandbox.push.apple.com"}, {apple_host, "api.sandbox.push.apple.com"},
{apple_port, 443}, {apple_port, 443},
@ -27,6 +27,23 @@
]} ]}
]}, ]},
{apns_prod, [
{connection_opts, [
{apple_host, "https://api.push.apple.com"},
{apple_port, 443},
{certfile, "cert.pem"},
{keyfile, "private.key"},
{type, cert},
{timeout, 5000}
]},
{headers, [
{apns_expiration, 0},
{apns_priority, 10},
{apns_topic, "com.jihe.dimensionhub"},
{apns_push_type, "alert"}
]}
]},
{pools, [ {pools, [
]} ]}