個推 APP推送

個推的做用:能夠爲手機端的app使用者推送消息,而不是經過手機上的app對用戶發送消息。因此用戶是被動的接收信息。固然不僅是隻有對用戶彈出 窗口的這種方式,也能夠把信息推送給app,讓app決定對用戶實行怎麼樣的操做,例如在app的欄目中顯示出有新信息的圖標,以便提升用戶體驗。java

個推的官網http://www.igetui.com/android

該api支持Android和iso的推送。api

下載個推的sdk,裏面有各類不一樣文檔,其中有android的apk的安裝文件,能夠進行推送的測試。app

/** 
 * 推送的基類 
 * @author admin
 */  
public abstract class PushBase {  
      
    protected static final String APPID = "b03c5cfef65ed30108f0a3fd82c3f6b4";  
    protected static final String APPKEY = "110000";  
    protected static final String MASTERSECRET = "a02a76119b20d4e31620d7597a3b4f35";  
    protected static final String CLIENTID = "f8b14fc288a21bc3d675190e9a4db0a4";  
    protected static final String API = "http://sdk.open.api.igexin.com/apiex.htm";     //OpenService接口地址  
      
    protected static String getDate(){  
        Date date = new Date();  
        return date.toLocaleString();  
    }  
}  


import java.util.ArrayList;  
import java.util.List;  
import com.gexin.rp.sdk.base.IIGtPush;  
import com.gexin.rp.sdk.base.IPushResult;  
import com.gexin.rp.sdk.base.impl.AppMessage;  
import com.gexin.rp.sdk.http.IGtPush;  
import com.gexin.rp.sdk.template.LinkTemplate;  
  /**
  *對多個app進行推送
  **/
public class PushMessageToAppTest extends PushBase{  
  
    public static void main(String[] args) {  
  
        // 推送主類  
        IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);  
  
        try {  
  
            AppMessage message = new AppMessage();  
  
            //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此處以LinkTemplate爲例  
            //在通知欄顯示一條含圖標、標題等的通知,用戶點擊可打開您指定的網頁  
            LinkTemplate template = new LinkTemplate();  
              
            template.setAppId(APPID);                               //應用APPID  
            template.setAppkey(APPKEY);                         //應用APPKEY  
              
            //通知屬性設置:如通知的標題,內容  
            template.setTitle("填寫通知標題");                        // 通知標題  
            template.setText("填寫通知內容");                 // 通知內容  
            template.setLogo("hello.png");  
//          template.setIsRing(true);                   // 收到通知是否響鈴,可選,默認響鈴  
//          template.setIsVibrate(true);                    // 收到通知是否震動,可選,默認振動  
//          template.setIsClearable(true);              // 通知是否可清除,可選,默承認清除  
            template.setUrl("http://baidu.com");        //點擊通知後打開的網頁地址,你能夠設定你但願跳轉的網頁地址如http://www.igetui.com  
  
            message.setData(template);  
//          message.setOffline(true);       //用戶當前不在線時,是否離線存儲,可選,默認不存儲  
//          message.setOfflineExpireTime(72 * 3600 * 1000);     //離線有效時間,單位爲毫秒,可選  
  
            List<String> appIdList = new ArrayList<String>();  
            appIdList.add(APPID);  
  
            List<String> phoneTypeList = new ArrayList<String>();//通知接收者的手機操做系統類型,可選  
            phoneTypeList.add("ANDROID");  
  
            List<String> provinceList = new ArrayList<String>();        //通知接收者所在省份,可選  
            provinceList.add("浙江");  
            provinceList.add("上海");  
            provinceList.add("北京");  
              
            List<String> tagList = new ArrayList<String>();         //通知接收者的標籤用戶,可選  
            tagList.add("填寫tags名稱");  
  
            message.setAppIdList(appIdList);                  
            message.setPhoneTypeList(phoneTypeList);  
            message.setProvinceList(null);  
            message.setTagList(null);  
  
            IPushResult ret = push.pushMessageToApp(message);     
  
            System.out.println(ret.getResponse().toString());  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
}  

/**  對單個app的多個用戶進行推送:  **/


import java.util.ArrayList;  
import java.util.List;  
import com.gexin.rp.sdk.base.IIGtPush;  
import com.gexin.rp.sdk.base.IPushResult;  
import com.gexin.rp.sdk.base.impl.ListMessage;  
import com.gexin.rp.sdk.base.impl.Target;  
import com.gexin.rp.sdk.http.IGtPush;  
import com.gexin.rp.sdk.template.NotificationTemplate;  
  
//可接收多個用戶,最多爲50個  
public class PushMessageToListTest extends PushBase{  
  
