Jpush How to use httpclient to push messages to your phone

Source: Internet
Author: User

Have a nice smile

"1. Push me again, force me to pretend to be dead to you."
2. I will not tell you that you have not made the beauty count.
3. The handsome has a P use, not to be eaten by pawn.
4. Don't worry, I'm not a good person.
5. If you can't reach it, try it on your right foot with your left foot.
Just to make you smile.

Ask questions

How the backend uses Jpush Aurora to push messages to the phone???

solve the problem Jpush Aurora Document official website

http://docs.jiguang.cn/jpush/guideline/intro/

Jpush Product Brief

Jpush is a tested, large-scale app push platform that pushes more than 500 million messages per day. After the developer integrates the SDK, you can push the message by invoking the API. At the same time, Jpush provides a visual Web-side console to send notifications, statistical analysis of the push effect. Jpush full support Android, IOS, winphone three mobile platforms

Jpush Back-end development data

This is the data document that Jpush needs to see when pushing messages to the mobile phone.
http://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/

Jpush Back-end development examples Call Address

In fact, we just use HttpClient to send a POST request to the following path.

Https://api.jpush.cn/v3/push (important)

the requested data format is
{   "platform": "all",   "audience" : "all",   "notification" : {      "alert" : "Hi, JPush!",      "android" : {},       "ios" : {         "extras" : { "newsid" : 321}      }   }}//调用时,需要的一些认证信息,这里需要自己到Jpush上去注册获取认证信息Authorization: Basic N2Q0MzFlNDJkZmE2YTZkNjkzYWMyZDA0OjVlOTg3YWM2ZDJlMDRkOTVhOWQ4ZjBkMQ==

Return Example

After the call succeeds, the following information is returned:

