Thinkphp5对接阿里云短信接口,不使用官方demo

Thinkphp5对接阿里云短信接口,不使用官方demo

阿里云提供的最新对接api 个人感觉太过复杂不是很容易懂,所以根据官方接口和网上的资料整合一下阿里云发送短信的接口。

/**
 * @xk 重新定义阿里云相关接口 api 第一个就是阿里云相关短信接口
 * 包含短信的验证码发送和通知类的短信
 * @actor xingkongyinzhe
 * @time 2019-11-13 周三 青岛 天气 小雨转多云
 * @var [type]
 */
namespace app\index\controller;
use think\Controller;
use think\Session;
use think\Db;

/**
 * @xk 开始执行定义短信发送方案
 */
class Aliyun extends Controller
{
   
    /**
     * 构造公共函数
     */
    function __construct(){
   
      $this->al_id = ''; //阿里云ID
      $this->al_access = ''; //阿里云密钥
      $this->al_signName = ''; //阿里云配置的模板名称
      $this->al_signCode = ''; //阿里云模板ID  阿里云通知短信模板
      $this->al_signMsgCode = ''; //阿里云通知短信模板
      $this->al_version = '2017-05-25'; //阿里云版本号
    }
    /**
     * @xk 发送验证码 使用阿里云相关短信接口
     * @param  [type] $phone
     * @return [type]        [description]
     */
    public function sendCode($phone=''){
   
      if(!preg_match("/^1[34578]{1}\d{9}$/",$phone)){
   
        return Json(array('code'=>0,'msg'=>'手机号格式错误'));
        exit();
      }
      $code = rand(1111,9999);
      $templateparam = [
        'code'=>$code
      ];
      $params = 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值