PHP code example of hyancat / short-messenger
1. Go to this page and download the library: Download hyancat/short-messenger library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
hyancat / short-messenger example snippets
$config = [
'default' => 'aliyun' ,
'providers' => [
'aliyun' => [
'region' => 'cn-hangzhou' ,
'access_id' => 'xxx' ,
'access_key' => 'yyy' ,
],
'sendcloud' => [
'sms_user' => 'xxx' ,
'sms_key' => 'yyy' ,
],
],
];
$manager = new SmsManager();
$manager->config($config);
$manager->extend('aliyun' , function () use ($config) {
return new AliyunProvider($config['providers' ]['aliyun' ]);
});
$manager->extend('sendcloud' , function () use ($config) {
return new SendCloudProvider($config['providers' ]['sendcloud' ]);
});
$smsService = new SmsService($manager);
$smsService->send('186xxx' , function (ShortMessage $message) {
$message->template('template_123' )
->signature('SIGNATURE_xx' )
->data(['code' => 1234 ]);
});
HyanCat\ShortMessenger\SmsServiceProvider::class
[
'default' => 'aliyun' ,
'providers' => [
'aliyun' => [
'region' => 'cn-hangzhou' ,
'access_id' => env('ALIYUN_SMS_ACCESS_ID' , '' ),
'access_key' => env('ALIYUN_SMS_ACCESS_KEY' , '' ),
],
'sendcloud' => [
'sms_user' => env('SENDCLOUD_SMS_USER' , '' ),
'sms_key' => env('SENDCLOUD_SMS_KEY' , '' ),
],
]
]
use HyanCat \ShortMessenger \SmsServiceFacade as SMS ;
SMS::send('18688888888' , function (ShortMessage $message) {
$message->template('template_123' )
->signature('SIGNATURE_xx' )
->data(['code' => 1234 ]);
});