    public static void main(String[] args) {  
        //顯示每一個用戶的用戶狀態,false:不顯示,true:顯示  
        System.setProperty("gexin.rp.sdk.pushlist.needDetails", "true");  
  
        // 推送主類  
        IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);  
  
        try {  
            ListMessage message = new ListMessage();  
  
            //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此處以NotificationTemplate爲例  
            //在通知欄顯示一條含圖標、標題等的通知,用戶點擊後激活您的應用  
            NotificationTemplate template = new NotificationTemplate();  
  
            template.setAppId(APPID);                           //應用APPID  
            template.setAppkey(APPKEY);                         //應用APPKEY  
              
            //通知屬性設置:如通知的標題,內容  
            template.setTitle("此處填寫通知標題"+getDate());                    // 通知標題  
            template.setText("此處填寫通知內容"+getDate());                 // 通知內容  
            template.setLogo("push.png");               // 通知圖標,須要客戶端開發時嵌入  
            template.setIsRing(false);                  // 收到通知是否響鈴,可選,默認響鈴  
//          template.setIsVibrate(true);                    // 收到通知是否震動,可選,默認振動  
            template.setIsClearable(true);              // 通知是否可清除,可選,默承認清除  
              
            template.setTransmissionType(2);                // 收到消息是否當即啓動應用,1爲當即啓動,2則廣播等待客戶端自啓動  
            template.setTransmissionContent("你須要透傳的內容"+getDate());  // 透傳內容(點擊通知後SDK將透傳內容傳給你的客戶端,須要客戶端作相應開發)  
  
            message.setData(template);  
//          message.setOffline(true);       //用戶當前不在線時,是否離線存儲,可選,默認不存儲  
//          message.setOfflineExpireTime(72 * 3600 * 1000);     //離線有效時間,單位爲毫秒,可選  
  
            // 接收者  
            List<Target> targets = new ArrayList<Target>();  
            Target target1 = new Target();  
//          Target target2 = new Target();                      //若是須要可設置多個接收者  
            target1.setAppId(APPID);                            //接收者安裝的應用的APPID  
            target1.setClientId(CLIENTID);                      //接收者的ClientID  
  
            //如需,可設置多個接收者  
//          target2.setAppId(APPID2);                           //接收者2安裝應用的APPID  
//          target2.setClientId(CLIENTID2);                     //接收者2的ClientID  
  
            targets.add(target1);  
//          targets.add(target2);  
  
            //推送前經過該接口申請「ContentID」  
            String contentId = push.getContentId(message);    
            IPushResult ret = push.pushMessageToList(contentId, targets);  
   
            System.out.println(ret.getResponse().toString());  
        } catch (Exception e) {  
                e.printStackTrace();  
        }  
    }  
}  


/**對單個app的單個用戶進行推送**/
mport com.gexin.rp.sdk.base.IIGtPush;  
import com.gexin.rp.sdk.base.IPushResult;  
import com.gexin.rp.sdk.base.impl.SingleMessage;  
import com.gexin.rp.sdk.base.impl.Target;  
import com.gexin.rp.sdk.http.IGtPush;  
import com.gexin.rp.sdk.template.TransmissionTemplate;  
//對單個用戶推送  
public class PushMessageToSingleTest extends PushBase{  
      
  
    public static void main(String[] args) {  
        // 推送主類  
        IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);  
  
