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());
    }
}
原文地址:https://www.cnblogs.com/zhouheblog/p/12624684.html