<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ``` composer require alibabacloud/client ``` v1.5.29 ## **步驟:** 1. 設置全局客戶端 ~~~php AlibabaCloud::accessKeyClient() ~~~ 2. 創建對應 API 的 Request 。 ``` $request=AlibabaCloud::rpc() //or $request=AlibabaCloud::roa() ``` 3. 設置選項/參數并執行請求 ``` //rpc時 $result =$request ->product('Dysmsapi') // ->scheme('https') // https | http ->version('2017-05-25') ->action('SendSms') ->method('POST') ->host('dysmsapi.aliyuncs.com') ->options([ 'query' => [ 'RegionId' => "cn-hangzhou", 'PhoneNumbers' => $config['test_mobile'], 'SignName' => $config['signName'], 'TemplateCode' => $config['templateCode'], 'TemplateParam' => $code, ], ]) ->request(); ``` 4. 打印 API 返回結果。 ``` print_r($result->toArray()); ``` 5. 客戶端報錯 ~~~php catch (ClientException $exception) { echo $exception->getMessage(). PHP_EOL; } ~~~ 6. 服務端報錯 ~~~php catch (ServerException $exception) { echo $exception->getMessage() . PHP_EOL; echo $exception->getErrorCode(). PHP_EOL; echo $exception->getRequestId(). PHP_EOL; echo $exception->getErrorMessage(). PHP_EOL; } ~~~ ## **示例:** ~~~ <?php // 應用公共文件 use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; /** * 驗證碼(阿里云短信) */ function smsVerify($mobile, $code, $tempId) { AlibabaCloud::accessKeyClient(config('app.aliyunsms.access_key_id'), config('app.aliyunsms.access_key_secret')) ->regionId('cn-hangzhou') //replace regionId as you need(這個地方是發短信的節點,默認即可,或者換成你想要的) ->asGlobalClient(); $data = []; try { $result = AlibabaCloud::rpcRequest() ->product('Dysmsapi') //->scheme('https') //https | http(如果域名是https,這里記得開啟) ->version('2017-05-25') ->action('SendSms') ->method('POST') ->options([ 'query' => [ 'PhoneNumbers' => $mobile, 'SignName' => config('app.aliyunsms.sign_name'), 'TemplateCode' => $tempId, 'TemplateParam' => json_encode(['code'=>$code]), ], ]) ->request(); $res = $result->toArray(); if($res['Code'] == 'OK'){ $data['status'] = 1; $data['info'] = $res['Message']; }else{ $data['status'] = 0; $data['info'] = $res['Message']; } return $data; } catch (ClientException $e) { $data['status'] = 0; $data['info'] = $e->getErrorMessage(); return $data; } catch (ServerException $e) { $data['status'] = 0; $data['info'] = $e->getErrorMessage(); return $data; } } ~~~ 復制以上代碼,配置換成自己的即可使用,當然,配置也可以放到數據庫里。 3.在需要的地方調用這個方法即可: 我這里是ajax調用的,所以返回值是json格式。 ~~~ $code = rand_string(4,1);//這里是隨機生成4位數字,這個方法是我自己寫的哦,要注意! $res = smsVerify($mobile, $code, 'SMS_113461246'); if($res['status'] == 1){ Session::set($mobile.'code',$code); ajaxReturn(1,"驗證碼已發送"); }else{ ajaxReturn(0,"驗證碼發送失敗,請聯系客服"); } ~~~ 這樣就好了,驗證碼發送的功能就完成了! ## **舊版含有`Dysmsap`類時的示例** ~~~php use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; use AlibabaCloud\Dysmsapi\Dysmsapi; // 設置全局客戶端 AlibabaCloud::accessKeyClient('<your-access-key-id>', '<your-access-key-secret>') ->regionId('cn-hangzhou') ->asDefaultClient(); try { // 訪問產品 APIs $request = Dysmsapi::v20170525()->addShortUrl(); // 設置選項/參數并執行請求 $result = $request ->withResourceOwnerAccount("your_value") // 該參數 ResourceOwnerAccount 值為假設值,請您根據實際情況進行填寫 ->withResourceOwnerId(1) // 該參數 ResourceOwnerId 值為假設值,請您根據實際情況進行填寫 ->withSourceUrl("your_value") // 該參數 SourceUrl 值為假設值,請您根據實際情況進行填寫 ->withShortUrlName("your_value") // 該參數 ShortUrlName 值為假設值,請您根據實際情況進行填寫 ->client('client1') // 指定發送客戶端,否則使用全局客戶端 ->debug(true) // 開啟調試會輸出詳細信息 ->connectTimeout(0.01) // 連接超時會拋出異常 ->timeout(0.01) // 超時會拋出異常 ->request(); // 執行請求 // 打印 API 返回結果 print_r($result->toArray()); } catch (ClientException $exception) { echo $exception->getMessage() . PHP_EOL; } catch (ServerException $exception) { echo $exception->getMessage() . PHP_EOL; echo $exception->getErrorCode() . PHP_EOL; echo $exception->getRequestId() . PHP_EOL; echo $exception->getErrorMessage() . PHP_EOL; } ~~~ ``` <?php use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; use AlibabaCloud\Dysmsapi\Dysmsapi; // Download:https://github.com/aliyun/openapi-sdk-php // Usage:https://github.com/aliyun/openapi-sdk-php AlibabaCloud::accessKeyClient('<your-access-key-id>', '<your-access-key-secret>') // use STS Token // AlibabaCloud::stsClient('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>') ->regionId('cn-hangzhou') ->asDefaultClient(); try { $request = Dysmsapi::v20170525()->sendSms(); $result = $request ->debug(true) // Enable the debug will output detailed information ->connectTimeout(1) // Throw an exception when Connection timeout ->timeout(1) // Throw an exception when timeout ->request(); print_r($result->toArray()); } catch (ClientException $exception) { echo $exception->getMessage() . PHP_EOL; } catch (ServerException $exception) { echo $exception->getMessage() . PHP_EOL; echo $exception->getErrorCode() . PHP_EOL; echo $exception->getRequestId() . PHP_EOL; echo $exception->getErrorMessage() . PHP_EOL; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看