赞
踩
1、按照阿里的模版进行安装,composer require alibabacloud/dysmsapi-20170525 2.0.24 直接安装,组成的接口,封转的方法,提示报错,分析原因,发现是版本有问题,需要下载指定的版本:
composer require alibabacloud/dysmsapi-20170525 2.0.20
2、将下载的组件全部清理了,然后再重新按照新的版本;该代码是写在common.php里面的,上面加载对应的配置
代码实例:
- use Darabonba\OpenApi\Models\Config as Dconfig;
- use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
- use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
- use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
-
-
- /**
- * 阿里大于短信发送新版
- */
- function sendsms($phone, $code, $type="SMS_154950909", $flag = 'single')
- {
-
- $option = Config::get('applet.sms');
- $config = new Dconfig([
- // 必填,您的 AccessKey ID
- "accessKeyId" => $option['sms_key'],
- // 必填,您的 AccessKey Secret
- "accessKeySecret" => $option['sms_secret'],
- ]);
- $config->endpoint = "dysmsapi.aliyuncs.com";
- $client = new Dysmsapi($config);
- $sendSmsRequest = new SendSmsRequest(
- [
- "signName" => $flag,
- "templateCode" => $type,
- "phoneNumbers" => $phone,
- "templateParam" => "{\"code\":\"$code\"}"
- ]
- );
-
- $runtime = new RuntimeOptions([]);
- try {
- // 复制代码运行请自行打印 API 的返回值
- $a = $client->sendSmsWithOptions($sendSmsRequest, $runtime);
- return 1;
- }
- catch (Exception $error) {
- if (!($error instanceof TeaError)) {
- // $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
- }
- // 如有需要,请打印 error
- return 0;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。