mui+个推 java服务器代码 以及ios踩坑过程

我是一名Android程序员,最近刚入混合的坑,所以此文为小白文,大佬勿入,蟹蟹。

java服务器:先导lib文件,再贴代码;

package com.pushmessage;

import java.util.Date;

/**
 * Created by xy2 on 2017/10/30.
 *  推送的基类
 */
public abstract class PushBase {
    //此参数为测试参数,正式需要屏蔽
    protected static final String APPID = "";
    protected static final String APPKEY = "";
    protected static final String MASTERSECRET = "";
    protected static final String AppSecret = "";   
    protected static final String API = "http://sdk.open.api.igexin.com/apiex.htm";     //OpenService接口地址
    protected static final String CLIENTID = "";
    protected static String getDate(){
        Date date = new Date();
        return date.toLocaleString();
    }
}

第二页:

package com.pushmessage;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.base.uitls.AppConditions;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.LinkTemplate;
import com.gexin.rp.sdk.template.style.Style0;

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

/**
 * Created by xy2 on 2017/10/30.
 * 通知栏消息单人通知
 */
public class AppPush extends PushBase {
    static String host = "http://sdk.open.api.igexin.com/apiex.htm";

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

            IGtPush push = new IGtPush(host, APPKEY, MASTERSECRET);

            LinkTemplate template = linkTemplateDemo();
            AppMessage message = new AppMessage();
            message.setData(template);

            message.setOffline(true);
            //离线有效时间,单位为毫秒,可选
            message.setOfflineExpireTime(24 * 1000 * 3600);
            //推送给App的目标用户需要满足的条件
            AppConditions cdt = new AppConditions();
            List<String> appIdList = new ArrayList<String>();
            appIdList.add(APPID);
            message.setAppIdList(appIdList);
            //手机类型
            List<String> phoneTypeList = new ArrayList<String>();
            //省份
            List<String> provinceList = new ArrayList<String>();
            //自定义tag
            List<String> tagList = new ArrayList<String>();

            cdt.addCondition(AppConditions.PHONE_TYPE, phoneTypeList);
            cdt.addCondition(AppConditions.REGION, provinceList);
            cdt.addCondition(AppConditions.TAG,tagList);
            message.setConditions(cdt);

            IPushResult ret = push.pushMessageToApp(message,"任务别名_toApp");
            System.out.println(ret.getResponse().toString());
            System.out.println("1111");
        }

    public static LinkTemplate linkTemplateDemo() throws Exception {
        LinkTemplate template = new LinkTemplate();
        template.setAppId(APPID);
        template.setAppkey(APPKEY);

        Style0 style = new Style0();
        // 设置通知栏标题与内容
        style.setTitle("请输入通知栏标题");
        style.setText("请输入通知栏内容");
        // 配置通知栏图标
        style.setLogo("icon.png");
        // 配置通知栏网络图标
        style.setLogoUrl("");
        // 设置通知是否响铃,震动,或者可清除
        style.setRing(true);
        style.setVibrate(true);
        style.setClearable(true);
        template.setStyle(style);

        template.setUrl("http://www.baidu.com");

        return template;
    }
}

第三页:

package com.pushmessage;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.base.uitls.AppConditions;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.LinkTemplate;
import com.gexin.rp.sdk.template.style.Style0;

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

/**
 * Created by xy2 on 2017/10/30.
 * 通知栏消息单人通知
 */
public class AppPush extends PushBase {
    static String host = "http://sdk.open.api.igexin.com/apiex.htm";

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

            IGtPush push = new IGtPush(host, APPKEY, MASTERSECRET);

            LinkTemplate template = linkTemplateDemo();
            AppMessage message = new AppMessage();
            message.setData(template);

            message.setOffline(true);
            //离线有效时间,单位为毫秒,可选
            message.setOfflineExpireTime(24 * 1000 * 3600);
            //推送给App的目标用户需要满足的条件
            AppConditions cdt = new AppConditions();
            List<String> appIdList = new ArrayList<String>();
            appIdList.add(APPID);
            message.setAppIdList(appIdList);
            //手机类型
            List<String> phoneTypeList = new ArrayList<String>();
            //省份
            List<String> provinceList = new ArrayList<String>();
            //自定义tag
            List<String> tagList = new ArrayList<String>();

            cdt.addCondition(AppConditions.PHONE_TYPE, phoneTypeList);
            cdt.addCondition(AppConditions.REGION, provinceList);
            cdt.addCondition(AppConditions.TAG,tagList);
            message.setConditions(cdt);

            IPushResult ret = push.pushMessageToApp(message,"任务别名_toApp");
            System.out.println(ret.getResponse().toString());
            System.out.println("1111");
        }

    public static LinkTemplate linkTemplateDemo() throws Exception {
        LinkTemplate template = new LinkTemplate();
        template.setAppId(APPID);
        template.setAppkey(APPKEY);

        Style0 style = new Style0();
        // 设置通知栏标题与内容
        style.setTitle("请输入通知栏标题");
        style.setText("请输入通知栏内容");
        // 配置通知栏图标
        style.setLogo("icon.png");
        // 配置通知栏网络图标
        style.setLogoUrl("");
        // 设置通知是否响铃,震动,或者可清除
        style.setRing(true);
        style.setVibrate(true);
        style.setClearable(true);
        template.setStyle(style);

        template.setUrl("http://www.baidu.com");

        return template;
    }
}

第四页:

package com.pushmessage;

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;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xy2 on 2017/10/30.
 * Android/ios通知栏消息 多人通知
 */
public class PushMessageToList 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();
        }
    }
}

第五页:

package com.pushmessage;

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;

/**
 * Created by xy2 on 2017/10/30.
 * Android 通知栏消息 自定义样式
 */
public class PushMessageToSingleDetail 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();
        }
    }
}

以上代码百度一下,也是会有的。

开始讲解踩坑内容
1.android:就很简单了,我们混合Android是用hblider写以及打包,只需要在mamifast里SDK配置选择plus.push点√,放入个推申请号的参数。个推操作传送门。至此Android配置完成,正常推送没问题
获取clientID:
var vInfo = plus.push.getClientInfo();
alert(JSON.stringify(vInfo));
2.ios:因为是混合开发啊,所以我们没有直接用hbulider打包,而是取了一个ios的框,所以还是需要配置ios的,直接给传送门告诉你都有什么坑就行了。

ios1:需要配置p12签名文件,不知道为什么ios有四个签名,重新签名也不影响什么,无语ing,但是四个账号出自一个appid。初始配置允许推送
ios2:继续配置,xcode配置1Xcode配置2;两篇内容差不多,能看懂就行。配置3
ios3:appiderror这是服务器报的错,就是说以上都配置完之后,运行没问题但是会报错,错误原因clientID错误,需要卸载,打包,重新安装再获取就改变clientID了。所以上边的配置3一定要配置好。

话不多说。基本就能用了。不能用就请仔细阅读开发文档。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值