You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
55 lines
1.7 KiB
<?php
|
|
|
|
namespace app\utility;
|
|
|
|
use AlibabaCloud\Client\AlibabaCloud;
|
|
use AlibabaCloud\Client\Exception\ClientException;
|
|
use AlibabaCloud\Client\Exception\ServerException;
|
|
use think\facade\Log;
|
|
|
|
class SendSms
|
|
{
|
|
|
|
public function send($toNum, $content, $accessKey, $secret)
|
|
{
|
|
|
|
try {
|
|
// LTAI5t66pUgcFJBMGHamFoxJ
|
|
// BxHnmVDiXvOrnxbAfOPvP6jibJL6pp
|
|
AlibabaCloud::accessKeyClient($accessKey, $secret)
|
|
->regionId('ap-southeast-1')
|
|
->asDefaultClient();
|
|
|
|
$result = AlibabaCloud::rpcRequest()
|
|
->product('Dysmsapi')
|
|
->host('dysmsapi.ap-southeast-1.aliyuncs.com')
|
|
->version('2018-05-01')
|
|
->action('SendMessageToGlobe')
|
|
->method('POST')
|
|
->options([
|
|
'query' => [
|
|
"To" => $toNum,
|
|
"Message" => $content,
|
|
],
|
|
])
|
|
->request();
|
|
|
|
$res = $result->toArray();
|
|
|
|
Log::error("----sms_send-----".json_encode([$res]));
|
|
if(!isset($res['ResponseCode']) || $res['ResponseCode'] != 'OK'){
|
|
trace('短信发送失败00_'.json_encode([$res]), 'error');
|
|
}
|
|
return true;
|
|
|
|
}catch (ClientException $clientException) {
|
|
trace('短信发送失败01_'.$clientException->getMessage(), 'error');
|
|
}catch (ServerException $serverException) {
|
|
trace('短信发送失败02_'.$serverException->getMessage(), 'error');
|
|
}catch (\Exception $exception) {
|
|
trace('短信发送失败03_'.$exception->getMessage(), 'error');
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|