Ssl 使用erlang发送APN
这是我用来发送APN的部分代码Ssl 使用erlang发送APN,ssl,erlang,apple-push-notifications,ejabberd,Ssl,Erlang,Apple Push Notifications,Ejabberd,这是我用来发送APN的部分代码 Options = case Password of undefined -> [{certfile, Cert}, {keyfile, Keyfile}, {mode, binary}]; _ -> [{certfile, Cert}, {keyfile, Keyfile}, {password, Password}, {mode, binary}] end, case ssl:
Options = case Password of
undefined ->
[{certfile, Cert}, {keyfile, Keyfile}, {mode, binary}];
_ ->
[{certfile, Cert}, {keyfile, Keyfile}, {password, Password}, {mode, binary}]
end,
case ssl:connect(Address, Port, Options, ?Timeout) of
{ok, Socket} ->
PayloadBin = list_to_binary(Payload),
PayloadLength = size(PayloadBin),
TokenNum = erlang:binary_to_integer(Token, 16),
TokenBin = <<TokenNum:32/integer-unit:8>>,
Packet = <<
0:8,
32:16/big,
TokenBin/binary,
PayloadLength:16/big,
PayloadBin/binary
>>,
ssl:send(Socket, Packet),
ssl:close(Socket),
?DEBUG("mod_apns: Successfully sent payload to the APNS server", []),
ok;
{error, Reason} ->
?ERROR_MSG("mod_apns: Unable to connect:~p to the APNS server ~p: ~p", [Options, Address, Reason]),
Reason
end
Options=密码大小写
未定义->
[{certfile,Cert},{keyfile,keyfile},{mode,binary}];
_ ->
[{certfile,Cert},{keyfile,keyfile},{password,password},{mode,binary}]
完,,
案例ssl:ssl的连接(地址、端口、选项、超时)
{好的,套接字}->
PayloadBin=列表到二进制(有效载荷),
有效载荷长度=尺寸(有效载荷箱),
TokenNum=erlang:binary-to-integer(Token,16),
TokenBin=,
数据包=>,,
ssl:发送(套接字、数据包),
ssl:关闭(套接字),
?调试(“mod_apns:已成功将有效负载发送到apns服务器,[]),
好啊
{错误,原因}->
?错误消息(“mod_apns:无法连接:~p到apns服务器~p:~p”,[选项、地址、原因],
理由
结束
但我得到了这个错误:
Unable to connect:[{certfile,<<"/etc/certificates/myCer.pem">>},{keyfile,<<"/etc/certificates/myKey.pem">>},{mode,binary}] to the APNS server <<"gateway.push.apple.com">>: {options,{socket_options,[{mode,binary}]}}
无法将:[{certfile,},{keyfile,},{mode,binary}]连接到APNS服务器:{options,{socket_options,[{mode,binary}]}
这是一个ejabberd模块,相同的代码在ejabberd 17.04中有效,但在17.06中无效。证书和密钥是有效的,正如我所说,我可以使用与旧版本ejabberd相同的erlang模块获取APN。
我是erlang新手,不理解错误消息
({options,{socket_options,[{mode,binary}]})
非常感谢您的帮助。问题是我发送的是二进制文件而不是列表:
mod_opt_type(address) -> fun binary_to_list/1;
mod_opt_type(port) -> fun(I) when is_integer(I) -> I end;
mod_opt_type(certfile) -> fun binary_to_list/1;
mod_opt_type(keyfile) -> fun binary_to_list/1;
我添加了更多的代码。。当我将{mode,binary}更改为{mode,mode::binary | list}时,可能会出现语法错误:
{mode,mode::binary | list}=>接收到的数据包按照mode的定义传递。
因此…接收到的数据包要么是erlang二进制类型,要么是列表。该选项将被指定为{mode,binary}
或{mode,list}
。在我发布的规范中,占位符变量的名称是Mode,它可以有值binary | list
。当我使用{mode,list}时,错误变为:{options,{socket_options,[{mode,list}]}如果有,我不确定如何检查!我只是简单地在ssl:connect转到{error,Reason}->部分之后打印出原因