Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
easy-sms
提交
d7e8fd6d
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,体验更适合开发者的 AI 搜索 >>
提交
d7e8fd6d
编写于
9月 14, 2018
作者:
O
overtrue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert #136
上级
6cefa1fd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
65 addition
and
16 deletion
+65
-16
src/EasySms.php
src/EasySms.php
+8
-2
src/Gateways/ChuanglanGateway.php
src/Gateways/ChuanglanGateway.php
+1
-1
src/Messenger.php
src/Messenger.php
+4
-5
tests/EasySmsTest.php
tests/EasySmsTest.php
+44
-0
tests/Gateways/ChuanglanGatewayTest.php
tests/Gateways/ChuanglanGatewayTest.php
+6
-6
tests/Gateways/YuntongxunGatewayTest.php
tests/Gateways/YuntongxunGatewayTest.php
+2
-2
未找到文件。
src/EasySms.php
浏览文件 @
d7e8fd6d
...
...
@@ -338,10 +338,16 @@ class EasySms
$globalSettings
=
$this
->
config
->
get
(
"gateways.
{
$gateway
}
"
,
[]);
if
(
is_string
(
$gateway
)
&&
!
empty
(
$globalSettings
)
&&
is_array
(
$setting
))
{
$formatted
[
$gateway
]
=
array_merge
(
$globalSettings
,
$setting
);
$formatted
[
$gateway
]
=
new
Config
(
array_merge
(
$globalSettings
,
$setting
)
);
}
}
return
$this
->
strategy
()
->
apply
(
$formatted
);
$result
=
[];
foreach
(
$this
->
strategy
()
->
apply
(
$formatted
)
as
$name
)
{
$result
[
$name
]
=
$formatted
[
$name
];
}
return
$result
;
}
}
src/Gateways/ChuanglanGateway.php
浏览文件 @
d7e8fd6d
...
...
@@ -13,8 +13,8 @@ namespace Overtrue\EasySms\Gateways;
use
Overtrue\EasySms\Contracts\MessageInterface
;
use
Overtrue\EasySms\Contracts\PhoneNumberInterface
;
use
Overtrue\EasySms\Exceptions\InvalidArgumentException
;
use
Overtrue\EasySms\Exceptions\GatewayErrorException
;
use
Overtrue\EasySms\Exceptions\InvalidArgumentException
;
use
Overtrue\EasySms\Support\Config
;
use
Overtrue\EasySms\Traits\HasHttpRequest
;
...
...
src/Messenger.php
浏览文件 @
d7e8fd6d
...
...
@@ -14,7 +14,6 @@ namespace Overtrue\EasySms;
use
Overtrue\EasySms\Contracts\MessageInterface
;
use
Overtrue\EasySms\Contracts\PhoneNumberInterface
;
use
Overtrue\EasySms\Exceptions\NoGatewayAvailableException
;
use
Overtrue\EasySms\Support\Config
;
/**
* Class Messenger.
...
...
@@ -56,23 +55,23 @@ class Messenger
$results
=
[];
$isSuccessful
=
false
;
foreach
(
$gateways
as
$gateway
)
{
foreach
(
$gateways
as
$gateway
=>
$config
)
{
try
{
$results
[
$gateway
]
=
[
'gateway'
=>
$gateway
,
'status'
=>
self
::
STATUS_SUCCESS
,
'result'
=>
$this
->
easySms
->
gateway
(
$gateway
)
->
send
(
$to
,
$message
,
new
Config
(
$this
->
easySms
->
getConfig
()
->
get
(
"gateways.
{
$gateway
}
"
))
),
'result'
=>
$this
->
easySms
->
gateway
(
$gateway
)
->
send
(
$to
,
$message
,
$config
),
];
$isSuccessful
=
true
;
break
;
}
catch
(
\
Throwable
$e
)
{
}
catch
(
\
Exception
$e
)
{
$results
[
$gateway
]
=
[
'gateway'
=>
$gateway
,
'status'
=>
self
::
STATUS_FAILURE
,
'exception'
=>
$e
,
];
}
catch
(
\
Exception
$e
)
{
}
catch
(
\
Throwable
$e
)
{
$results
[
$gateway
]
=
[
'gateway'
=>
$gateway
,
'status'
=>
self
::
STATUS_FAILURE
,
...
...
tests/EasySmsTest.php
浏览文件 @
d7e8fd6d
...
...
@@ -135,6 +135,50 @@ class EasySmsTest extends TestCase
$this
->
assertInstanceOf
(
Messenger
::
class
,
$easySms
->
getMessenger
());
}
public
function
testFormatGateways
()
{
$config
=
[
'gateways'
=>
[
'foo'
=>
[
'a'
=>
'b'
,
],
'bar'
=>
[
'c'
=>
'd'
,
],
],
];
$easySms
=
\
Mockery
::
mock
(
EasySms
::
class
.
'[formatMessage]'
,
[
$config
])
->
makePartial
()
->
shouldAllowMockingProtectedMethods
();
// gateway names
$gateways
=
$easySms
->
formatGateways
([
'foo'
,
'bar'
]);
$this
->
assertCount
(
2
,
$gateways
);
$this
->
arrayHasKey
(
'foo'
,
$gateways
);
$this
->
arrayHasKey
(
'bar'
,
$gateways
);
$this
->
assertSame
(
'b'
,
$gateways
[
'foo'
]
->
get
(
'a'
));
$this
->
assertSame
(
'd'
,
$gateways
[
'bar'
]
->
get
(
'c'
));
// gateway names && override config
$gateways
=
$easySms
->
formatGateways
([
'foo'
,
'bar'
=>
[
'c'
=>
'e'
]]);
$this
->
assertCount
(
2
,
$gateways
);
$this
->
arrayHasKey
(
'foo'
,
$gateways
);
$this
->
arrayHasKey
(
'bar'
,
$gateways
);
$this
->
assertSame
(
'b'
,
$gateways
[
'foo'
]
->
get
(
'a'
));
$this
->
assertSame
(
'e'
,
$gateways
[
'bar'
]
->
get
(
'c'
));
// gateway names && append config
$gateways
=
$easySms
->
formatGateways
([
'foo'
=>
[
'f'
=>
'g'
],
'bar'
=>
[
'c'
=>
'e'
]]);
$this
->
assertCount
(
2
,
$gateways
);
$this
->
arrayHasKey
(
'foo'
,
$gateways
);
$this
->
arrayHasKey
(
'bar'
,
$gateways
);
$this
->
assertSame
(
'b'
,
$gateways
[
'foo'
]
->
get
(
'a'
));
$this
->
assertSame
(
'g'
,
$gateways
[
'foo'
]
->
get
(
'f'
));
$this
->
assertSame
(
'e'
,
$gateways
[
'bar'
]
->
get
(
'c'
));
}
}
class
DummyGatewayForTest
implements
GatewayInterface
...
...
tests/Gateways/ChuanglanGatewayTest.php
浏览文件 @
d7e8fd6d
...
...
@@ -145,13 +145,13 @@ class ChuanglanGatewayTest extends TestCase
$config
=
[
'channel'
=>
ChuanglanGateway
::
CHANNEL_VALIDATE_CODE
];
$config
=
new
Config
(
$config
);
$endpoint
=
'https://smsbj1.253.com/msg/send/json'
;
$this
->
assert
Equals
(
$endpoint
,
$method
->
invoke
(
$gateway
,
$config
));
$this
->
assert
Same
(
$endpoint
,
$method
->
invoke
(
$gateway
,
$config
));
// 营销通道
$config
=
[
'channel'
=>
ChuanglanGateway
::
CHANNEL_PROMOTION_CODE
];
$config
=
new
Config
(
$config
);
$endpoint
=
'https://smssh1.253.com/msg/send/json'
;
$this
->
assert
Equals
(
$endpoint
,
$method
->
invoke
(
$gateway
,
$config
));
$this
->
assert
Same
(
$endpoint
,
$method
->
invoke
(
$gateway
,
$config
));
}
/**
...
...
@@ -168,12 +168,12 @@ class ChuanglanGatewayTest extends TestCase
// 验证码通道
$config
=
[
'channel'
=>
ChuanglanGateway
::
CHANNEL_VALIDATE_CODE
];
$config
=
new
Config
(
$config
);
$this
->
assert
Equals
(
ChuanglanGateway
::
CHANNEL_VALIDATE_CODE
,
$method
->
invoke
(
$gateway
,
$config
));
$this
->
assert
Same
(
ChuanglanGateway
::
CHANNEL_VALIDATE_CODE
,
$method
->
invoke
(
$gateway
,
$config
));
// 营销通道
$config
=
[
'channel'
=>
ChuanglanGateway
::
CHANNEL_PROMOTION_CODE
];
$config
=
new
Config
(
$config
);
$this
->
assert
Equals
(
ChuanglanGateway
::
CHANNEL_PROMOTION_CODE
,
$method
->
invoke
(
$gateway
,
$config
));
$this
->
assert
Same
(
ChuanglanGateway
::
CHANNEL_PROMOTION_CODE
,
$method
->
invoke
(
$gateway
,
$config
));
}
/**
...
...
@@ -211,7 +211,7 @@ class ChuanglanGatewayTest extends TestCase
// 验证码通道
$config
=
[
'channel'
=>
ChuanglanGateway
::
CHANNEL_VALIDATE_CODE
];
$config
=
new
Config
(
$config
);
$this
->
assert
Equals
(
'这是短信内容。'
,
$method
->
invoke
(
$gateway
,
$content
,
$config
));
$this
->
assert
Same
(
'这是短信内容。'
,
$method
->
invoke
(
$gateway
,
$content
,
$config
));
}
/**
...
...
@@ -234,7 +234,7 @@ class ChuanglanGatewayTest extends TestCase
'unsubscribe'
=>
'回TD退订'
,
];
$config
=
new
Config
(
$config
);
$this
->
assert
Equals
(
'【通讯云】这是短信内容。回TD退订'
,
$method
->
invoke
(
$gateway
,
$content
,
$config
));
$this
->
assert
Same
(
'【通讯云】这是短信内容。回TD退订'
,
$method
->
invoke
(
$gateway
,
$content
,
$config
));
}
/**
...
...
tests/Gateways/YuntongxunGatewayTest.php
浏览文件 @
d7e8fd6d
...
...
@@ -42,8 +42,8 @@ class YuntongxunGatewayTest extends TestCase
'templateId'
=>
5589
,
'appId'
=>
'mock-app-id'
,
'datas'
=>
[
'mock-data-1'
,
'mock-data-2'
],
]
&&
$params
[
'headers'
][
'Accept'
]
==
'application/json'
&&
$params
[
'headers'
][
'Content-Type'
]
==
'application/json;charset=utf-8'
;
]
&&
'application/json'
==
$params
[
'headers'
][
'Accept'
]
&&
'application/json;charset=utf-8'
==
$params
[
'headers'
][
'Content-Type'
]
;
})
)
->
andReturn
([
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录