Ali cloud (international edition) official documentation: www.alibabacloud.com/help/zh/doc…

Note: Ali cloud accounts (domestic version, international version), different accounts to send SMS SDK is not the same

The SDK download is slow, so be patient

The international SDK is downloaded using the Composer command (There are other ways. I haven’t tried), if you are using a TP framework and can download the composer using the composer command, you may not be able to download the composer.

Find a separate empty folder and download it using composer command. Place it under your framework’s third-party file or vendor folder to use

Composer Download SDK command:

composer require alibabacloud/client
Copy the code

SDK download will appear the following 2 files a folder

Next we will create a demo.php file that can be copied from the official documentation

www.alibabacloud.com/help/zh/doc…

Here is the code for the demo.php file:

Note ** : Be sure to use “require_once” to import autoload.php from the vendor folder of the SDK you downloaded, otherwise you will not find the classes that you can instantiate

require_once dirname(__DIR__) . '/aliyun_sdk_guojiban/vendor/autoload.php'; <? php require_once dirname(__DIR__) . '/aliyun_sdk_guojiban/vendor/autoload.php'; use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; Class Aliyungj {/* international -- no template code and signature required, Message templates define your own * / public function sendSms ($phone, $code) {AlibabaCloud: : accessKeyClient ($accessKeyId, $accessKeySecret) ->regionId('ap-southeast-1') ->asGlobalClient(); $code = '.$code.', enter within 10 minutes, do not disclose to others '; // This is the SMS template. $result = AlibabaCloud::rpcRequest() ->product('Dysmsapi') ->host(' dysmSAPi.ap-southeast-1.aliyuncs.com ') ->version('2018-05-01') -> Action ('SendMessageToGlobe')// Request API name - > method (" POST ") - > options ([' query '= > [" To "= >" $" phone, / / receiving phone number "Message" = > $code, / / receive verification code],]) - > request (); return \GuzzleHttp\json_decode($result); } catch (ClientException $e) { echo $e->getErrorMessage() . PHP_EOL; } catch (ServerException $e) { echo $e->getErrorMessage() . PHP_EOL; }} / * domestic - template code and signature * / public function gn_sendSms ($phone, $code) {AlibabaCloud: : accessKeyClient (' $accessKeyId ', '$accessKeySecret') ->regionId('ap-southeast-1') ->asGlobalClient(); try { $result = AlibabaCloud::rpcRequest() ->product('Dysmsapi') ->host('dysmsapi.ap-southeast-1.aliyuncs.com') ->action('SendMessageWithTemplate') ->method('POST') ->options(['query' => ["From") Signature = > ", "/ /" TemplateCode "= >", "/ / template code" To "= >" $" phone, / / receiving phone number "TemplateParam" = > '{" code ":"'. $code. '"}', / / verification code], ]) ->request(); return \GuzzleHttp\json_decode($result); } catch (ClientException $e) { echo $e->getErrorMessage() . PHP_EOL; } catch (ServerException $e) { echo $e->getErrorMessage() . PHP_EOL; } } } $Aliyungj = new Aliyungj; $phone = ''; $code = '1111'; $code = '1111'; //$res = $Aliyungj->sendSms($phone,$code); $res = $Aliyungj->gn_sendSms($phone,$code); var_dump($res);Copy the code

The following are other interfaces called by the official API. Modify the demo request parameters and request interface names according to different API interface request parameters

www.alibabacloud.com/help/zh/doc…