我正在尝试触发Apple推送通知。我的代码是:
-module(ssltest).
-export([sendpush/0]).
sendpush() ->
Address = "gateway.sandbox.push.apple.com",
Port = 2195,
Cert = "/usr/lib/erlang/bin/MantuPush/cert.pem",
Key = "/usr/lib/erlang/bin/MantuPush/key.pem",
Options = [{certfile, Cert}, {keyfile, Key}, {mode, binary}],
Timeout = 1000,
{ok, Socket} = ssl:connect(Address, Port, Options, Timeout),
Payload = mochijson2:encode({struct, [{"aps", [{"alert", "This is Message"}]}]}),
BPayload = erlang:list_to_binary(Payload),
PayloadLen = erlang:byte_size(BPayload),
Token = "7518b1c2c7686d3b5dcac8232313d5d0047cf0dc0ed5d753c017ffb64ad25b60",
BToken = hex:hexstr_to_bin(Token),
BTokenLength = erlang:byte_size(BToken),
SomeID= 1,
{MSeconds,Seconds,_} = erlang:now(),
Expiry = MSeconds * 1000000 + Seconds + 3600*1,
Packet = "1:8, SomeID:32/big, Expiry:32/big, BTokenLength:16/big, BToken/binary, PayloadLen:16/big, BPayload/binary",
ssl:send(Socket, Packet),
ssl:close(Socket).
但每次出现以下错误:
{error,{keyfile,{badmatch,{error,{asn1,{wrong_tag,{{expected,16}, {got,65565,{65565,<<243,247,242,108,193,12,122,139,140,60,...>>}}}}}}}}}
任何线索?