This article mainly talks about using the Yii framework to simulate PHP Aurora push message notifications. It has certain reference value. Interested friends can learn about it. I hope it will be helpful to you.
1. Download the Aurora Push PHP SDK, unzip it and place it in the /protected/components/ directory, as shown below:
2. Complete the modifications Below is the official demo example. I copy a demo here and change it to NotifyPush.php, with the following code:
<?php require dirname(__FILE__) . '/jpush-api-php-client/autoload.php'; use JPush\Client as JPush; class NotifyPush { static function pushAlias($alias,$ticket='消息提醒',$alert){ $appKey=Yii::app()->params['push']['AppKey']; $appMasterSecret=Yii::app()->params['push']['AppMasterSecret']; $production_mode=Yii::app()->params['push']['production_mode']; $client = new JPush($appKey, $appMasterSecret); // 完整的推送示例 // 这只是使用样例,不应该直接用于实际生产环境中 !! try { $response = $client->push() ->setPlatform(array('ios', 'android')) // 一般情况下,关于 audience 的设置只需要调用 addAlias、addTag、addTagAnd 或 addRegistrationId // 这四个方法中的某一个即可,这里仅作为示例,当然全部调用也可以,多项 audience 调用表示其结果的交集 // 即是说一般情况下,下面三个方法和没有列出的 addTagAnd 一共四个,只适用一个便可满足大多数的场景需求 ->addAlias($alias) ->setNotificationAlert($alert) ->iosNotification($ticket, array( 'sound' => 'sound.caf', // 'badge' => '+1', // 'content-available' => true, // 'mutable-content' => true, 'category' => 'jiguang', 'extras' => array( 'key' => 'value', 'jiguang' ), )) ->androidNotification($ticket, array( 'title' => $alert, // 'build_id' => 2, 'extras' => array( 'key' => 'value', 'jiguang' ), )) ->message($alert, array( 'title' => $alert, // 'content_type' => 'text', 'extras' => array( 'key' => 'value', 'jiguang' ), )) ->options(array( // sendno: 表示推送序号,纯粹用来作为 API 调用标识, // API 返回时被原样返回,以方便 API 调用方匹配请求与返回 // 这里设置为 100 仅作为示例 // 'sendno' => 100, // time_to_live: 表示离线消息保留时长(秒), // 推送当前用户不在线时,为该用户保留多长时间的离线消息,以便其上线时再次推送。 // 默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到 // 这里设置为 1 仅作为示例 // 'time_to_live' => 1, // apns_production: 表示APNs是否生产环境, // True 表示推送生产环境,False 表示要推送开发环境;如果不指定则默认为推送生产环境 'apns_production' => $production_mode, // big_push_duration: 表示定速推送时长(分钟),又名缓慢推送,把原本尽可能快的推送速度,降低下来, // 给定的 n 分钟内,均匀地向这次推送的目标用户推送。最大值为1400.未设置则不是定速推送 // 这里设置为 1 仅作为示例 // 'big_push_duration' => 1 )) ->send(); print_r($response); } catch (\JPush\Exceptions\APIConnectionException $e) { // try something here print $e; } catch (\JPush\Exceptions\APIRequestException $e) { // try something here print $e; } } static function pushAll($ticket='消息提醒',$alert){ $appKey=Yii::app()->params['push']['AppKey']; $appMasterSecret=Yii::app()->params['push']['AppMasterSecret']; $production_mode=Yii::app()->params['push']['production_mode']; $client = new JPush($appKey, $appMasterSecret); // 完整的推送示例 // 这只是使用样例,不应该直接用于实际生产环境中 !! try { $response = $client->push() ->setPlatform(array('ios', 'android')) ->setAudience('all') // 一般情况下,关于 audience 的设置只需要调用 addAlias、addTag、addTagAnd 或 addRegistrationId // 这四个方法中的某一个即可,这里仅作为示例,当然全部调用也可以,多项 audience 调用表示其结果的交集 // 即是说一般情况下,下面三个方法和没有列出的 addTagAnd 一共四个,只适用一个便可满足大多数的场景需求 ->setNotificationAlert($alert) ->iosNotification($ticket, array( 'sound' => 'sound.caf', // 'badge' => '+1', // 'content-available' => true, // 'mutable-content' => true, 'category' => 'jiguang', 'extras' => array( 'key' => 'value', 'jiguang' ), )) ->androidNotification($ticket, array( 'title' => $alert, // 'build_id' => 2, 'extras' => array( 'key' => 'value', 'jiguang' ), )) ->message($alert, array( 'title' => $alert, // 'content_type' => 'text', 'extras' => array( 'key' => 'value', 'jiguang' ), )) ->options(array( // sendno: 表示推送序号,纯粹用来作为 API 调用标识, // API 返回时被原样返回,以方便 API 调用方匹配请求与返回 // 这里设置为 100 仅作为示例 // 'sendno' => 100, // time_to_live: 表示离线消息保留时长(秒), // 推送当前用户不在线时,为该用户保留多长时间的离线消息,以便其上线时再次推送。 // 默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到 // 这里设置为 1 仅作为示例 // 'time_to_live' => 1, // apns_production: 表示APNs是否生产环境, // True 表示推送生产环境,False 表示要推送开发环境;如果不指定则默认为推送生产环境 'apns_production' => $production_mode, // big_push_duration: 表示定速推送时长(分钟),又名缓慢推送,把原本尽可能快的推送速度,降低下来, // 给定的 n 分钟内,均匀地向这次推送的目标用户推送。最大值为1400.未设置则不是定速推送 // 这里设置为 1 仅作为示例 // 'big_push_duration' => 1 )) ->send(); print_r($response); } catch (\JPush\Exceptions\APIConnectionException $e) { // try something here print $e; } catch (\JPush\Exceptions\APIRequestException $e) { // try something here print $e; } } }
Third, call the method in NotifyPush.php to implement push, as follows:
class CronNotifyPushCommand extends CConsoleCommand{ public $keys=array(); public function init(){ parent::init(); } public function actionIndex(){ echo 'start CronNotifyPushCommand '.chr(10); if(!Yii::app()->params['push']['push_status']){ echo 'push status disabled';die(); } $rkey='message_notify_list'; $waitTotals=Fredis::model()->redis->lsize($rkey); echo 'wait totals:'.$waitTotals.chr(10); $waitResult=true; $i=0; while($waitResult) {$i++; echo $i.'/'.$waitTotals.' wait to do'.chr(10); $waitResult=Fredis::model()->redis->rpop($rkey); if(!$waitResult) { continue; } $db_data=unserialize($waitResult);var_dump($db_data); $message_content=$db_data['message_content']; $uid=$db_data['uid']; $alias=$uid; if($uid==0){ NotifyPush::pushAll($message_content, $message_content); }else { NotifyPush::pushAlias($alias, $message_content, $message_content); } } echo 'end'.chr(10); } }
Related tutorials: PHP video tutorial
The above is the detailed content of Yii1.1 framework simulates PHP Aurora push message notification. For more information, please follow other related articles on the PHP Chinese website!

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function