区分环境
This commit is contained in:
parent
774bf79897
commit
ff98b783df
@ -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) ->
|
||||
{ok, Pid} = dimension_apn_worker:start_link(),
|
||||
{ok, Pid} = dimension_apn_worker:start_link(apns_dev),
|
||||
dimension_apn_worker:push(Pid, Notifications),
|
||||
|
||||
{ok, 200, dimension_utils:json_data(<<"success">>)};
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
-behaviour(gen_server).
|
||||
|
||||
%% API
|
||||
-export([start_link/0]).
|
||||
-export([start_link/1]).
|
||||
-export([push/2]).
|
||||
-export([test/0]).
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
%%%===================================================================
|
||||
|
||||
test() ->
|
||||
{ok, Pid} = start_link(),
|
||||
{ok, Pid} = start_link(apns_dev),
|
||||
DeviceToken = <<"b48b911e85874b403ce80cbb33864e8ed6f06455e80310b0f6b95e672a3e39dc">>,
|
||||
Title = <<"动物狂响曲"/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}).
|
||||
|
||||
%% @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()}).
|
||||
start_link() ->
|
||||
gen_server:start_link(?MODULE, [], []).
|
||||
start_link(Profile) when is_atom(Profile) ->
|
||||
gen_server:start_link(?MODULE, [Profile], []).
|
||||
|
||||
%%%===================================================================
|
||||
%%% gen_server callbacks
|
||||
@ -68,8 +68,8 @@ start_link() ->
|
||||
-spec(init(Args :: term()) ->
|
||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||
{stop, Reason :: term()} | ignore).
|
||||
init([]) ->
|
||||
{ok, Props} = application:get_env(dimension_apn, apns),
|
||||
init([Profile]) ->
|
||||
{ok, Props} = application:get_env(dimension_apn, Profile),
|
||||
ConnectionOpts0 = proplists:get_value(connection_opts, Props),
|
||||
Headers0 = proplists:get_value(headers, Props),
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
]},
|
||||
|
||||
%% 推送配置
|
||||
{apns, [
|
||||
{apns_dev, [
|
||||
{connection_opts, [
|
||||
{apple_host, "api.sandbox.push.apple.com"},
|
||||
{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, [
|
||||
|
||||
]}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user