First go to Aliyun application account (background address: https://www.aliyun.com/, note is not more than Ali SMS platform, Ali is more than has stopped the new user registration), login to the console, to create keyID and Keysecret.
Download SDK from Aliyun SMS website (https://help.aliyun.com/document_detail/55359.html?spm=5176.8195934.507901.12.2NiZni)
Place the SDK in the vendor directory of the THINKPHP5 framework, as shown in the following figure:
Send SMS code as follows:
Private Function Sendsmsbyaliyun () {include_once './vendor/aliyun-php-sdk-core/config.php ';
Include_once './vendor/dysmsapi/request/v20170525/sendsmsrequest.php '; $accessKeyId = $this->config[' sms_appkey '];//aliyun sms keyID $accessKeySecret = $this->config[' Sms_secretkey '];//
Aliyun SMS Keysecret//SMS API Product Name $product = "Dysmsapi";
SMS API product Domain name $domain = "Dysmsapi.aliyuncs.com";
Region $region = "Cn-hangzhou" is not supported at the moment;
Initialize access to the Acscleint $profile = \defaultprofile::getprofile ($region, $accessKeyId, $accessKeySecret);
\defaultprofile::addendpoint ("Cn-hangzhou", "Cn-hangzhou", $product, $domain);
$acsClient = new \defaultacsclient ($profile);
$request = new \dysmsapi\request\v20170525\sendsmsrequest; $request->setphonenumbers ("138xxx");/required-SMS Receive number $request->setsignname ("xxxx");/required-Short message signature: How to add a signature can refer to Aliyun SMS or T Pshop Official Document//required-SMS template code $requeSt->settemplatecode ("Modify mobile phone number");/required-Short message signature: How to add a signature can refer to Aliyun SMS or Tpshop Official document/optional-required (JSON format) if there are variables in the template that need to be replaced $req
Uest->settemplateparam ("{\" code\ ": \" 4894\ "}");//SMS Signature content://optional-send SMS Serial number//$request->setoutid ("1234");
Initiating an access request $RESP = $acsClient->getacsresponse ($request); SMS sent successfully returns TRUE, Failure returns False if ($resp && $resp->code = = ' OK ') {return array (' status ' => 1,
' msg ' => $resp->code); else {return array (' status ' =>-1, ' msg ' => $resp->message. ' Subcode: '.
$resp->code);
}
}
Note that you must add "./" to the SDK file that references Aliyun SMS, or you may not find the PHP file.
After integration, the test results are as follows
For full demo download address, please go to tpshop website to download the open source version