Objective
Series article:[Portal]
Bubble feet, write blog, regular life, sleep a good sleep, later will read the book.
Body
Above the two-dimensional code generation, and mobile phone scanning sweep, we are interested to see.
Today we talk about, Baidu Cloud push platform.
Every day thinking about the problem, the problem will only slowly clear. Think about it, and slowly the pattern comes out.
Mode
Push Interactive mode
①② refers to the student community
③ is referring to the teacher
③: Teachers can indicate to the server based on HTTP, prompting the server to operate (push ... And so on) or directly on the web side.
①: Student groups accept push, or view certain notifications directly, or view rich text directly, or click to proceed (③ steps)
②: Students pull data from the server based on HTTP
# #ps: Everyone has a good idea message
Baidu Cloud Push delivery platform
Baidu Cloud push Service related information, mainly consists of two parts:
1. Rapid development using the Push service.
2. Further development and use of Push services.
Android side
- Register Baidu Account, and become Baidu developer;
- To create an app, get API key and Secret key, refer to view app key;
- Download the application example;
- Import the example (Android project) into the Eclipse project;
- Run the sample application;
- Log in to the admin console to send notifications;
- Receive notifications on your phone.
More information: http://developer.baidu.com/wiki/index.php?title=docs/cplat/push/guide
Here are the following:
#API Key: Application identity, server binding and push are used
#Secret key: Apply private key, service-side push
#APP ID: This ID, is an ID, although there is a unique line, temporarily no use
#channel ID: The Push channel ID, which usually corresponds to a single terminal. The same app, which is installed on mobile phone A and phone B, has a different channel ID.
#user ID: The app's user ID, the same user, can have the same app on different terminals. User ID and Channel ID are used together
Service side
Go directly to the code.
PackageSedion.jeffli.wmuitp.util.baidu;ImportCom.baidu.yun.channel.auth.ChannelKeyPair;Importcom.baidu.yun.channel.client.BaiduChannelClient;Importcom.baidu.yun.channel.exception.ChannelClientException;Importcom.baidu.yun.channel.exception.ChannelServerException;Importcom.baidu.yun.channel.model.PushBroadcastMessageRequest;ImportCom.baidu.yun.channel.model.PushBroadcastMessageResponse;Importcom.baidu.yun.channel.model.PushUnicastMessageRequest;ImportCom.baidu.yun.channel.model.PushUnicastMessageResponse;Importcom.baidu.yun.core.log.YunLogEvent;ImportCom.baidu.yun.core.log.YunLogHandler; Public classandroidpushbybaiduhelper{Private StaticString apiKey = "XXX"; Private StaticString secretkey = "XXX"; /*** Initialize *@return */ Private Staticbaiduchannelclient initpushclient () {//1. Set the Apikey/secretkey of the developer platformChannelkeypair pair =NewChannelkeypair (ApiKey, Secretkey); //2. Creating an Baiduchannelclient object instanceBaiduchannelclient channelclient =Newbaiduchannelclient (pair); //3. To learn the details of the interaction, register the Yunloghandler classChannelclient.setchannelloghandler (NewYunloghandler () {@Override Public voidOnhandle (Yunlogevent event) {System.out.println (Event.getmessage ()); } }); returnchannelclient; } /*** Push Broadcast message (message type is pass-through, the developer applies itself to resolve message content) Message_type = 0 (default = 0) *@paramContent Push Contents*/ Public Static voidpushbroadcastmessage (String Content) {baiduchannelclient channelclient=initpushclient (); Try { //4. Create a Request class objectPushbroadcastmessagerequest request =Newpushbroadcastmessagerequest (); Request.setdevicetype (3); //Device_type = 1:web 2:pc 3:android//4:ios 5:wprequest.setmessage (Content); //5. Call the Pushmessage interfacePushbroadcastmessageresponse response =channelclient. Pushbroadcastmessage (Request); //6. Certification Push SuccessSYSTEM.OUT.PRINTLN ("Push amount:" +Response.getsuccessamount ()); } Catch(channelclientexception e) {//Handling Client Error ExceptionsE.printstacktrace (); } Catch(channelserverexception e) {//Handling server-side error exceptionsSystem.out.println (String.Format ("request_id:%d, Error_code:%d, Error_message:%s", E.getrequestid (), E.geterrorcode (), e.geterrormsg ()); } } /*** Push unicast message (message type is pass-through, the developer applies itself to resolve message content) Message_type = 0 (default = 0) *@paramchannelid mobile phone side *@paramContent Push Contents *@paramUserId Phone Side*/ Public Static voidPushmessagesample (String content,Longchannelid,string UserId) {baiduchannelclient channelclient=initpushclient (); Try { //Create a Request class object//mobile phone side of the channelid, cell phone userid, first replaced with 1111111111111, the user needs to replace their ownPushunicastmessagerequest request =Newpushunicastmessagerequest (); Request.setdevicetype (3);//Device_type = 1:web 2:pc 3:android//4:ios 5:wpRequest.setchannelid (Channelid); Request.setuserid (USERID); Request.setmessage (content); //5. Call the Pushmessage interfacePushunicastmessageresponse response =channelclient. Pushunicastmessage (Request); //6. Certification Push SuccessSYSTEM.OUT.PRINTLN ("Push amount:" +Response.getsuccessamount ()); } Catch(channelclientexception e) {//Handling Client Error ExceptionsE.printstacktrace (); } Catch(channelserverexception e) {//Handling server-side error exceptionsSystem.out.println (String.Format ("request_id:%d, Error_code:%d, Error_message:%s", E.getrequestid (), E.geterrorcode (), e.geterrormsg ()); } } }
#初始化
# push Broadcast message (message type is pass through, the developer applies itself to resolve message content) Message_type = 0 (default = 0)
* @param content Push Contents
# Push Unicast message (message type is pass-through, the developer applies itself to resolve message content) Message_type = 0 (default = 0)
* @param channelid Mobile Terminal
* @param content Push Contents
* @param userid Mobile
Summarize
It's a tool class, nothing else. read it, come on, everybody.
Thanks and resource sharing
The road came to step by step, I hope you and I together.
Thanks to the reader! I really like the support you gave me. If you support, click like.
Knowledge Source: Baidu Cloud Platform