Jpush Aurora Push Java Call server-side API development

Source: Internet
Author: User
Tags ssl connection

Aurora Push is : enables developers to instantly push notifications or messages to users of their applications to stay in touch with users, effectively improving retention and improving user experience. Simply put, through the Jpush background management website to push the app message. Allows users to receive the latest message prompt in a timely manner.

However, sometimes it is necessary for us to develop our own background management website to push the function, this time we need to call the API interface provided by Jpush to push the message. Here I only talk about some of the core API interface, the client site there are examples of people can download their own to see.

Here is the code section of the Java backend:

     Public classJpushclientexample {//AppKey and Mastersecret for uploading applications in the Aurora register        Private Static FinalString AppKey = "a148767f7440ff9daf56457f";////required, e.g. 466f7032ac604e02fb7bda89        Private Static FinalString Mastersecret = "731e374afd796d5942ba1363";//required, each application corresponds to a mastersecret        Private StaticJpushclient Jpush =NULL; /** Save the length of time offline. seconds in the unit.          Supports up to 10 days (864,000 seconds). * 0 indicates that the message is not saved offline.          That is, the user is issued immediately online, the current non-online users will not receive this message. * This parameter is not set to default, the default is to save 1 days of offline messages (86,400 seconds*/          Private Static LongtimeToLive = 60 * 60 * 24;  Public Static voidMain (string[] args) {/** Example1: Initialize, default sent to Android and iOS, while setting offline message survival time * Jpush = new Jpushclient (Mastersecret, Appke              Y, timeToLive); * * Example2: Only sent to Android * * Example3: Only sent to iOS * Jpush = new Jpushclient              (Mastersecret, AppKey, Deviceenum.ios); * * Example4: Send only to Android, while setting offline message survival time * Jpush = new Jpushclient (Mastersecret, AppKey, Timetoli              ve, deviceenum.android); */Jpush=Newjpushclient (Mastersecret, AppKey, timeToLive); /** Whether to enable SSL secure connection, optional * parameter: Enable true, disable false, default is non-SSL connection*/Jpush.setenablessl (true); //test Send message or notificationTestsend (); }          Private Static voidTestsend () {//in real business, it is recommended that Sendno be a self-increment number that your own business can handle. //unless you need to overwrite, make sure you don't reuse it.      Please refer to the API documentation for details. //Integer num= Getrandomsendno (); String sendno= "1900192560"; String Msgtitle= "Jpush Test Information"; String msgcontent= "I am jpush test information, has been successfully sent to you, please check." "; /** ios Device extension parameter, * Set badge, set sound*/Map<string, object> extra =NewHashmap<string, object>(); Iosextra Iosextra=NewIosextra (1, "Windowslogonsound.wav"); Extra.put ("Id1", Iosextra); Extra.put ("Id2", "I am extra infomation"); //iOS and Android togetherMessageresult Msgresult = Jpush.sendnotificationwithappkey (Sendno, Msgtitle, msgcontent, 0, extra); //to send notifications to all users, please refer to the documentation for more methods//Messageresult Msgresult = Jpush.sendcustommessagewithappkey (Sendno,msgtitle, msgcontent);             if(NULL!=Msgresult) {System.out.println ("Server returns data:" +msgresult.tostring ()); if(Msgresult.geterrcode () = =ErrorCodeEnum.NOERROR.value ()) {System.out.println ("Send success, sendno=" +Msgresult.getsendno ()); } Else{System.out.println ("Send failed, error code =" + msgresult.geterrcode () + ", error message =" +msgresult.geterrmsg ()); }              } Else{System.out.println ("Unable to get data"); }             }           Public Static Final intMAX =Integer.max_value;  Public Static Final intMIN = (int) MAX/2; /*** Maintaining the uniqueness of sendno is necessary * It is very important to keep Sendno unique. * @returnSendno*/           Public Static intGetrandomsendno () {return(int) (MIN + math.random () * (MAX-MIN)); }      }  

Developers can define their own headers, content, additional information, offline wait time and other messages. Very convenient to use. Here I will add this demo core code. Interested in the entire demo can be downloaded to study.

You are welcome to disturb the program ape disturb communication

Jpush Aurora Push Java Call server-side API development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.