zoukankan      html  css  js  c++  java
  • 推送(评论,点赞,关注)

     public function push_message($v_uid = "", $uid = "", $type = 1,$message='')
        {
            $data['type'] = $type;
            $openid = $this->get_openid($v_uid);
            $body="";
            switch ($type) {
                case 1;
                    $title = "评论通知";
                    $data['time'] = time();
                    $data['data'] = $message;
                    $data['user_data'] = get_user_info($uid, 'uid,head_img,nickname');
                  //  print_r($data['user_data']);exit;
                   $body = $data['user_data']['nickname'] . "回复了您";
                    break;
                case 2;//系统推送
                    $title='养生推送';
                    break;
            }
            $data = json_encode($data);
            $this->pushMessageToSingle($openid, $data,0,$title,$body);
        }
    
        /**单推接口案例
         * @param $clientId
         * @param $data
         * @param int $type
         * @param $title
         * @param $body
         * @return Array
         */
        function pushMessageToSingle($clientId, $data, $type = 0, $title,$body)
        {
            //消息推送Demo
            header("Content-Type: text/html; charset=utf-8");
            define('HOST', 'http://sdk.open.api.igexin.com/apiex.htm');
            define('APPKEY', ?);
            define('APPID', ?);
            define('MASTERSECRET', ?);
            import('api.lib.GETUI.Push');
            //  define('CID','请输入您的CID')
            $igt = new IGeTui(HOST, APPKEY, MASTERSECRET);
            $template = $this->IGtTransmissionTemplateDemo($data, $title,$body);
            // $template =$this->IGtNotyPopLoadTemplateDemo();
            //  print_r($data);die;
            //个推信息体
            $message = new IGtSingleMessage();
            $message->set_isOffline(true);//是否离线
            $message->set_offlineExpireTime(3600 * 12 * 1000);//离线时间
            $message->set_data($template);//设置推送消息类型
            $message->set_PushNetWorkType($type);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
            //接收方
            $target = new IGtTarget();
            $target->set_appId(APPID);
            $target->set_clientId($clientId);
            return $igt->pushMessageToSingle($message, $target);
        }
    
    
    
        function IGtTransmissionTemplateDemo($data, $title,$body)
        {
            $template = new IGtTransmissionTemplate();
            $template->set_appId(APPID);//应用appid
            $template->set_appkey(APPKEY);//应用appkey
            $template->set_transmissionType(2);//透传消息类型
            $template->set_transmissionContent($data);//透传内容
            //$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
    
    // 如下有两个推送模版,一个简单一个高级,可以互相切换使用。此处以高级为例,所以把简单模版注释掉。
            //APN简单推送
    //        $apn = new IGtAPNPayload();
    //        $alertmsg=new SimpleAlertMsg();
    //        $alertmsg->alertMsg="";
    //        $apn->alertMsg=$alertmsg;
    //      $apn->badge=2;
    //      $apn->sound="";
    //        $apn->add_customMsg("payload","payload");
    //        $apn->contentAvailable=1;
    //        $apn->category="ACTIONABLE";
    //        $template->set_apnInfo($apn);
    
            //APN高级推送
            $apn = new IGtAPNPayload();
            $alertmsg = new DictionaryAlertMsg();
            $alertmsg->body = "body";
            $alertmsg->actionLocKey = "打开天天养生";
            $alertmsg->locKey = $body;
            $alertmsg->locArgs = array("locargs");
            $alertmsg->launchImage = "launchimage";
    //        IOS8.2 支持
            $alertmsg->titleLocKey = $title;
            $alertmsg->titleLocArgs = array("TitleLocArg");
    
            $apn->alertMsg = $alertmsg;
            $apn->badge = 1;
            $apn->sound = "";
            $apn->add_customMsg("payload", $data);
    //        $apn->contentAvailable=1;
            $apn->category = "ACTIONABLE";
            $template->set_apnInfo($apn);
    
            return $template;
        }
    
        /**
         * 返回c_id
         * @param $v_uid
         * @return array|mixed|null
         */
        private function get_openid($v_uid){
           return  M('member')->where(['uid'=>$v_uid])->getField('c_id');
        }
    
  • 相关阅读:
    [NOIP2010]关押罪犯
    图的联通入门题
    【luogu4777】扩展中国剩余定理(EXCRT)[数论 扩展中国剩余定理]
    【luogu3868】【TJOI2009】猜数字[模板] [数论 中国剩余定理]
    【luogu1082】【noip2012】同余方程 [数论 扩展欧几里德]
    【luogu1962】斐波那契数列 [矩阵乘法]
    【uva1644】 素数间隔 Prime Gap [数学 质数筛]
    【uva307】小木棍 Sticks [dfs搜索]
    【luogu4011】孤岛营救问题(拯救大兵瑞恩) [最短路][分层思想]
    【noip2015】
  • 原文地址:https://www.cnblogs.com/yunian/p/6047769.html
Copyright © 2011-2022 走看看