firebase-cloud-messaging - 如何在 ejabberd 上使用 FCM 连接和发送推送通知?
问题描述
我正在尝试使用 FCM 向 android 客户端发送推送通知。我点击以下链接:https ://github.com/vkatsuba/epns但收到以下错误:异常错误:未定义函数 epns:push/2这是我的代码:```
-behaviour(gen_mod).
-export([start/2, stop/1, mod_options/1, mod_doc/0, depends/2, create_message/1, post_offline_message/3]).
-include("/home/faiqkhan/ejabberd-20.07/lib/fast_xml-1.1.43/include/fxml.hrl").
-include("/home/faiqkhan/ejabberd-20.07/lib/ejabberd-20.07/include/logger.hrl").
-include("/home/faiqkhan/ejabberd-20.07/lib/ejabberd-20.07/include/translate.hrl").
start(_Host, _Opt) ->
?INFO_MSG("mod_http_offline loading", []),
ejabberd_hooks:add(offline_message_hook, _Host, ?MODULE, create_message, 0).
stop (_Host) ->
?INFO_MSG("stopping mod_http_offline", []),
ejabberd_hooks:delete(offline_message_hook, _Host, ?MODULE, create_message, 0).
create_message({_Action, Packet} = Acc) ->
% ?INFO_MSG("Packet details: ~p", [Packet]),
EncodedData = xmpp:encode(Packet),
% ?INFO_MSG("Encoded Packet: ~p", [EncodedData]),
{value, To} = fxml:get_tag_attr(<<"to">>, EncodedData),
{value, From} = fxml:get_tag_attr(<<"from">>, EncodedData),
Body = fxml:get_path_s(EncodedData, [{elem, <<"body">>}, cdata]),
To_id = lists:nth(1,string:lexemes(To,"@")),
From_id = lists:nth(1,string:lexemes(From,"@")),
?INFO_MSG("To id: ~p",[To_id]),
?INFO_MSG("From id: ~p",[From_id]),
?INFO_MSG("PacketsBody ~p",[Body]),
post_offline_message(From_id, To_id, Body),
Acc.
post_offline_message(From, To, Body) ->
?INFO_MSG("Posting From ~p To ~p Body ~p~n",[From, To, Body]),
?INFO_MSG("post request sent (not really yet)", []),
FCMData = #{
key => "fcm-key",
url => "https://fcm.googleapis.com/fcm/send",
playload => #{
to => <<"rid">>,
priority => <<"high">>,
data => #{
<<"title">> => <<"Some Title">>,
<<"some_custom_field">> => true
}
}
}, epns:push(fcm, FCMData).
解决方案
exception error: undefined function epns:push/2
This means that Erlang couldn't find the file epns.beam with the function push/2
defined.
From what I see, that module defines and exports that function correctly, https://github.com/vkatsuba/epns/blob/master/src/epns.erl
So probably the problem is that you forgot some step:
- compile that epns library with the same Erlang version that you run ejabberd
- copy the *.beam files to a path where erlang can find them (for example, copy those files with all the other ejabberd *.beam files)
推荐阅读
- spring-boot - 尝试在 Spring Boot 应用程序中使用 Redis 作为缓存时出现存储库错误
- java - 使用 InetSocketAddress 创建 DatagramPacket,缺少构造函数
- javascript - 单页 Vue 应用程序仅在 https 上的 aws s3 上加载空白
- svn - 从命令行列出 SVN 的项目/分支/主干
- javascript - MySQL 在 Windows 上给了我“未知列”错误
- javascript - 使用顶部 div 和底部 div 背景创建一个渐变,将它们连接到中间 div
- vba - 如何将收件箱中的电子邮件保存到本地驱动器为 .msg 文件?
- php - 即使使用索引,Laravel orWhere 查询也非常慢
- java - springboot依赖类可以自动装配服务模块吗?
- google-apps-script - Google Sheet Script - 将每个选项卡保存到特定文件夹中的单独文件中