繁体   English   中英

使用Erlang发送APN

[英]Sending apns using erlang

这是我用来发送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

但是我得到这个错误:

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

这是一个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;

暂无
暂无

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

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