• composer安装阿里云短信


    • 环境准备

    • 安装composer并切换到阿里云源

    • cd到项目根目录

    • 根据阿里云示例安装 composer require alibabacloud/smsintl

    • 直接在api/controller/common源码里引用

    •   use AlibabaCloudClientAlibabaCloud;
        use AlibabaCloudClientExceptionClientException;
        use AlibabaCloudClientExceptionServerException;
        public function smsaliyun(){
                $req = $this->request->param();
                $vali = $this->validate($req, [
                    'mobile' => 'require|integer',
                    'code' => 'require|integer',
                ]);
                if (true !== $vali) {
                    $this->error('参数错误', $vali);
                }
                AlibabaCloud::accessKeyClient('akey', 'skey')
                    ->regionId('cn-hangzhou')
                    ->asDefaultClient();
                try {
                    $result = AlibabaCloud::rpc()
                        ->product('Dysmsapi')
                        // ->scheme('https') // https | http
                        ->version('2017-05-25')
                        ->action('SendSms')
                        ->method('POST')
                        ->host('dysmsapi.aliyuncs.com')
                        ->options([
                            'query' => [
                                'RegionId' => "cn-hangzhou",
                                'PhoneNumbers' => $req['mobile'],
                                'SignName' => "掌上医堂",
                                'TemplateCode' => "SMS_199920034",
        //                        'TemplateParam' => "{"code":"123456"}",
                                'TemplateParam' => "{"code":"".$req['code'].""}",
                            ],
                        ])
                        ->request();
                     $this->success('发送成功', $result->toArray());
                } catch (ClientException $e) {
                    $this->error('发送失败',$e->getErrorMessage() . PHP_EOL);
                } catch (ServerException $e) {
                    $this->error('发送失败',$e->getErrorMessage() . PHP_EOL);
                }
            }
      
  • 相关阅读:
    174. Dungeon Game
    240. Search a 2D Matrix II
    300. Longest Increasing Subsequence
    test markdown style
    多源多汇费用流——poj2516
    费用流消圈算法(构造残量网络)
    费用流模板(带权二分图匹配)——hdu1533
    最大流模板——进阶指南整理
    最大流任务调度+离散化——hdu2883
    最大流拆点——hdu2732,poj3436
  • 原文地址:https://www.cnblogs.com/bufeetu/p/13780642.html
Copyright © 2020-2023  润新知