小米xiaomi推送push server sdk for Erlang
集成版本:https://github.com/dcy/epush
使用例子:/src/xiaomi_push_example.erl
- gen_authorization(AppSecret)
- gen_headers(AppSecret)
- regid_message(MsgMaps) ->
- regid_message(AppSecret, MsgMaps) ->
MsgMaps = #{<<"description">> => <<68,69,83,67,229,134,133,229,174,185>>,
<<"extra.notify_effect">> => 1,
<<"notify_type">> => -1,
<<"pass_through">> => 0,
<<"registration_id">> => <<"go6VssZlTDDypm+hxYdaxycXtqM7M9NsTPbCjzyIyh0=">>,
<<"restricted_package_name">> => <<"xiaomi_pkg_name">>,
<<"title">> => <<84,105,116,108,101,230,160,135,233,162,152>>},
xiaomi_push:regid_message(MsgMaps).
- regid_notification(RegIds, Title, Desc) ->
- regid_notification(AppSecret, PkgName, RegIds, Title, Desc) ->
xiaomi_push:regid_notification(?REGID, ?TITLE, ?DESC).
- regid_pass_through(RegIds, Payload) ->
- regid_pass_through(AppSecret, PkgName, RegIds, Payload) ->
Payload = jiffy:encode(#{<<"body">> => <<"Body">>}),
xiaomi_push:regid_pass_through(?REGID, Payload).
- regid_messages(Messages) ->
- regid_messages(AppSecret, Messages) ->
{ok, PkgName} = application:get_env(xiaomi_push, pkg_name),
Message1 = #{<<"restricted_package_name">> => list_to_binary(PkgName),
<<"pass_through">> => 0,
<<"notify_type">> => -1,
<<"title">> => unicode:characters_to_binary("title"),
<<"description">> => unicode:characters_to_binary("description")
},
Messages = [#{<<"target">> => list_to_binary(?REGID), <<"message">> => Message1}],
xiaomi_push:regid_messages(Messages).
- all_message(MsgMaps) ->
- all_message(AppSecret, MsgMaps) ->
MsgMaps =#{<<"description">> => <<68,69,83,67,229,134,133,229,174,185>>,
<<"extra.notify_effect">> => 1,
<<"notify_type">> => -1,
<<"pass_through">> => 0,
<<"restricted_package_name">> => <<"xiaomi_pkg_name">>,
<<"title">> => <<84,105,116,108,101,230,160,135,233,162,152>>},
xiaomi_push:all_message(MsgMaps).
- all_notificaiton(Title, Desc) ->
- all_notificaiton(AppSecret, PkgName, Title, Desc) ->
xiaomi_push:all_notificaiton(?TITLE, ?DESC).
- all_pass_through(Payload) ->
- all_pass_through(AppSecret, PkgName, Payload) ->
xiaomi_push:all_pass_through(<<"Hello World">>).
- topic_message(MsgMaps) ->
- topic_message(AppSecret, MsgMaps) ->
MsgMaps = #{<<"description">> => <<68,69,83,67,229,134,133,229,174,185>>,
<<"extra.notify_effect">> => 1,
<<"notify_type">> => -1,
<<"pass_through">> => 0,
<<"restricted_package_name">> => <<"xiaomi_pkg_name">>,
<<"title">> => <<84,105,116,108,101,230,160,135,233,162,152>>,
<<"topic">> => <<"topic1">>},
xiaomi_push:topic_message(MsgMaps).
- topic_notification(Topic, Title, Desc) ->
- topic_notification(AppSecret, PkgName, Topic, Title, Desc) ->
xiaomi_push:topic_notification("topic1", ?TITLE, ?DESC).
- topic_pass_through(Topic, Payload) ->
- topic_pass_through(AppSecret, PkgName, Topic, Payload) ->
xiaomi_push:topic_pass_through("topic1", ?PAYLOAD).
- regid_subscribe(RegId, Topic) ->
- regid_subscribe(AppSecret, PkgName, RegId, Topic) ->
xiaomi_push:regid_subscribe(?REGID, "topic1").
- regid_unsubscribe(RegId, Topic) ->
- regid_unsubscribe(AppSecret, PkgName, RegId, Topic) ->
xiaomi_push:regid_unsubscribe(?REGID, "topic1").
- message_status(StartDate, EndDate) ->
- message_status(AppSecret, PkgName, StartDate, EndDate) ->
xiaomi_push:message_status("20161016", "20161018").
- trace_status(MsgId) ->
- trace_status(AppSecret, PkgName, MsgId) ->
xiaomi_push:trace_status("slm43b99476776547639jH").
- fetch_invalid_regids() ->
- fetch_invalid_regids(AppSecret) ->
xiaomi_push:fetch_invalid_regids().
- all_topic(RegId) ->
- all_topic(AppSecret, RegId) when is_list(RegId) or is_binary(RegId) ->
xiaomi_push:all_topic(?REGID).
- all_topic(AppSecret, Query) when is_map(Query) ->
{ok, AppSecret} = application:get_env(xiaomi_push, app_secret),
{ok, PkgName} = application:get_env(xiaomi_push, pkg_name),
Query = #{<<"restricted_package_name">> => list_to_binary(PkgName),
<<"registration_id">> => list_to_binary(?REGID)
},
xiaomi_push:all_topic(AppSecret, Query).