MUI集成個推實現消息推送


1.個推官網注冊

2.開發者中心-我的-應用管理,創建應用

3.HBuilder中獲取應用包名,配置到應用里面

4.在應用配置中可以看到AppID,AppSecret,AppKey,MasterSecret信息,把相應的信息填到項目的mainfest.json-sdk配置-個推,然后打包安裝app(配置好的app要安裝才能收到信息)

5.個推官網發送消息測試

6.java集成(可參考文檔,內容足夠詳細)

 

7.app獲取cid: var cid = plus.push.getClientInfo().clientid;

  這樣就可以實現推送消息到指定設備上

   這個加到dependencies

<!-- 個推 -->
        <dependency>
            <groupId>com.gexin.platform</groupId>
            <artifactId>gexin-rp-sdk-http</artifactId>
            <version>4.1.1.0</version>
        </dependency>

  這個加到外面

<!-- 個推 -->
    <repositories>
        <repository>
            <id>getui-nexus</id>
            <url>http://mvn.gt.igexin.com/nexus/content/repositories/releases/</url>
        </repository>
    </repositories>

java代碼

package jt.cab.webapi.utils;

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.NotificationTemplate;
import com.gexin.rp.sdk.template.style.Style0;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AppPushUtil {
    // STEP1:獲取應用基本信息
    private static String appId = "";
    private static String appKey = "";
    private static String masterSecret = "";
    private static String url = "http://sdk.open.api.igexin.com/apiex.htm";

    public static void main(String[] args) throws IOException {

        IGtPush push = new IGtPush(url, appKey, masterSecret);

        Style0 style = new Style0();

        // STEP2:設置推送標題、推送內容(這里會有個問題,可能會中文亂碼,但是從實體中獲取就不存在這里問題了)
        style.setTitle("title");
        style.setText("content");
//        style.setLogo("push.png");  // 設置推送圖標
        // STEP3:設置響鈴、震動等推送效果
        style.setRing(true);  // 設置響鈴
        style.setVibrate(true);  // 設置震動
        //設置通道,根據cid發送,不設置默認所有
        style.setChannel("84e183e7414652a93a92453c6ec4dfac");


        // STEP4:選擇通知模板
        NotificationTemplate template = new NotificationTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setStyle(style);


        // STEP5:定義"AppMessage"類型消息對象,設置推送消息有效期等推送參數
        List<String> appIds = new ArrayList<String>();
        appIds.add(appId);
        AppMessage message = new AppMessage();
        message.setData(template);
        message.setAppIdList(appIds);
        message.setOffline(true);
        message.setOfflineExpireTime(1000 * 600);  // 時間單位為毫秒

        // STEP6:執行推送
        IPushResult ret = push.pushMessageToApp(message);
        System.out.println(ret.getResponse().toString());
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM