• 极光推送


    <?php
    namespace appcommoncontroller;

    class Jpush{

        private $app_key = 'e8e85eec91ad4d8359260aff';            //待发送的应用程序(appKey),只能填一个。

        private $master_secret = '752a4498507e54329d6e533c';        //主密码
        private $url = "https://api.jpush.cn/v3/push";      //推送的地址

        //若实例化的时候传入相应的值则按新的相应值进行
        public function __construct($app_key=null, $master_secret=null,$url=null) {
            if ($app_key) $this->app_key = $app_key;
            if ($master_secret) $this->master_secret = $master_secret;
            if ($url) $this->url = $url;
        }
        public function push($rece,$content,$m_time='86400',$arr){
            $base64=base64_encode("$this->app_key:$this->master_secret");
            $header=array("Authorization:Basic $base64","Content-Type:application/json");
            $data = array();
            $data['platform'] = 'all';          //目标用户终端手机的平台类型android,ios,winphone
            $data['audience'] = array(
                'alias' => $rece //别名推送
            );      //目标用户
           
            $data['notification'] = array(
                //统一的模式--标准模式
                "alert"=>$content,   
                //安卓自定义
                "android"=>array(
                    "alert"=>$content,
                    "title"=>"",
                    "builder_id"=>1,
                    "extras"=>$arr
                ),
                //ios的自定义
                "ios"=>array(
                    "alert"=>$content,
                    "badge"=>"1",
                    "sound"=>"default",
                    "extras"=>$arr
                ),
            );
            $data['message'] = array(
                "msg_content"=>$content,
                "extras"=>$arr
            );
            //附加选项
            $data['options'] = array(
                "sendno"=>time(),
                "time_to_live"=>$m_time, //保存离线时间的秒数默认为一天
                "apns_production"=>0,        //指定 APNS 通知发送环境:0开发环境,1生产环境。
            );
            $param = json_encode($data);
            $res = $this->push_curl($param,$header);
             
            if($res){       //得到返回值--成功已否后面判断
                 return $res;
            }else{          //未得到返回值--返回失败
                // echo "456";
                return false;
            }
        }
     
        //推送的Curl方法
        public function push_curl($param="",$header="") {
            if (empty($param)) { return false; }
            $postUrl = $this->url;
            $curlPost = $param;
            $ch = curl_init();                                      //初始化curl
            curl_setopt($ch, CURLOPT_URL,$postUrl);                 //抓取指定网页
            curl_setopt($ch, CURLOPT_HEADER, 0);                    //设置header
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            //要求结果为字符串且输出到屏幕上
            curl_setopt($ch, CURLOPT_POST, 1);                      //post提交方式
            curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
            curl_setopt($ch, CURLOPT_HTTPHEADER,$header);           // 增加 HTTP Header(头)里的字段
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);        // 终止从服务端进行验证
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            $data = curl_exec($ch);                                 //运行curl
            curl_close($ch);
            return $data;
        }
    }
    ?>

  • 相关阅读:
    C++11——Lambda表达式
    匿名空间使用
    C++11——可调用对象包装器、绑定器
    winhttp 发送https的get请求
    C++11——基于范围的for循环
    C++11——列表初始化
    C++11——委托构造和继承构造函数
    C++11——using的使用
    使用appnium,Uiautomatorviewer连接手机报错:Unexpected error while obtaining UI hierarchy java.lang.reflect.Invocation【已解决】
    逆向 | IATHook 全屏加速挂
  • 原文地址:https://www.cnblogs.com/myJuly/p/10077843.html
Copyright © 2020-2023  润新知