简体   繁体   English

使用Erlang发送APN

[英]Sending apns using erlang

this is part of code I am using to send apns. 这是我用来发送APN的代码的一部分。

  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

But I get this error: 但是我得到这个错误:

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}]}}

This is an ejabberd module and same code works in ejabberd 17.04 but not in 17.06. 这是一个ejabberd模块,相同的代码在ejabberd 17.04中起作用,但在17.06中不起作用。
Certificates and keys are valid and as I said I can get apns using same erlang module with older version of ejabberd. 证书和密钥是有效的,正如我所说,我可以使用旧版ejabberd使用相同的erlang模块来获得apn。
I am new to erlang and I don't understand the error message ({options,{socket_options,[{mode,binary}]}}) 我是erlang的新手,但我不理解错误消息({options,{socket_options,[{mode,binary}]}})

Any help is appreciated. 任何帮助表示赞赏。

The problem was I was sending binary instead of list: 问题是我正在发送二进制文件而不是列表:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM