yl / easysms-notification-channel Goto Github PK
View Code? Open in Web Editor NEWEasySms Notification Channel for Laravel.
License: MIT License
EasySms Notification Channel for Laravel.
License: MIT License
没有正常捕捉到异常信息,重现方式,输入错误的模版或者把签名类型设置为 验证码。
短信通知类型代码如下:
public function via($notifiable)
{
return ['database', EasySmsChannel::class];
}
public function toEasySms($notifiable)
{
try{
return (new EasySmsMessage)
->setContent('您提交的企业“123456”认证信息已通过审核,感谢您的使用。')
->setTemplate( 'SMS_198920278' ) // 短信阿里云模板
->setData(['company_name' => 2222222]);
} catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $e) {
dd($e);
}
}
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Leonis\Notifications\EasySms\Channels\EasySmsChannel;
use Leonis\Notifications\EasySms\Messages\EasySmsMessage;
class VerificationCode extends Notification
{
use Queueable;
public function via($notifiable)
{
return [EasySmsChannel::class];
}
public function toEasySms($notifiable)
{
return (new EasySmsMessage)
->setContent('您的验证码为: 6379')
->setTemplate('SMS_001')
->setData(['code' => 6379]);
}
}
Notification::route(
EasySmsChannel::class,
new PhoneNumber(13333333333, 86)
)->notify(new VerificationCode());
提示 "message": "Undefined index: Leonis\Notifications\EasySms\Channels\EasySmsChannel",
因当前包使用overtrue/easy-sms的1.1版本在php8.1环境会报以下错误提示,望同步更新
PHP Deprecated: Return type of Overtrue\EasySms\PhoneNumber::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/illusplus-server/vendor/overtrue/easy-sms/src/PhoneNumber.php on line 111 PHP Deprecated: Return type of Overtrue\EasySms\Support\Config::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/illusplus-server/vendor/overtrue/easy-sms/src/Support/Config.php on line 82 PHP Deprecated: Return type of Overtrue\EasySms\Support\Config::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/illusplus-server/vendor/overtrue/easy-sms/src/Support/Config.php on line 100 PHP Deprecated: Return type of Overtrue\EasySms\Support\Config::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/illusplus-server/vendor/overtrue/easy-sms/src/Support/Config.php on line 119 PHP Deprecated: Return type of Overtrue\EasySms\Support\Config::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/code/illusplus-server/vendor/overtrue/easy-sms/src/Support/Config.php on line 137
消息方法实现
public function toEasySms($notifiable) { $code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT); return (new EasySmsMessage()) ->setTemplate(env('SMS_TEMPLATE')) ->setData(['code' => $code]); }
发送验证码调用
Notification::route( EasySmsChannel::class, new PhoneNumber($phone,86) )->notify(new SmsVerificationCode());
问题来了 我怎么获取消息方法里面的code啊。。或者我怎么把发送验证码时候的phone传进去
// 可用的网关配置
'gateways' => [
// 失败日志
'errorlog' => [
'channel' => 'daily',
],
'san' => [
'username' => '000',
'password' => '000',
]
],
'custom_gateways' => [
'errorlog' => \Leonis\Notifications\EasySms\Gateways\ErrorLogGateway::class,
'winic' => \Leonis\Notifications\EasySms\Gateways\WinicGateway::class,
'san' => \App\Gateway\SanGateway::class,
],
配置了这个之后怎么操作?
我现在发送
加载不了网关
Overtrue\EasySms\Exceptions\NoGatewayAvailableException
All the gateways have failed. You can get error details by `$exception->getExceptions()`
storage/logs/sms.log
[2021-12-17 00:57:42] local.ERROR: to: +8618589149677 | message: "" | template: "SMS_230010220" | data: {"code":"111111"}
使用阿里云短信服务,如何获取接口返回的结果
例如:是发送成功,还是账户余额不足等,错误代码或者原因,smslog.log 只呈现出来local.ERROR message:""
我使用的laravel的版本是8.26.1
use Leonis\Notifications\Channels\EasySmsChannel;
use Leonis\Notifications\Messages\EasySmsMessage;
use Leonis\Notifications\EasySms\Channels\EasySmsChannel;
use Leonis\Notifications\EasySms\Messages\EasySmsMessage;
怎么获取阿里短信发送返回的结果
比如阿里云国际是不支持发国内的,所以国内用的其他平台国际用阿里云
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.