Blogger Information
Blog 5
fans 0
comment 0
visits 5847
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
阿里云短信
毅铭
Original
804 people have browsed it

<?php

require_once(‘引入你自己的’);
use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Console\Console;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;

class SmsSingleSender {

  1. /**
  2. * 使用AK&SK初始化账号Client
  3. * @param string $accessKeyId
  4. * @param string $accessKeySecret
  5. * @return Dysmsapi Client
  6. */
  7. public static function createClient(){
  8. $config = new Config([
  9. // 您的AccessKey ID
  10. "accessKeyId" => "你自己的ID",
  11. // 您的AccessKey Secret
  12. "accessKeySecret" => "你自己的KEY"
  13. ]);
  14. // 访问的域名
  15. $config->endpoint = "dysmsapi.aliyuncs.com";
  16. return new Dysmsapi($config);
  17. }
  18. /**
  19. * @param string[] $args
  20. * @return void
  21. */
  22. public static function main($mobile,$code){
  23. $client = self::createClient();
  24. $templ = ['code'=>$code];
  25. $sendSmsRequest = new SendSmsRequest([
  26. "phoneNumbers" => $mobile,
  27. "signName" => "你自己的",
  28. "templateCode" => "你自己的",
  29. "templateParam" => json_encode($templ)
  30. ]);
  31. $resp = $client->sendSms($sendSmsRequest);
  32. if ($resp->body->code =="OK" && $resp->body->message =="OK" ){
  33. return true;
  34. }
  35. return false;
  36. }

}
$path = DIR . \DIRECTORY_SEPARATOR . ‘..’ . \DIRECTORY_SEPARATOR . ‘vendor’ . \DIRECTORY_SEPARATOR . ‘autoload.php’;
if (file_exists($path)) {
require_once $path;
}

  1. //接收参数
  2. public function index(){
  3. $mobile = request()->get('mobile/s','');
  4. if (empty($mobile)) throw new ErrorException(['msg'=>"手机号不能为空"]);
  5. $code = rand(111111,999999);
  6. $res=(new \app\api\service\SendSms())->send($mobile,$code);
  7. $res = json_decode($res,true);
  8. if ($res['SendStatusSet'][0]['Code'] =="Ok") {
  9. cache($mobile,$code,300);
  10. return json(['code'=>200,'msg'=>"发送成功"]);
  11. }
  12. return json(['code'=>201,'msg'=>"ok"]);
  13. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post