Skip to content

Commit

Permalink
Ucloud网关支持模板指定签名 (#345)
Browse files Browse the repository at this point in the history
* Ucloud网关支持模板指定签名

* Ucloud网关支持模板指定签名
  • Loading branch information
omgbbq authored Apr 14, 2023
1 parent d8f01fd commit 78b9bda
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Gateways/UcloudGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function buildParams(PhoneNumberInterface $to, MessageInterface $messa
$data = $message->getData($this);
$params = [
'Action' => self::ENDPOINT_Action,
'SigContent' => $config->get('sig_content'),
'SigContent' => !empty($data['sig_content']) ? $data['sig_content'] : $config->get('sig_content', ''),
'TemplateId' => $message->getTemplate($this),
'PublicKey' => $config->get('public_key'),
];
Expand Down
42 changes: 42 additions & 0 deletions tests/Gateways/UcloudGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,46 @@ public function testSend()

$gateway->send(new PhoneNumber(18888888888), $message, $config);
}

public function testSignContent()
{
$defaultSigContent = 'default_sig_content';

$dataSigContent = 'data_sig_content';

$config = [
'private_key' => '', //私钥
'public_key' => '', //公钥
'sig_content' => $defaultSigContent, //签名
'project_id' => '',
];
$easySms = new EasySms($config);

$phoneNumber = new PhoneNumber('18888888888');
$gateway = $easySms->gateway('ucloud');

$reflectionMethod = new \ReflectionMethod(get_class($gateway), 'buildParams');
$reflectionMethod->setAccessible(true);
//验证指定签名
$message = new Message([
'template' => '',
'data' => [
'code' => '', // 如果是多个参数可以用数组
'mobiles' => '', //同时发送多个手机也可以用数组来,[1111111,11111]
'sig_content'=>$dataSigContent
],
]);
$result = $reflectionMethod->invokeArgs($gateway, [$phoneNumber, $message, $easySms->getConfig()]);
$this->assertSame($dataSigContent, $result['SigContent']);
//验证配置默认签名
$message = new Message([
'template' => '',
'data' => [
'code' => '', // 如果是多个参数可以用数组
'mobiles' => '', //同时发送多个手机也可以用数组来,[1111111,11111]
],
]);
$result = $reflectionMethod->invokeArgs($gateway, [$phoneNumber, $message, $easySms->getConfig()]);
$this->assertSame($defaultSigContent, $result['SigContent']);
}
}

0 comments on commit 78b9bda

Please sign in to comment.