文档开发者中心
我的

新版华为推送消息到客户端,不能触发onEvent的回调是为啥

集成了好几个推送平台的服务了,唯一就华为的文档支持最不给力,混乱
服务短按下面的格式发了推送消息到客户端,客户端能展示消息通知,但点击后没有触发onEvent的回调
有没有人告诉我这是为什么啊!!!!!
我用华为开发者后台的网页取发送消息通知的话客户端是可以触发onEvent回调的。
有没有人能告诉我这是为什么??????
{
    "hps":{
        "msg":{
            "type":3,
            "action":{
                "type":1,
                "param":{
                    "appPkgName":"**********",
                    "push_type":"好友上线",
                    "push_id":"150519041111519360",
                    "url":"******",
                    "intent":"#Intent;compo=com.ceshi.flashchat/.app.SplashActivity;S.W=U;end"
                }
            },
            "body":{
                "title":"测试标题",
                "content":"测试用户 上线了,快去活捉TA!"
            }
        }
    }
}

点赞
收藏
回复
4
分享
举报
浏览3113 发布于2017-09-18 03:12未知归属地
全部评论
最多点赞
最新发布
最早发布
以下为修改后的官网示例代码,注意红色部分。   

//发送Push消息
    private void sendPushMessage(int IsPassThrough,String packageName,String appSecret,String appId,
       List regIdList,String title, String content) throws IOException{
        if (tokenExpiredTime <= System.currentTimeMillis()){
            refreshToken(appSecret,appId);
        }
        JSONArray deviceTokens = new JSONArray();//目标设备Token
        if(regIdList != null){
            for (int i=0;i                 deviceTokens.add(regIdList.get(i));
            }
        }
        JSONObject body = new JSONObject();//仅通知栏消息需要设置标题和内容,透传消息key和value为用户自定义
        body.put("title",title);//消息标题
        body.put("content",content);//消息内容体

        JSONObject param = new JSONObject();
        param.put("appPkgName",packageName);//定义需要打开的appPkgName

        JSONObject action = new JSONObject();
        action.put("type", 3);//类型3为打开APP,其他行为请参考接口文档设置
        action.put("param", param);//消息点击动作参数

        JSONObject msg = new JSONObject();
        msg.put("type", IsPassThrough);//1:透传异步消息,3:通知栏消息
        msg.put("action", action);//消息点击动作
        msg.put("body", body);//通知栏消息body内容

        JSONObject ext = new JSONObject();//扩展信息,含BI消息统计,特定展示风格,消息折叠。
        ext.put("biTag", "Trump");//设置消息标签,如果带了这个标签,会在回执中推送给CP用于检测某种类型消息的到达率和状态
        ext.put("icon", "");//自定义推送消息在通知栏的图标,value为一个公网可以访问的URL
        JSONArray  mCustomizes = new JSONArray();
        JSONObject customize = new JSONObject();
        customize.put("pushNotifyId","6000");
        mCustomizes.add(customize);
        ext.put("customize",mCustomizes);

        JSONObject hps = new JSONObject();//华为PUSH消息总结构体
        hps.put("msg", msg);
        hps.put("ext", ext);
        System.out.print("hps.toString() = " + hps.toString());
        JSONObject payload = new JSONObject();
        payload.put("hps", hps);
        String postBody = MessageFormat.format(
                "access_token={0}&nsp_svc={1}&nsp_ts={2}&device_token_list={3}&payload={4}",
                URLEncoder.encode(accessToken,"UTF-8"),
                URLEncoder.encode("openpush.message.api.send","UTF-8"),
                URLEncoder.encode(String.valueOf(System.currentTimeMillis() / 1000),"UTF-8"),
                URLEncoder.encode(deviceTokens.toString(),"UTF-8"),
                URLEncoder.encode(payload.toString(),"UTF-8"));

        String postUrl = apiUrl + "?nsp_ctx=" + URLEncoder.encode("{\"ver\":\"1\", \"appId\":\"" + appId + "\"}", "UTF-8");
        httpPost(postUrl, postBody, 5000, 5000);
    }
展开全部
4楼回复于2018-05-22 09:14 未知归属地
为什么没人搭理
3楼回复于2017-09-27 07:45 未知归属地
怎么没人搭理啊
2楼回复于2017-09-19 09:54 未知归属地
有华为的人能给点指导么?
1楼回复于2017-09-18 05:59 未知归属地
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。