zoukankan      html  css  js  c++  java
  • 在ionic项目中使用极光推送实现推送 & 服务器端代码

    ionic start -a jPushDemo -i com.lawxin.fengkong jpushdemo blank

    meteor add cordova:cn.jpush.phonegap.JPushPlugin@https://github.com/jpush/jpush-phonegap-plugin/tarball/f54252dd4f28874319c002cf0d066b6adb865c1f

    http://ionichina.com/topic/54f96e7b59a9bdef119234a1

    下载之后,手动修改以下文件,也可以实现。需要注意的是极光有延迟,稍后便能看到效果。

    cn.jpush.phonegap.JPushPlugin.java
    src/android/AndroidManifest.xml
    src/ios/PushConfig.plist

    source code:http://vdisk.weibo.com/s/ao-ZYIoZdUTFI

    取设备ID

    //在非登陆页使用
    document.addEventListener("deviceready", function () {
    //alert(10000)
    if (undefined != window.plugins
    && undefined != window.plugins.jPushPlugin){
    //alert("on phone");
    //启动极光推送服务
    window.plugins.jPushPlugin.init();
    window.plugins.jPushPlugin.getRegistrationID(function (result) {

    if (result){
    var registrationID = result;
    console.log("registrationID",registrationID);
    //alert("init registrationID"+result);
    //alert("init registrationID"+result);
    }
    //alert("init registrationID"+result);
    console.log("result registrationID",registrationID);
    });
    }
    }, false);

      

    server code:

    package main
    
    import (
        "fmt"
        "github.com/ylywyn/jpush-api-go-client"
    )
    
    const (
        appKey = ""
        secret = ""
    )
    
    func main() {
    
        //Platform
        var pf jpushclient.Platform
        pf.Add(jpushclient.ANDROID)
        pf.Add(jpushclient.IOS)
        //pf.Add(jpushclient.WINPHONE)
        //pf.All()
    
        //Audience
        var ad jpushclient.Audience
        s := []string{"011364bb516","0000103808e"}
        //ad.SetTag(s)
        //ad.SetAlias(s)
        ad.SetID(s)
        //ad.All()
    
        //Notice
        message := "您有1条消息风控信息,请注意查收"
        var notice jpushclient.Notice
        notice.SetAlert(message)
        notice.SetAndroidNotice(&jpushclient.AndroidNotice{Alert: message})
        notice.SetIOSNotice(&jpushclient.IOSNotice{Alert: message})
        //notice.SetWinPhoneNotice(&jpushclient.WinPhoneNotice{Alert: "WinPhoneNotice"})
    
        var msg jpushclient.Message
        msg.Title = "风控宝"
        msg.Content = message
    
        payload := jpushclient.NewPushPayLoad()
        payload.SetPlatform(&pf)
        payload.SetAudience(&ad)
        payload.SetMessage(&msg)
        payload.SetNotice(&notice)
    
        bytes, _ := payload.ToBytes()
        fmt.Printf("%s
    ", string(bytes))
    
        //push
        c := jpushclient.NewPushClient(secret, appKey)
        str, err := c.Send(bytes)
        if err != nil {
            fmt.Printf("err:%s", err.Error())
        } else {
            fmt.Printf("ok:%s", str)
        }
    }
    

      

  • 相关阅读:
    关于Ubuntu中passwd、shadow、group等文件
    Android colors.xml 颜色列表
    【设计】线框图、原型和视觉稿的区别
    【设计】24款线框图相关工具及资源大放送
    【辅助工具】20款优秀的移动产品原型和线框图设计工具(二)
    【辅助工具】20款优秀的移动产品原型和线框图设计工具(一)
    GET RESTful With Python
    VRRP、Track与NQA联动配置举例(Master监视上行链路)
    静态路由、Track与NQA联动配置举例
    ROS-MikroTik-RouterOS-培训认证各种证书
  • 原文地址:https://www.cnblogs.com/sban/p/4757308.html
Copyright © 2011-2022 走看看