百度一下,會有很多ios推送證書的方法
比如這套:
1、證書轉成pem
openssl x509 -in aps_developer.cer -inform der -out PushChatCert.pem
2、私鑰Push.p12文件轉換成.pem文件
openssl pkcs12 -nocerts -out PushChatKey.pem -in Push.p12
3、私鑰與證書整合到一個.pem文件
cat PushChatCert.pem PushChatKey.pem > ck.pem
4、測試
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
但是怎麼都拿到的證書怎麼都搞不通。。
後來
openssl pkcs12 -clcerts -nokeys -nodes -out apns-dev-key4.pem -in push_dis.p12
openssl pkcs12 -nocerts -nodes -out apns-dev-key5.pem -in push_dis.p12
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-key4.pem -key apns-dev-key5.pem
居然通了
我只是不小心看了一下文件內容,因爲發現好像用錯命令了,然後發現一個裏面是cert,一個裏面是key
然後就試了試。。媽蛋,通了
誰能告訴我,究竟是咋回事兒= =
蛋碎了。。
一共給來四個文件,dev.cer,dev.key,dis.cer,dis.key,都是p12文件,都這樣生成了一下。。然後,有4個key了可以用的東西了。。
localkeyID全是不一樣的= =
轉個別人的東西
- %%%-------------------------------------------------------------------
- %%% @doc
- %%%
- %%% @end
- %%% Created : 31 Aug 2012 langxianzhe@163.com
- %%%-------------------------------------------------------------------
- -module(test_apns).
- -record(apns_connection, {apple_host = "gateway.sandbox.push.apple.com" :: string(),
- apple_port = 2195 :: integer(),
- cert_file = "priv/cert.pem" :: string(),
- key_file = undefined :: undefined | string(),
- timeout = 30000 :: integer(),
- error_fun = fun(X,Y) -> erlang:display({X,Y}) end :: fun((binary(), apns:status()) -> stop | _),
- feedback_host = "feedback.sandbox.push.apple.com" :: string(),
- feedback_port = 2196 :: integer(),
- feedback_fun = fun erlang:display/1 :: fun((string()) -> _),
- feedback_timeout = 30*60*1000 :: pos_integer()
- }).
- -record(apns_msg, {id = apns:message_id() :: binary(),
- expiry = apns:expiry(86400) :: non_neg_integer(), %% default = 1 day
- device_token :: string(),
- alert = none :: none | apns:alert(),
- badge = none :: none | integer(),
- sound = none :: none | string(),
- extra = [] :: [apns_mochijson2:json_property()]}).
- -record(loc_alert, {body = none :: none | string(),
- action = none :: none | string(),
- key = "" :: string(),
- args = [] :: [string()],
- image = none :: none | string()}).
- push_token/1]).
- get_pid() ->
- {ok, Pid} = apns:connect(),
- Pid.
- delete_pid(ConnId) ->
- apns:disconnect(ConnId).
- push_by_pid(ConnId, Token1) ->
- Alert1 = #apns_msg{device_token = Token1,
- badge = 9,
- sound = "bingbong.aiff",
- %extra = [{"jump","yes"}],
- extra = [{jump, yes}],
- alert = #loc_alert{body="hello1"
- }},
- io:format("In ~p:appns_packet ~p Alert1 = ~p ~n", [?MODULE, ?LINE, Alert1]),
- apns:send_message(ConnId, Alert1).
- -spec push(DeviceToken :: string(), Alert :: tuple()) -> ok.
- push(DeviceToken, Alert)->
- Conn = apns:connect(),
- case Conn of
- {ok,ConnId} ->
- Res = apns:send_message(ConnId, DeviceToken, Alert),
- Res1 = apns:send_message(ConnId, DeviceToken, Alert),
- case Res of
- ok ->
- ok;
- Err ->
- Err
- end,
- apns:disconnect(ConnId);
- Err ->
- Err
- end.