Baidu Cloud push to send official address Http://developer.baidu.com/wiki/index.php?title=docs/cplat/push
Simple introduction of the following principle:
Baidu Cloud push sends support for iOS and Android cloud push. Android support is good, but iOS is generally difficult to tune. Baidu Cloud for the iOS push, he just did a middle agent, to provide users with the interface, the advantage is to use Baidu Cloud Push, Android and iOS can be unified management; The disadvantage is: the communication is not easy, the user's iOS certificate needs to upload verification, will be directly exposed to the third party, and iOS APNs supports users to build their own provider servers and communicate directly with APNs.
Personal advice: Android uses Baidu Cloud Push, iOS uses its own built provider to communicate directly with iOS APNs. There are many implementations of APNs direct communication with iOS, Java, PHP, object-c, C + +, and one of my blogs is implemented using Erlang and interested to see.
Android implementation push function Baidu Cloud has its own demo, we can according to the official website (http://developer.baidu.com/wiki/index.php?title=docs/cplat/push) of the steps, First register a Baidu developer account, and then create their own application, according to the example Baidu Cloud server will produce a client's demo, can run on the Android phone. Then push the experiment on the page. Of course, you can download Baidu cloud push server, and then run using server Push, the official website has PHP, Java, Python, Node.js, C # implementation.
In view of the need, the individual uses Erlang to implement the service-side push function.
Steps: 1, the above you set up the project Baidu Cloud Server for your production example demo installed to the mobile phone, and then registered with their own developer account login, which has a userid and Channelid,channelid recorded, UserID and developers on the corresponding, Then decide which one to use, if the same, that is fine, not the same as the general use of the registrant page that. UserID can also be analyzed using data obtained from the Android server.
2, get token is also channelid, the specific equipment ID,
3, get the user's Apikey
4, get the user's Secretekey
To send a message to the user are as follows: To give a user all the equipment to send information at this time need the user's userid; send a message to a user at this time need the user's userid and channelid; send a message to a class of users, need tag classification, This means sending information to all users of the class.
Simple example, sending a message to a user device
Copy Code code as follows:
Start ()->
Inets:start (),
{Mega,sec,_} = Now (),
Apikey = "APIKEY=AGHJKLPOIKMNBHJKLPOIJNBFD",% of the user's Apikey
Percent% of my equipment
% channel_id = "channel_id=1234567890098765432",% percent user of a device channelid, that is, client demo installed in the mobile phone Channelid
Percent% simulator
channel_id = "channel_id=3959774938927755088",%-percent client emulator Channelid
Device_type = "device_type=3",%-percent type, details viewed in official documents, 1: browser equipment; 2:pc equipment; 3:android equipment; 4:ios device; 5:windows phone device
Message_type = "message_type=1",% 0: message; 1: notification; default is 0
Titlestr = ": KKKK, Quack ada air pieces Aston,,,, hahaha, Erlang",
Descriptionstr = "OK No: Yes!",
Messages0 = "Messages={\" title\ ": \" ",
Messages1 = Titlestr,
Messages2 = "\", \ "description\": \ "",
Messages3 = Descriptionstr,
Messages4 = "\", \ "notification_builder_id\": 0, "
+ + "\ notification_basic_style\": 2,\ "open_type\": 2,\ "url\": \ "\", \ "user_confirm\": 0,\ "pkg_content\": \ "\", \ " Custom_content\ ": \" \ "}",
Messages = Messages0 + + Messages1 + + Messages2 + + Messages3 + + Messages4,
method = "Method=push_msg",
msg_keys= "Msg_keys=erlang_keys",
Push_type = "Push_type=1",
Time = "timestamp=" + + integer_to_list (Mega * 1000000 + Sec)
user_id = "user_id=213123123",% of the user's UserID
URL = "Http://channel.api.duapp.com/rest/2.0/channel/channel",
Http_method = "POST",
Secretkey = "123weqwe12wq12eqweqweqwe",% of the user's Secretekey
STR0 = Http_method + + URL + + Apikey + + channel_id + + Device_type + + Message_type + + Messages0,
STR1 = Messages2,
STR2 = Messages4 + + method + + Msg_keys + + Push_type + + time + + user_id + + Secretkey,
Titlebin = List_to_binary (TITLESTR),
Tintegeru = Unicode:characters_to_list (Titlebin,utf8),
Tchanges = UTF8 (tintegeru,[]),
Title_utf8 =
LISTS:FOLDL (Fun (CHANGE,ACC)->
Case Change of
[Term] When Term >= $a, Term =< $z->
ACC + + change;
[Term] When Term >= $A, Term =< $Z->
ACC + + change;
[Term] When Term >= $, Term =< $->
ACC + + change;
[Term] When Term =:= $. ->
ACC + + change;
[Term] When Term =:= $_->
ACC + + change;
[Term] When Term =:= $-->
ACC + + change;
[Term] When Term =:=->
ACC + + [43];
_->
ACC + + list_to_hex_s (change)
End
End,[],tchanges),
Desbin = List_to_binary (DESCRIPTIONSTR),
Dintegeru = Unicode:characters_to_list (Desbin,utf8),
Dchanges = UTF8 (dintegeru,[]),
Des_utf8 =
LISTS:FOLDL (Fun (CHANGE,ACC)->
Case Change of
[Term] When Term >= $a, Term =< $z->
ACC + + change;
[Term] When Term >= $A, Term =< $Z->
ACC + + change;
[Term] When Term >= $, Term =< $->
ACC + + change;
[Term] When Term =:= $. ->
ACC + + change;
[Term] When Term =:= $_->
ACC + + change;
[Term] When Term =:= $-->
ACC + + change;
_->
ACC + + list_to_hex_s (change)
End
End,[],dchanges),
strvalue = Escape_uri (STR0) + + Title_utf8 + + Escape_uri (STR1) + + Des_utf8 + + Escape_uri (STR2),
Md5str = Md5_hex (strvalue),
Sign = "sign=" + + MD5STR,
PostInfo = Apikey + + "&" + + Sign + + "&" + + user_id + + "&"
+ + channel_id + + "&" + + Device_type + + "&" + + Message_type + + "&" + + Messages
+ + "&" + + method + + "&" + + Msg_keys + + "&" + + Push_type + + "&" + + Time,
Timer:sleep (30*1000),
result = Httpc:request (post,{url,[], "application/x-www-form-urlencoded", postinfo},[],[]),
Case result of
{ok,{{"http/1.1", "OK"},_,_}}->
Nothing
_->
Io:format ("Result:~p~n", [result])
End.