Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
easy-sms
提交
25e8ec71
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 搜索 >>
提交
25e8ec71
编写于
2月 27, 2019
作者:
T
timjuly
提交者:
安正超
2月 27, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复在填写了大陆国际区号的情况下短信发送失败的Bug (#165)
上级
078abd52
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
1 deletion
+81
-1
src/Gateways/SubmailGateway.php
src/Gateways/SubmailGateway.php
+15
-1
tests/Gateways/SubmailGatewayTest.php
tests/Gateways/SubmailGatewayTest.php
+66
-0
未找到文件。
src/Gateways/SubmailGateway.php
浏览文件 @
25e8ec71
...
...
@@ -41,7 +41,7 @@ class SubmailGateway extends Gateway
*/
public
function
send
(
PhoneNumberInterface
$to
,
MessageInterface
$message
,
Config
$config
)
{
$endpoint
=
$this
->
buildEndpoint
(
$t
o
->
getIDDCode
()
?
'internationalsms/xsend'
:
'message
/xsend'
);
$endpoint
=
$this
->
buildEndpoint
(
$t
his
->
inChineseMainland
(
$to
)
?
'message/xsend'
:
'internationalsms
/xsend'
);
$data
=
$message
->
getData
(
$this
);
...
...
@@ -71,4 +71,18 @@ class SubmailGateway extends Gateway
{
return
sprintf
(
self
::
ENDPOINT_TEMPLATE
,
$function
,
self
::
ENDPOINT_FORMAT
);
}
/**
* Check if the phone number belongs to chinese mainland.
*
* @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to
*
* @return bool
*/
protected
function
inChineseMainland
(
$to
)
{
$code
=
$to
->
getIDDCode
();
return
empty
(
$code
)
||
86
===
$code
;
}
}
tests/Gateways/SubmailGatewayTest.php
浏览文件 @
25e8ec71
...
...
@@ -95,4 +95,70 @@ class SubmailGatewayTest extends TestCase
'sms_credits'
=>
14197
,
],
$gateway
->
send
(
new
PhoneNumber
(
18188888888
),
$message
,
$config
));
}
public
function
testEndpointChina
()
{
$config
=
[
'app_id'
=>
'mock-app-id'
,
'app_key'
=>
'mock-app-key'
,
'project'
=>
'mock-project'
,
];
$gateway
=
\
Mockery
::
mock
(
SubmailGateway
::
class
.
'[post]'
,
[
$config
])
->
shouldAllowMockingProtectedMethods
();
$gateway
->
shouldReceive
(
'post'
)
->
with
(
'https://api.mysubmail.com/message/xsend.json'
,
[
'appid'
=>
'mock-app-id'
,
'signature'
=>
'mock-app-key'
,
'project'
=>
'mock-project'
,
'to'
=>
new
PhoneNumber
(
18188888888
,
86
),
'vars'
=>
json_encode
([
'code'
=>
'123456'
,
'time'
=>
'15'
]),
])
->
andReturn
([
'status'
=>
'success'
,
'send_id'
=>
'093c0a7df143c087d6cba9cdf0cf3738'
,
'fee'
=>
1
,
'sms_credits'
=>
14197
,
]);
$message
=
new
Message
([
'data'
=>
[
'code'
=>
'123456'
,
'time'
=>
'15'
]]);
$config
=
new
Config
(
$config
);
$this
->
assertSame
([
'status'
=>
'success'
,
'send_id'
=>
'093c0a7df143c087d6cba9cdf0cf3738'
,
'fee'
=>
1
,
'sms_credits'
=>
14197
,
],
$gateway
->
send
(
new
PhoneNumber
(
18188888888
,
86
),
$message
,
$config
));
}
public
function
testEndpointInternational
()
{
$config
=
[
'app_id'
=>
'mock-app-id'
,
'app_key'
=>
'mock-app-key'
,
'project'
=>
'mock-project'
,
];
$gateway
=
\
Mockery
::
mock
(
SubmailGateway
::
class
.
'[post]'
,
[
$config
])
->
shouldAllowMockingProtectedMethods
();
$gateway
->
shouldReceive
(
'post'
)
->
with
(
'https://api.mysubmail.com/internationalsms/xsend.json'
,
[
'appid'
=>
'mock-app-id'
,
'signature'
=>
'mock-app-key'
,
'project'
=>
'mock-project'
,
'to'
=>
new
PhoneNumber
(
18188888888
,
1
),
'vars'
=>
json_encode
([
'code'
=>
'123456'
,
'time'
=>
'15'
]),
])
->
andReturn
([
'status'
=>
'success'
,
'send_id'
=>
'093c0a7df143c087d6cba9cdf0cf3738'
,
'fee'
=>
1
,
'sms_credits'
=>
14197
,
]);
$message
=
new
Message
([
'data'
=>
[
'code'
=>
'123456'
,
'time'
=>
'15'
]]);
$config
=
new
Config
(
$config
);
$this
->
assertSame
([
'status'
=>
'success'
,
'send_id'
=>
'093c0a7df143c087d6cba9cdf0cf3738'
,
'fee'
=>
1
,
'sms_credits'
=>
14197
,
],
$gateway
->
send
(
new
PhoneNumber
(
18188888888
,
1
),
$message
,
$config
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录