regionId('ap-southeast-1') ->asDefaultClient(); // $result = AlibabaCloud::rpc() // ->product('Dysmsapi') // 短信服务的产品名称 // ->version('2017-05-25') // API 版本 // ->action('SendSms') // 调用 SendSms 接口 // ->method('POST') // ->host('dysmsapi.ap-southeast-1.aliyuncs.com') // 短信服务的域名 // ->options([ // 'query' => [ // 'RegionId' => 'ap-southeast-1', // 区域 ID // 'PhoneNumbers' => $toNum, // 接收短信的手机号 多个号码用逗号分隔 // 'SignName' => $content, // 短信签名名称 短信签名名称,在阿里云控制台中创建。 // 'TemplateCode' => 'SMS_1234567', // 短信模板 ID, 短信模板 ID,在阿里云控制台中创建。 // 'TemplateParam' => json_encode(['code' => '123456']), // 模板参数(JSON 格式) 短信模板中的变量参数,以 JSON 格式传递(如验证码、动态内容等)。 // ], // ]) // ->request(); $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("----发送短信结果-----".json_encode([$res])); if(!isset($res['ResponseCode']) || $res['ResponseCode'] != 'OK'){ trace('短信发送失败:'.json_encode([$res]), 'error'); } return true; }catch (ClientException $clientException) { trace('短信发送失败01_'.$clientException->getMessage(), 'error'); }catch (ServerException $serverException) { trace('短信发送失败02_'.$serverException->getErrorMessage(), 'error'); }catch (\Exception $exception) { trace('短信发送失败03_'.$exception->getMessage(), 'error'); } return false; } }