php版本大于5.6
执行命令
Composer
composer require alibabacloud/dysmsapi-20170525
然后自己定义个php的控制器
<?php // This file is auto-generated, don't edit it. Thanks. namespace AlibabaCloud\SDK\Sample; use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi; use \Exception; use AlibabaCloud\Tea\Exception\TeaError; use AlibabaCloud\Tea\Utils\Utils; use Darabonba\OpenApi\Models\Config; use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest; use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; class Sample { /** * 使用AK&SK初始化账号Client * @param string $accessKeyId * @param string $accessKeySecret * @return Dysmsapi Client */ public static function createClient($accessKeyId, $accessKeySecret){ $config = new Config([ // 必填,您的 AccessKey ID "accessKeyId" => $accessKeyId, // 必填,您的 AccessKey Secret "accessKeySecret" => $accessKeySecret ]); // 访问的域名 $config->endpoint = "dysmsapi.aliyuncs.com"; return new Dysmsapi($config); } /** * @param string[] $args * @return void */ public static function main($args){ // 工程代码泄露可能会导致AccessKey泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/311677.html $client = self::createClient("accessKeyId", "accessKeySecret"); $sendSmsRequest = new SendSmsRequest([]); $runtime = new RuntimeOptions([]); try { // 复制代码运行请自行打印 API 的返回值 $client->sendSmsWithOptions($sendSmsRequest, $runtime); } catch (Exception $error) { if (!($error instanceof TeaError)) { $error = new TeaError([], $error->getMessage(), $error->getCode(), $error); } // 如有需要,请打印 error Utils::assertAsString($error->message); } } } $path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php'; if (file_exists($path)) { require_once $path; } Sample::main(array_slice($argv, 1));
好了,就是这么简单,配置下自己的参数即可
标签:短信,接入,accessKeySecret,阿里,SEPARATOR,error,DIRECTORY,new,path From: https://www.cnblogs.com/sjiatong/p/17219471.html