Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
easy-sms
提交
2a1c840d
E
easy-sms
项目概览
OpenDocCN
/
easy-sms
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easy-sms
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2a1c840d
编写于
5月 25, 2018
作者:
O
overtrue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve exception handle.
上级
27a86912
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
1 deletion
+56
-1
README.md
README.md
+11
-0
src/Exceptions/NoGatewayAvailableException.php
src/Exceptions/NoGatewayAvailableException.php
+42
-1
src/Messenger.php
src/Messenger.php
+3
-0
未找到文件。
README.md
浏览文件 @
2a1c840d
...
...
@@ -131,10 +131,12 @@ $easySms->send(13188888888, [
```
php
[
'yunpian'
=>
[
'gateway'
=>
'yunpian'
,
'status'
=>
'success'
,
'result'
=>
[
...
]
// 平台返回值
],
'juhe'
=>
[
'gateway'
=>
'juhe'
,
'status'
=>
'failure'
,
'exception'
=>
\
Overtrue\EasySms\Exceptions\GatewayErrorException
对象
],
...
...
@@ -144,6 +146,15 @@ $easySms->send(13188888888, [
如果所选网关列表均发送失败时,将会抛出
`Overtrue\EasySms\Exceptions\NoGatewayAvailableException`
异常,你可以使用
`$e->results`
获取发送结果。
你也可以使用
`$e`
提供的更多便捷方法:
```
php
$e
->
getResults
();
// 返回所有 API 的结果,结构同上
$e
->
getExceptions
();
// 返回所有调用异常列表
$e
->
getException
(
$gateway
);
// 返回指定网关名称的异常对象
$e
->
getLastException
();
// 获取最后一个失败的异常对象
```
## 自定义网关
本拓展已经支持用户自定义网关,你可以很方便的配置即可当成与其它拓展一样的使用:
...
...
src/Exceptions/NoGatewayAvailableException.php
浏览文件 @
2a1c840d
...
...
@@ -25,6 +25,11 @@ class NoGatewayAvailableException extends Exception
*/
public
$results
=
[];
/**
* @var array
*/
public
$exceptions
=
[];
/**
* NoGatewayAvailableException constructor.
*
...
...
@@ -35,6 +40,42 @@ class NoGatewayAvailableException extends Exception
public
function
__construct
(
array
$results
=
[],
$code
=
0
,
Throwable
$previous
=
null
)
{
$this
->
results
=
$results
;
parent
::
__construct
(
'All the gateways have failed.'
,
$code
,
$previous
);
$this
->
exceptions
=
\
array_column
(
$results
,
'exception'
,
'gateway'
);
parent
::
__construct
(
'All the gateways have failed. You can get error details by `$exception->getExceptions()`'
,
$code
,
$previous
);
}
/**
* @return array
*/
public
function
getResults
()
{
return
$this
->
results
;
}
/**
* @param string $gateway
*
* @return mixed|null
*/
public
function
getException
(
$gateway
)
{
return
isset
(
$this
->
exceptions
[
$gateway
])
?
$this
->
exceptions
[
$gateway
]
:
null
;
}
/**
* @return array
*/
public
function
getExceptions
()
{
return
$this
->
exceptions
;
}
/**
* @return mixed
*/
public
function
getLastException
()
{
return
$this
->
exceptions
[
end
(
$this
->
exceptions
)];
}
}
src/Messenger.php
浏览文件 @
2a1c840d
...
...
@@ -70,6 +70,7 @@ class Messenger
foreach
(
$strategyAppliedGateways
as
$gateway
)
{
try
{
$results
[
$gateway
]
=
[
'gateway'
=>
$gateway
,
'status'
=>
self
::
STATUS_SUCCESS
,
'result'
=>
$this
->
easySms
->
gateway
(
$gateway
)
->
send
(
$to
,
$message
,
new
Config
(
$gateways
[
$gateway
])),
];
...
...
@@ -78,11 +79,13 @@ class Messenger
break
;
}
catch
(
\
Throwable
$e
)
{
$results
[
$gateway
]
=
[
'gateway'
=>
$gateway
,
'status'
=>
self
::
STATUS_FAILURE
,
'exception'
=>
$e
,
];
}
catch
(
\
Exception
$e
)
{
$results
[
$gateway
]
=
[
'gateway'
=>
$gateway
,
'status'
=>
self
::
STATUS_FAILURE
,
'exception'
=>
$e
,
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录