小白兔晒黑了

导航

 
<?php

interface Strategy
{
  public function send_code($code);
}

class messageStrategy implements Strategy
{
  public function send_code($code)
  {
    return "短信已发送";
  }
}

class emailStrategy implements Strategy
{
  public function send_code($code)
  {
    return "邮件已发送";
  }
}

class weixinStrategy implements Strategy
{
  public function send_code($code)
  {
    return "微信已发送";
  }
}


class sendCode
{
  private $strategyInstance;
  public function __construct ($instance)
  {
    $this->strategyInstance = $instance;
  }
 
  public function send($code)
  {
    return $this->strategyInstance->send_code($code);
  }
}


$type = $_GET('type');

if($type=='weixin'){
    $instance = new weixinStrategy();
}elseif($type=='message'){
    $instance = new messageStrategy();
}elseif ($type=='email') {
    $instance = new emailStrategy();
}



$class = new sendCode($instance);
$code =  rand(10000,99999);
$class->send($code);


?>




1 使用场景说明
用户注册/登录/忘记密码三种情况下,需要发送验证码

2 接口说明
   后台系统实现推送验证码功能,支持短信/邮件/微信模版消息。

3  请求参数
type:发送的类型 weixin 或 message 或 email

 

posted on 2019-10-31 11:48  小白兔晒黑了  阅读(401)  评论(0)    收藏  举报