曹え 5811 发布于:2021-12-10 08:48:39
1、后台安装sms插件
2、修改文件 /Home/plugins/MsgController.php
使用方法
短信接口
/msg/index
邮件推送接口
/msg/gomail
代码内容
<?php namespace Homeplugins; use HomecCommonController; use FrPHPExtendPage; use FrPHPExtendArrayPage; class MsgController extends CommonController { function _init(){ parent::_init(); $w['filepath'] = 'aliyunsms'; $w['isopen'] = 1; $res = M('plugins')->find($w); if(!$res){ JsonReturn(['code'=>1,'msg'=>'短信插件未开启!']); } $res['config'] = json_decode($res['config'],1); $this->plugin = $res; require_once APP_PATH.'aliysms/api_demo/SmsDemo.php'; SmsDemo::setdata($res['config']['AccessKeyId'],$res['config']['accessKeySecret'],$res['config']['SignName'],$res['config']['templatecode']); } function index(){ $yzmname = $this->frparam('codename',1); $yzm = $this->frparam('yzm',1); if(!$yzm || md5(md5($yzm))!=$_SESSION[$yzmname]){ JsonReturn(['code'=>1,'msg'=>'验证码错误!']); } $tel = $this->frparam('tel',1); if(preg_match("/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])d{8}$/",$tel)){ }else{ JsonReturn(['code'=>1,'msg'=>'手机号格式错误!']); } $code = rand(100000,999999); $_SESSION['tel_code'] = $code; $response = SmsDemo::sendSms($tel,$code); //echo "发送短信(sendSms)接口返回的结果: "; //print_r($response); if($response->Code=='OK'){ JsonReturn(['code'=>0,'msg'=>'发送成功!']); }else{ JsonReturn(['code'=>1,'msg'=>$response->Message]); } } function gomail(){ $email = $this->frparam('email',1); $code = rand(100000,999999);//生成验证码 $_SESSION['email_code'] = $code; $user = M('member')->find(['email'=>$email]); if($user){ //生成随机秘钥 $w['logintime'] = time(); $w['token'] = getRandChar(32); M('member')->update(['id'=>$user['id']],$w); //发送邮件 if($this->webconf['email_server'] && $this->webconf['email_port'] && $this->webconf['send_email'] && $this->webconf['send_pass']){ $title = '找回密码-'.$this->webconf['web_name']; $body = '您的账号正在进行找回密码操作,如果确定是本人操作,请在1分钟内输入'.$code.'验证码,过期失效!'; $fan = send_mail($this->webconf['send_email'],$this->webconf['send_pass'],$this->webconf['send_name'],$user['email'],$title,$body); if(!isset($_SESSION['forget_time'])){ $_SESSION['forget_time'] = time(); $_SESSION['forget_num'] = 0; } if(($_SESSION['forget_time']+10*60)<time()){ $_SESSION['forget_num'] = 0; $_SESSION['forget_time'] = time(); } $_SESSION['forget_num']++; if($_SESSION['forget_num']>5 && ($_SESSION['forget_time']+10*60)>time()){ JsonReturn(['code'=>0,'msg'=>'您操作过于频繁,请10分钟后再尝试!']); } JsonReturn(['code'=>1,'msg'=>'找回密码邮件已发送,请到您的邮箱查看!'.$fan]); }else{ JsonReturn(['code'=>0,'msg'=>'邮箱服务器未配置,无法发送邮件,请联系管理员找回密码!']); } }else{ JsonReturn(['code'=>0,'msg'=>'该用户不存在!']); } } }
登录后可以留言提问!
微信扫码登录