< HTTP/1.1 200 OK< Content-Type: application/json{"sendno":"18","msg_id":"1828256757"}
Back-end code
Package com.evada.de.projcommand.utils;/** * Description: Mobile-side message Push Tool class * Created by Ay on 2017/4/17. */public class Pcshttpclientutil {/** requested URL path **/public static final String Jpush_url = "Https://api.jpush.cn/v3    /push ";    /** character encoding **/private static final String CHARSET = "Utf-8"; /** Authentication password **/private static final String AUTH = "Basic mzrizmu5nwrjymyxmjhhnzfjmmm2yze4omq4ngvhzjzkowi3yjy1njuwzdaxodbl    yg== "; /** * Description: Send POST request * @return */public static String DoPost (map<sysuser,list<pcssubtaskdto>> use        Rlistmap, String ActionType, Pcstask pcstask) {HttpClient HttpClient = null;        HttpPost httppost = null;        String result = null;            try{httpClient = new Defaulthttpclient ();            HttpPost = new HttpPost (Jpush_url);            Set up authentication information Httppost.setheader ("Authorization", AUTH); For (Sysuser SysUser:userListMap.keySet ()) {Jsonobject Msgobject = getrequestcontent (Userlistmap.get (sysusER), sysuser,actiontype,pcstask);                stringentity entity = new Stringentity (msgobject.tostring (), "utf-8");                Entity.setcontenttype ("Application/json");                Httppost.setentity (entity);                Execution Request HttpResponse response = Httpclient.execute (HttpPost);                    if (response! = null) {httpentity resentity = response.getentity ();                    if (resentity! = null) {result = Entityutils.tostring (Resentity,charset);        }}}}catch (IOException e) {e.printstacktrace ();    } return result; } private static Jsonobject getrequestcontent (list<pcssubtaskdto> pcssubtaskdtolist,sysuser sysUser,String        Actiontype,pcstask pcstask) {jsonobject msgobject = new Jsonobject ();        Msgobject.put ("platform", "all");        Msgobject.put ("Audience", Getuseraccountarray (Sysuser)); Msgobject.put ("NotifiCation ", GetNotification (Pcssubtaskdtolist,actiontype,pcstask));        Jsonobject Optionsjson = new Jsonobject ();        Optionsjson.put ("Apns_production", false);        Msgobject.put ("Options", Optionsjson);    return msgobject; } private static Jsonobject getnotification (list<pcssubtaskdto> pcssubtaskdtolist,string ActionType, PcsTask PCs        Task) {jsonobject result = new Jsonobject ();        StringBuilder msg = new StringBuilder (); If task deliver if (TaskMsgTypeEnum.TASK_ISSUE_NOTICE.toString () equals (ActionType)) {Msg.append ("" task issued Notification ""). Append ("Hello,"). Append (Sessionutils.getcurrentuser (). GetName ()). Append ("task:"). Append ( Pcstask.getname ()). Append ("-"). Append (Pcstask.getcode ()). Append ("issued.            Please sign in time to handle your task: \ n "); for (Pcssubtaskdto pcssubtaskdto:pcssubtaskdtolist) {msg.append (Pcssubtaskdto.getcode ()). Append ("-"). Append ( Pcssubtaskdto.getname ()). Append (", scheduled start time:"). Append (New DateTime (Pcssubtaskdto.getplanstarttime ()). ToString ("dd-mm-yyyy HH:mm:ss")). Append ("\ n"); }}else{Msg.append ("Task Collection Notification"). Append ("Hello,"). Append (Sessionutils.getcurrentuser (). GetName ()). Append ("task:"). Append (Pcstask.getname ()). Append ("-"). Append (Pcstask.getcode ()). The collection.            You also have the following tasks not completed: \ n "); for (Pcssubtaskdto pcssubtaskdto:pcssubtaskdtolist) {msg.append (Pcssubtaskdto.getcode ()). Append ("-"). Append ( Pcssubtaskdto.getname ()). Append (", Scheduled time to finish:"). Append (New DateTime (Pcssubtaskdto.getplancompletetime (            ). ToString ("dd-mm-yyyy HH:mm:ss")). Append ("\ n");        }} result.put ("Alert", msg.tostring ());        Jsonobject badge = new Jsonobject ();        Badge.put ("badge", "+1");        Result.put ("ios", badge);    return result; /** * Description: Get user account * @param sysuser user * @return * */private static Jsonobject Getuseraccountarray (Sysuser sysuser) {jsonobject result = new Jsonobject ();        Jsonarray Accountarray = new Jsonarray ();        Accountarray.add (Sysuser.getaccount ());        Alias Result.put ("Alias", Accountarray);    return result; }}
Reading Comprehension

From the noise and the commotion

    • Any one who is alive is better than a dead man. But no one alive is better than the one who lives.
    • Man is nothing but the sum of its misfortunes. You think that one day you will be bored, but by then, time has become your misfortune.
    • People live in a dream, where you run, but you can't leave a fear that you can't believe, you're running into a safe place, you don't have faith in it.
Classic Story

 
"There is such a story: The old patriarch led the villagers to travelled day, to transport salt to a place for winter barley." One night, they slept in the wilderness and the stars were shining. The elders still use the method of ancestral generation, take out three pieces of salt into the bonfire, divination the change of weather between the mountain ... Everyone is waiting for the "weather forecast" of the Elders: if you hear a "crackling" sound from the salt in the fire, it is a harbinger of good weather, and if it is silent, it symbolizes that the weather is about to turn bad, and that the storm will come at any moment. The elder looked solemn, for the salt-block was silent in the fire. He thought ominous, and advocated to hurry after daybreak. But another young man in the clan thought that "to peep the day with salt" was superstition and opposed a hasty departure. The next afternoon, sure enough, the weather was abrupt and wintry, and the young man who insisted on the late walk realized the wisdom of the Elder. In fact, with today's scientific explanation, the old patriarch is also right, the salt block in the fire whether the sound, and the humidity in the air related. In other words, when the wind and rain desire to come, high humidity, salt blocks damp, into the fire naturally dumb silent. Young people tend to look down on the old man's philosophy, one-sided thinking that they are obsolete and useless. In fact, some life philosophy like sea salt, it is old, still is a crystallization, and has the memory of the sea. 】

Great God article

"1" httpclient send get POST request and data parsing
"2" Easy HttpClient Demo POST request example
Understanding of "3" Jpush Aurora push
Simple use of "4" Jpush message push

other

If there is a little bit of happiness for you, let happiness continue to pass, welcome to praise, top, welcome to leave valuable comments, thank you for your support!

Jpush How to use httpclient to push messages to your phone

Related Article

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.