description($desc['message']); $message->body($desc['message']); $message->title($desc['title']); $message->soundUrl('1'); $message->badge('1'); if (isset($desc['goods_id'])){ $message->extra('pushType',1000); $message->extra('goods_id', $desc['goods_id']); $message->extra('is_coupon',$desc['is_coupon']); $message->extra('coupon_price',$desc['coupon_price']); $message->extra('price',$desc['price']); $message->extra('discount_price',$desc['discount_price']); $message->extra('commission_rate',$desc['commission_rate']); $message->extra('coupon_start_time',$desc['coupon_start_time']); $message->extra('coupon_end_time',$desc['coupon_end_time']); }elseif(isset($desc['group_id'])){ $message->extra('pushType',1001); $message->extra('gid', $desc['group_id']); $message->extra('name',$desc['group_name']); }else{ if( !empty($desc['url']) ){ $message->extra('pushType',1002); $message->extra('url',$desc['url']); }else{ switch ($desc['message_type']) { case '1': $pushType = 1003; break; case '4': $pushType = 1004; break; case '5': $pushType = 1005; break; case '6': $pushType = 1006; break; default: $pushType = 0; break; } $message->extra('pushType',$pushType); } } $message->timeToLive($desc['timetolive']*1000); $message->build(); $sender = new Sender(); $re = $sender->broadcastAll($message)->getRaw(); //print_r($re); return $re; } /* * 立即推送-部分用户 */ public static function iphonePushPart($desc) { Constants::useOfficial();//正式环境 // Constants::useSandbox();//测试环境 $secret = $desc['secret']; $bundleId = $desc['bundleId']; Constants::setSecret($secret); Constants::setBundleId($bundleId); $message = new IOSBuilder(); $message->description($desc['message']); $message->body($desc['message']); $message->title($desc['title']); $message->soundUrl('1'); $message->badge('1'); if (isset($desc['goods_id'])){ $message->extra('pushType',1000); $message->extra('goods_id', $desc['goods_id']); $message->extra('is_coupon',$desc['is_coupon']); $message->extra('coupon_price',$desc['coupon_price']); $message->extra('price',$desc['price']); $message->extra('discount_price',$desc['discount_price']); $message->extra('commission_rate',$desc['commission_rate']); $message->extra('coupon_start_time',$desc['coupon_start_time']); $message->extra('coupon_end_time',$desc['coupon_end_time']); }elseif(isset($desc['group_id'])){ $message->extra('pushType',1001); $message->extra('gid', $desc['group_id']); $message->extra('name',$desc['group_name']); }else{ if( !empty($desc['url']) ){ $message->extra('pushType',1002); $message->extra('url',$desc['url']); }else{ switch ($desc['message_type']) { case '1': $pushType = 1003; break; case '4': $pushType = 1004; break; case '5': $pushType = 1005; break; case '6': $pushType = 1006; break; case '10': $pushType = 1010; break; default: $pushType = 0; break; } $message->extra('pushType',$pushType); } } $message->timeToLive($desc['timetolive']*1000); $message->build(); $sender = new Sender(); if(is_string($desc['users'])){ $re = $sender->sendToAlias($message,$desc['users'])->getRaw(); }else{ $re = $sender->sendToAliases($message,$desc['users'])->getRaw(); } //print_r($re); return $re; } /* * 定时推送-全部用户 */ public static function iphonePushAllTimingPush($desc) { Constants::useOfficial();//正式环境 //Constants::useSandbox();//测试环境 $secret = $desc['secret']; $bundleId = $desc['bundleId']; Constants::setSecret($secret); Constants::setBundleId($bundleId); $message = new IOSBuilder(); $message->description($desc['message']); $message->body($desc['message']); $message->title($desc['title']); $message->soundUrl('1'); $message->badge('1'); if (isset($desc['goods_id'])){ $message->extra('pushType',1000); $message->extra('goods_id', $desc['goods_id']); $message->extra('is_coupon',$desc['is_coupon']); $message->extra('coupon_price',$desc['coupon_price']); $message->extra('price',$desc['price']); $message->extra('discount_price',$desc['discount_price']); $message->extra('commission_rate',$desc['commission_rate']); $message->extra('coupon_start_time',$desc['coupon_start_time']); $message->extra('coupon_end_time',$desc['coupon_end_time']); }elseif(isset($desc['group_id'])){ $message->extra('pushType',1001); $message->extra('gid', $desc['group_id']); $message->extra('name',$desc['group_name']); }else{ if( !empty($desc['url']) ){ $message->extra('pushType',1002); $message->extra('url',$desc['url']); }else{ switch ($desc['message_type']) { case '1': $pushType = 1003; break; case '4': $pushType = 1004; break; case '5': $pushType = 1005; break; case '6': $pushType = 1006; break; default: $pushType = 0; break; } $message->extra('pushType',$pushType); } } $message->timeToLive($desc['timetolive']*1000); $message->timeToSend($desc['timetosend']*1000); $message->build(); $sender = new Sender(); $re = $sender->broadcastAll($message)->getRaw(); //判断该条推送消息是否有之前版本,有->删除 if ($re['code']==0){ self::iphonePushAllTimingPushDelete($desc); // //print_r($messageid); // $flag=$sender->checkScheduleJobExist($messageid); //检测定时消息的任务是否存在 // $error_code=$flag->getErrorCode(); // if ($error_code==0){ // //有->删除 // $sender->deleteScheduleJob($messageid); // } } //echo '
';
        //print_r($re);
        return $re;
    }

    /*
     * 定时推送-部分用户
     */
    public static function  iphonePushPartTimingPush($desc)
    {       
        Constants::useOfficial();//正式环境
        //Constants::useSandbox();//测试环境
       
        $secret   = $desc['secret'];
        $bundleId = $desc['bundleId'];

        Constants::setSecret($secret);
        Constants::setBundleId($bundleId);

        $message = new IOSBuilder();
        $message->description($desc['message']);
        $message->body($desc['message']);
        $message->title($desc['title']);
        $message->soundUrl('1');
        $message->badge('1');
        if (isset($desc['goods_id'])){
            $message->extra('pushType',1000);
            $message->extra('goods_id', $desc['goods_id']);
            $message->extra('is_coupon',$desc['is_coupon']);
            $message->extra('coupon_price',$desc['coupon_price']);
            $message->extra('price',$desc['price']);
            $message->extra('discount_price',$desc['discount_price']);
            $message->extra('commission_rate',$desc['commission_rate']);
            $message->extra('coupon_start_time',$desc['coupon_start_time']);
            $message->extra('coupon_end_time',$desc['coupon_end_time']);
        }elseif(isset($desc['group_id'])){
            $message->extra('pushType',1001);
            $message->extra('gid', $desc['group_id']);
            $message->extra('name',$desc['group_name']);
        }else{
            if( !empty($desc['url']) ){
                $message->extra('pushType',1002);
                $message->extra('url',$desc['url']);
            }else{
                switch ($desc['message_type']) {
                    case '1':
                        $pushType = 1003;
                        break;
                    case '4':
                        $pushType = 1004;
                        break;
                    case '5':
                        $pushType = 1005;
                        break;
                    case '6':
                        $pushType = 1006;
                        break;
                    default:
                        $pushType = 0;
                        break;                        
                }
                $message->extra('pushType',$pushType);
            }
        }
        $message->timeToLive($desc['timetolive']*1000);
        $message->timeToSend($desc['timetosend']*1000);
        $message->build();

        $sender = new Sender();
        if(is_string($desc['users'])){
            $re = $sender->sendToAlias($message,$desc['users'])->getRaw();
        }else{
            $re = $sender->sendToAliases($message,$desc['users'])->getRaw();
        }
//        //判断该条推送消息是否有之前版本,有->删除
//        if ($re['code']==0){
//            $messageid=!empty($desc['push_msg_id'])?$desc['push_msg_id']:0;
//            //print_r($messageid);
//            $flag=$sender->checkScheduleJobExist($messageid); //检测定时消息的任务是否存在
//            $error_code=$flag->getErrorCode();
//            if ($error_code==0){
//                //有->删除
//                deleteScheduleJob($messageid);
//            }
//        }
//        return $re;
        //print_r($re);
        return $re;
    }

    /*
     * 删除定时推送 - 全部用户
     */

    public static function  iphonePushAllTimingPushDelete($desc)
    {       
        Constants::useOfficial();//正式环境
        //Constants::useSandbox();//测试环境
      
        $secret   = $desc['secret'];
        $bundleId = $desc['bundleId'];

        Constants::setSecret($secret);
        Constants::setBundleId($bundleId);

        $sender = new Sender();
        //判断该条推送消息是否有之前版本,有->删除
        $messageid=!empty($desc['push_msg_id'])?$desc['push_msg_id']:0;
        $flag=$sender->checkScheduleJobExist($messageid); //检测定时消息的任务是否存在
        $error_code=$flag->getErrorCode();
        //print_r($error_code);
        if ($error_code==0){
            //有->删除
            $flag2=$sender->deleteScheduleJob($messageid);
            $error_code2=$flag2->getErrorCode();
            //print_r($error_code2);
            if ($error_code2==0) {
                return true;
            }
        }else{
            return true;
        }
    }
    
}