tp项目引入阿里云短信sdk流程
composer require alibabacloud/darabonba-openapi
下载完成之后在控制器中引入
require_once realpath(__ROOT__) . '/vendor/autoload.php';
use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use \Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
public function send(){
$gpc = I('request.');
$code = mt_rand(999,9999);
$phone=$gpc['phone'];
$signName='无尽商城';
$templateCode='SMS_123456';
$config = new Config([
"accessKeyId" => "123213213",
"accessKeySecret" => "1231323dvdvdesf"
]);
$config->endpoint = "dysmsapi.aliyuncs.com";
$client = new Dysmsapi($config);
$sendSmsRequest = new SendSmsRequest([
"phoneNumbers" => trim($phone),
"signName" => $signName,
"templateCode" => $templateCode,
"templateParam" => "{\"code\":\"".$code."\"}"
]);
$data = $client->sendSms($sendSmsRequest);
if($data->body->code=='OK'){
session($phone,$code);
echo json_encode(['error_code'=>0,'msg'=>'发送短信成功']);
}else{
echo json_encode(['error_code'=>1,'msg'=>'发送短信失败']);
}
}
在此记录一下
|