Skip to content

Commit 9ebd911

Browse files
imxinyxinxstuovertrue
authored
完善 发送成功 逻辑判断 (#375)
* 增加 微趣云 短信发送渠道 * 完善 微趣云 渠道使用说明 * 完善 微趣云 渠道使用说明 * 完善 微趣云 渠道发送失败处理 --------- Co-authored-by: Qazink <tcp-ip@outlook.com> Co-authored-by: 安正超 <anzhengchao@gmail.com>
1 parent 110d3a5 commit 9ebd911

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

src/Gateways/WeiqucloudGateway.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config
2929
"action" => "sendhy",
3030
];
3131
$result = $this->postJson(self::ENDPOINT_URL, $data);
32-
if ($result < 0) {
33-
throw new GatewayErrorException('短信发送失败', $result, []);
32+
33+
if ($result['code'] === 200 && $result['data']['status'] === 'Success') {
34+
return $result;
3435
}
35-
return $result;
36+
throw new GatewayErrorException("短信发送失败: {$result['data']['message']}, remainPoint: {$result['data']['remainPoint']}, taskID:{$result['data']['taskID']}", 500, $result);
3637
}
37-
3838
}

tests/Gateways/WeiqucloudGatewayTest.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,45 @@ public function testSend()
3939
'action' => 'sendhy',
4040
];
4141

42+
43+
// 成功响应的数据结构
44+
$successResponse = [
45+
'code' => 200,
46+
'data' => [
47+
'status' => 'Success',
48+
'taskID' => 'mock-task-id',
49+
'remainPoint' => 100,
50+
'message' => '发送成功'
51+
]
52+
];
53+
54+
// 失败响应的数据结构
55+
$failureResponse = [
56+
'code' => 500,
57+
'data' => [
58+
'status' => 'Failed',
59+
'message' => '账户余额不足',
60+
'remainPoint' => 0,
61+
'taskID' => 'mock-task-id-failed'
62+
]
63+
];
64+
4265
$gateway->shouldReceive('postJson')
4366
->with(WeiqucloudGateway::ENDPOINT_URL, $expected)
44-
->andReturn(
45-
1, // 成功返回正数
46-
-1 // 失败返回负数
47-
)
67+
->andReturn($successResponse, $failureResponse)
4868
->twice();
4969

5070
$message = new Message(['content' => 'This is a test message.']);
5171
$config = new Config($config);
5272

5373
// 测试成功发送
54-
$this->assertSame(1, $gateway->send(new PhoneNumber(18188888888), $message, $config));
74+
$result = $gateway->send(new PhoneNumber(18188888888), $message, $config);
75+
$this->assertSame($successResponse, $result);
5576

5677
// 测试发送失败抛出异常
5778
$this->expectException(GatewayErrorException::class);
58-
$this->expectExceptionCode(-1);
59-
$this->expectExceptionMessage('短信发送失败');
79+
$this->expectExceptionCode(500);
80+
$this->expectExceptionMessage('短信发送失败: 账户余额不足, remainPoint: 0, taskID:mock-task-id-failed');
6081

6182
$gateway->send(new PhoneNumber(18188888888), $message, $config);
6283
}

0 commit comments

Comments
 (0)