Package Data | |
---|---|
Maintainer Username: | chenzi |
Maintainer Contact: | wenj_2011@hotmail.com (chenzi) |
Package Create Date: | 2017-05-10 |
Package Last Update: | 2017-05-23 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:01:27 |
Package Statistics | |
---|---|
Total Downloads: | 7 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Via Composer
$ composer require chenzi/laravel-mns-driver
Add following service providers into your providers array in config/app.php
Chenzi\LaravelMNS\LaravelMNSServiceProvider::class
Edit your config/queue.php
, add mns
connection
'mns' => [
'sms'=> [
'driver' => 'sms',
'key' => env('QUEUE_MNS_ACCESS_KEY'),
'secret' => env('QUEUE_MNS_SECRET_KEY'),
'endpoint' => env('QUEUE_MNS_ENDPOINT'),
'queue' => env('QUEUE_NAME'),
'wait_seconds' => 30,
],
'email'=> [
'driver' => 'email',
'key' => env('QUEUE_MNS_ACCESS_KEY'),
'secret' => env('QUEUE_MNS_SECRET_KEY'),
'endpoint' => env('QUEUE_MNS_ENDPOINT'),
'queue' => env('QUEUE_NAME'),
'wait_seconds' => 30,
]
]
About wait_seconds
Edit your .env
file
QUEUE_DRIVER=mns
QUEUE_NAME=foobar-local
QUEUE_MNS_ACCESS_KEY=your_acccess_key
QUEUE_MNS_SECRET_KEY=your_secret_key
QUEUE_MNS_ENDPOINT=http://12345678910.mns.cn-hangzhou.aliyuncs.com/
You should update QUEUE_MNS_ENDPOINT
to internal endpoint
in production mode
First create a queue and get queue endpoint at Aliyun MNS Console
Then update MNS_ENDPOINT
in .env
Push a test message to queue
Queue::push(function($job){
/**
* Your statments go here
*/
$job->delete();
});
You also can custom request data format add mns queue with other program
return json_encode( [
'displayName' => 'App\Jobs\SendSms',
'job' => 'App\Jobs\SendSms',
'maxTries' => null,
'timeout' => null,
'data' => [],
] );
Create queue work, run command in terminal
$ php artisan queue:mns:work sms
Flush MNS messages on Aliyun
$ php artisan queue:mns:flush
class SendSms implements ShouldQueue
{
...
public function handle(ReceiveMessageResponse $job){
$messageId = $job->getMessageId();
$messageBody = $job->getMessageBody();
//TODO do some thing...
}
...
}
Create RAM access control at Aliyun RAM Console
Create a custom policy such as AliyunMNSFullAccessFoobar
{
"Version": "1",
"Statement": [
{
"Action": "mns:*",
"Resource": [
"acs:mns:*:*:*/foobar-local",
"acs:mns:*:*:*/foobar-sandbox",
"acs:mns:*:*:*/foobar-production"
],
"Effect": "Allow"
}
]
}
Create a user for you app such as foobar
Assign the policy AliyunMNSFullAccessFoobar
to the user foobar
Create and get the AccessKeyId
and AccessKeySecret
for user foorbar
update QUEUE_MNS_ACCESS_KEY
and QUEUE_MNS_ACCESS_SECRET
in .env
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
The MIT License (MIT). Please see License File for more information.