title($desc['title']); // 通知栏的title $message->description($desc['message']); // 通知栏的descption $message->passThrough(0); // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数 //$message->payload($payload); // 携带的数据,点击后将会通过客户端的receiver中的onReceiveMessage方法传入。 //对于预定义点击行为,payload会通过点击进入的界面的intent中的extra字段获取,而不会调用到onReceiveMessage方法。 $message->extra(Builder::notifyEffect, 0); // 此处设置预定义点击行为,1为打开app //$message->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0 $message->notifyType(1);//设置通知类型, type类型(-1, 1-使用默认提示音提示, 2-使用默认震动提示, 3-使用默认led灯光提示) //$message->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存 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->build(); $sender = new Sender(); $re = $sender->broadcastAll($message)->getRaw(); //print_r($re); return true; } /* * 立即推送-部分用户 */ public static function androidPushPart($desc) { Constants::useOfficial();//正式环境 //Constants::useSandbox();//测试环境 $secret = $desc['secret']; $package = $desc['package']; Constants::setSecret($secret); Constants::setPackage($package); //Constants::setBundleId($package); $message = new Builder(); $message->title($desc['title']); // 通知栏的title $message->description($desc['message']); // 通知栏的descption $message->passThrough(0); // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数 //$message->payload($payload); // 携带的数据,点击后将会通过客户端的receiver中的onReceiveMessage方法传入。 //对于预定义点击行为,payload会通过点击进入的界面的intent中的extra字段获取,而不会调用到onReceiveMessage方法。 // $message->extra(Builder::notifyEffect, 0); // 此处设置预定义点击行为,1为打开app $message->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0 $message->notifyType(1);//设置通知类型, type类型(-1, 1-使用默认提示音提示, 2-使用默认震动提示, 3-使用默认led灯光提示) //$message->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存 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->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 androidPushAllTimingPush($desc) { Constants::useOfficial();//正式环境 //Constants::useSandbox();//测试环境 $secret = $desc['secret']; $package = $desc['package']; Constants::setSecret($secret); Constants::setPackage($package); //Constants::setBundleId($package); $message = new Builder(); $message->title($desc['title']); // 通知栏的title $message->description($desc['message']); // 通知栏的descption $message->passThrough(0); // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数 //$message->payload($payload); // 携带的数据,点击后将会通过客户端的receiver中的onReceiveMessage方法传入。 //对于预定义点击行为,payload会通过点击进入的界面的intent中的extra字段获取,而不会调用到onReceiveMessage方法。 $message->extra(Builder::notifyEffect, 0); // 此处设置预定义点击行为,1为打开app //$message->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0 $message->notifyType(1);//设置通知类型, type类型(-1, 1-使用默认提示音提示, 2-使用默认震动提示, 3-使用默认led灯光提示) //$message->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存 $message->timeToSend($desc['timetosend']*1000); 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->build(); $sender = new Sender(); $re = $sender->broadcastAll($message)->getRaw(); //print_r($re); return true; } /* * 定时推送-部分用户 */ public static function androidPushPartTimingPush($desc) { Constants::useOfficial();//正式环境 //Constants::useSandbox();//测试环境 $secret = $desc['secret']; $package = $desc['package']; Constants::setSecret($secret); Constants::setPackage($package); //Constants::setBundleId($package); $message = new Builder(); $message->title($desc['title']); // 通知栏的title $message->description($desc['message']); // 通知栏的descption $message->passThrough(0); // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数 //$message->payload($payload); // 携带的数据,点击后将会通过客户端的receiver中的onReceiveMessage方法传入。 //对于预定义点击行为,payload会通过点击进入的界面的intent中的extra字段获取,而不会调用到onReceiveMessage方法。 $message->extra(Builder::notifyEffect, 0); // 此处设置预定义点击行为,1为打开app //$message->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0 $message->notifyType(1);//设置通知类型, type类型(-1, 1-使用默认提示音提示, 2-使用默认震动提示, 3-使用默认led灯光提示) //$message->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存 $message->timeToSend($desc['timetosend']*1000); 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->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 androidPushAllTimingPushDelete($desc) { Constants::useOfficial();//正式环境 //Constants::useSandbox();//测试环境 $secret = $desc['secret']; $package = $desc['package']; Constants::setSecret($secret); Constants::setPackage($package); $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; } } } ?>