Aurora pushes the latest old convulsions, and then the push scheme changes again, this time to bring you Ali's mobile Push Server API:
The first is the introduction of dependency
<dependency> <groupId>com.aliyun</groupId> <artifactid>aliyun-java-sdk-push </artifactId> <version>2.2. 4</version> </dependency> <dependency> <groupid>com.aliyun</ groupid> <artifactId>aliyun-java-sdk-core</artifactId> <version>2.4. 2</version> </dependency>
Then the usual, after extracting the code untils
Package Com.commons.utils;import Java.util.date;import com.aliyuncs.defaultacsclient;import Com.aliyuncs.exceptions.clientexception;import Com.aliyuncs.exceptions.serverexception;import Com.aliyuncs.http.methodtype;import Com.aliyuncs.profile.defaultprofile;import Com.aliyuncs.profile.iclientprofile;import Com.aliyuncs.push.model.v20150827.cancelpushrequest;import Com.aliyuncs.push.model.v20150827.cancelpushresponse;import com.aliyuncs.push.model.v20150827.PushRequest; Import Com.aliyuncs.push.model.v20150827.pushresponse;import Com.aliyuncs.utils.parameterhelper;import Com.ecp.commons.api.apiconstants;import Com.ecp.commons.utils.JsonUtil; Public classJpushutils { Public StaticFinal String AppKey = Com.ecp.commons.common.PropertiesUtil.getProperty ("Push.appkey"); Public StaticFinal String Appsecret = Com.ecp.commons.common.PropertiesUtil.getProperty ("Push.appsecret"); Public StaticFinal String Accesskeyid = Com.ecp.commons.common.PropertiesUtil.getProperty ("Push.accesskeyid"); Public StaticFinal String Accesssecret = Com.ecp.commons.common.PropertiesUtil.getProperty ("Push.secret"); /** * * @auth Ren * @date May 2, 2018 * @decripe: Pushes the JSON string of the Obj object onto the device with the alias DEVICESN, while recording the returned msg_id * @par Am obj Push object, DEVICESN device identification code, MSGTYPE push business type (defined in apiconstants)*/ Public Staticpushresponse sendpush (Object obj, string devicesn, String msgtype) throws Exception {Pushrequest pushrequest =Newpushrequest (); Pushrequest.setmethod (Methodtype.post); Pushrequest.setappkey (long.valueof (AppKey)); Pushrequest.setdevicetype (1); Pushrequest.settarget ("alias"); Pushrequest.settargetvalue (DEVICESN); Pushrequest.settype (0);//0: Indicates a message (default is 0), 1: Indicates notificationPushrequest.settitle (Msgtype);//the title of the messagePushrequest.setbody (Objecttojson (obj));//content of the messageIclientprofile profile =defaultprofile.getprofile (Apiconstants.region_hangzhou, Accesskeyid, Accesssecret); Defaultacsclient Client=Newdefaultacsclient (profile); Pushresponse Pushresponse=Client.getacsresponse (pushrequest); System. out. printf ("RequestID:%s, Responseid:%s\n", Pushresponse.getrequestid (), Pushresponse.getresponseid ()); returnPushresponse; } /** * * @auth Ren * @date June 6, 2018 * @decripe: Push all * @param obj push objects, Msgtype push business type (apiconstants Righteousness)*/ Public Staticpushresponse Sendpush (Object obj,string msgtype) throws Exception {pushrequest pushrequest=Newpushrequest (); Pushrequest.setmethod (Methodtype.post); Pushrequest.setappkey (long.valueof (AppKey)); Pushrequest.setdevicetype (1); Pushrequest.settarget (" All"); Pushrequest.settargetvalue (" All"); Pushrequest.settype (0);//0: Indicates a message (default is 0), 1: Indicates notificationPushrequest.settitle (Msgtype);//the title of the messagePushrequest.setbody (Objecttojson (obj));//content of the messageIclientprofile profile =defaultprofile.getprofile (Apiconstants.region_hangzhou, Accesskeyid, Accesssecret); Defaultacsclient Client=Newdefaultacsclient (profile); Pushresponse Pushresponse=Client.getacsresponse (pushrequest); System. out. printf ("RequestID:%s, Responseid:%s\n", Pushresponse.getrequestid (), Pushresponse.getresponseid ()); returnPushresponse; } /** * * @auth Ren * @date June 6, 2018 * @decripe: Timed push all * @param obj Push object, Msgtype push business type (apiconstants Righteousness)*/ Public Staticpushresponse sendschedulepushall (Object obj, Date pushtime, String msgtype) throws Exception {Iclientprofile profile=defaultprofile.getprofile (Apiconstants.region_hangzhou, Accesskeyid, Accesssecret); Defaultacsclient Client=Newdefaultacsclient (profile); Pushrequest pushrequest=Newpushrequest (); Pushrequest.setmethod (Methodtype.post); Pushrequest.setappkey (long.valueof (AppKey)); Pushrequest.setdevicetype (1); Pushrequest.settarget (" All"); Pushrequest.settargetvalue (" All"); Pushrequest.settype (0);//0: Indicates a message (default is 0), 1: Indicates notificationPushrequest.settitle (Msgtype);//the title of the messagePushrequest.setbody (Objecttojson (obj));//content of the messageString Pushtime =Parameterhelper.getiso8601time (pushtime); Pushrequest.setpushtime (Pushtime); Pushresponse Pushresponse=Client.getacsresponse (pushrequest); System. out. printf ("RequestID:%s, Responseid:%s\n", Pushresponse.getrequestid (), Pushresponse.getresponseid ()); returnPushresponse; } /** * * @auth Ren * @date June 6, 2018 * @decripe time to push a specified device*/ Public Staticpushresponse sendschedulepush (Object obj, string devicesn, Date pushtime, String msgtype) throws exception{IC Lientprofile Profile=defaultprofile.getprofile (Apiconstants.region_hangzhou, Accesskeyid, Accesssecret); Defaultacsclient Client=Newdefaultacsclient (profile); Pushrequest pushrequest=Newpushrequest (); Pushrequest.setmethod (Methodtype.post); Pushrequest.setappkey (long.valueof (AppKey)); Pushrequest.setdevicetype (1); Pushrequest.settarget ("alias"); Pushrequest.settargetvalue (DEVICESN); Pushrequest.settype (0);//0: Indicates a message (default is 0), 1: Indicates notificationPushrequest.settitle (Msgtype);//the title of the messagePushrequest.setbody (Objecttojson (obj));//content of the messageString Pushtime =Parameterhelper.getiso8601time (pushtime); Pushrequest.setpushtime (Pushtime); Pushresponse Pushresponse=Client.getacsresponse (pushrequest); System. out. printf ("RequestID:%s, Responseid:%s\n", Pushresponse.getrequestid (), Pushresponse.getresponseid ()); returnPushresponse; } /** * Cancel timed push * <p> *//*/ Public voidTestcancelpush (String Responseid) throws Exception {Cancelpushrequest request=Newcancelpushrequest (); Request.setappkey (long.valueof (AppKey)); Request.setmessageid (Responseid);//the Responseid that is returned when the push is sent. Iclientprofile profile =defaultprofile.getprofile (Apiconstants.region_hangzhou, Accesskeyid, Accesssecret); Defaultacsclient Client=Newdefaultacsclient (profile); Cancelpushresponse Response=Client.getacsresponse (Request); System. out. println (Response.getrequestid ()); } Public Staticstring Objecttojson (Object o) {string json= Jsonutil.getjsonstring4javapojo (O,"YYYY-MM-DD HH:mm:ss"); returnJSON; }}
Alibaba Mobile Push Server API