        try {         
            //單推消息類型   
            SingleMessage message = new SingleMessage();  
  
            //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此處以TransmissionTemplate爲例  
            //數據經SDK傳給您的客戶端,由您寫代碼決定如何處理展示給用戶  
            TransmissionTemplate template = new TransmissionTemplate();//透傳方式  
            template.setAppId(APPID);  
            template.setAppkey(APPKEY);  
            template.setTransmissionContent("您須要透傳的內容:"+getDate());  
              
            //收到消息是否當即啓動應用,1爲當即啓動,2則廣播等待客戶端自啓動  
            template.setTransmissionType(1);                      
  
            message.setData(template);  
//          message.setOffline(true);                   //用戶當前不在線時,是否離線存儲,可選  
//          message.setOfflineExpireTime(72 * 3600 * 1000); //離線有效時間,單位爲毫秒,可選  
              
            Target target1 = new Target();  
            target1.setAppId(APPID);  
            target1.setClientId(CLIENTID);  
  
            //單推  
            IPushResult ret = push.pushMessageToSingle(message, target1);  
                          
            System.out.println(ret.getResponse().toString());  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
}  





import com.gexin.rp.sdk.base.IIGtPush;  
import com.gexin.rp.sdk.base.IPushResult;  
import com.gexin.rp.sdk.base.impl.SingleMessage;  
import com.gexin.rp.sdk.base.impl.Target;  
import com.gexin.rp.sdk.http.IGtPush;  
import com.gexin.rp.sdk.template.NotyPopLoadTemplate;  
  
public class PushMessageToSingleTest1 extends PushBase{  
  
    public static void main(String[] args) {  
        // 推送主類  
        IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);  
  
        try {  
  
            // 單推消息類型  
            SingleMessage message = new SingleMessage();  
  
            //通知欄彈框下載模版  
            //在通知欄顯示一條含圖標、標題等的通知,用戶點擊後彈出框,用戶能夠選擇直接下載應用或者取消下載應用。  
            NotyPopLoadTemplate template = new NotyPopLoadTemplate();  
            // 是否激活  
            template.setActived(true);  
            // 安卓標識  
            template.setAndroidMark("android_mark");  
            template.setAppId(APPID);  
            template.setAppkey(APPKEY);  
            // 是否自動安裝  
            template.setAutoInstall(true);  
            // 是否響鈴  
            template.setBelled(true);  
            // 通知是否可清除  
            template.setCleared(true);  
            // 蘋果標識  
            template.setIphoneMark("iphone_mark");  
            // 下載圖標  
            template.setLoadIcon("");  
            // 下載標題  
            template.setLoadTitle("LoadTitle");  
            // 下載地址  
            template.setLoadUrl("http://dizhensubao.igexin.com/dl/com.ceic.apk");  
            // 通知欄內容  
            template.setNotyContent("NotyContent");  
            // 通知欄圖標  
            template.setNotyIcon("");  
            // 通知欄標題  
            template.setNotyTitle("NotyTitle");  
            // 左側按鈕名稱  
            template.setPopButton1("下載");  
            // 右側按鈕名稱  
            template.setPopButton2("取消");  
            // 彈框內容  
            template.setPopContent("popContent");  
            // 彈框圖標  
            template.setPopImage("");  
            // 彈框標題  
            template.setPopTitle("PopTitle");  
            // 塞班標識  
            template.setSymbianMark("symbian_mark");  
            // 是否震動  
            template.setVibrationed(true);  
            message.setData(template);  
            message.setOffline(true);  
            message.setOfflineExpireTime(72 * 3600 * 1000);  
            // 設置優先級  
            message.setPriority(1);  
  
            Target target1 = new Target();  
            target1.setAppId(APPID);  
            target1.setClientId(CLIENTID);  
            // 單推  
            IPushResult ret = push.pushMessageToSingle(message, target1);  
            System.out.println(ret.getResponse().toString());  
        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
    }  
}
相關文章
相關標籤/搜索