1.手机验证码登录
public function login(Request $request){
$tel=$request->get('phoneNum');
if (Cache::has($tel)){
$num=Cache::get($tel);
}else{
$num=Cache::put($tel,0);
}
if ($num>30){
return $this->getJsonData(10010,'一天只能请求30次',null);
}
$smsapi = $this->smsapi;
$user = $this->user;
$pass = md5($this->pass);
$rand=rand(1000,9999);
$content="【八维】:您的验证码:".$rand;
$phone = $tel;
$sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
$result =file_get_contents($sendurl) ;
if ($result!=0){
Cache::increment($tel,1);
Cache::put('code',$rand);
return $this->getJsonData(200,'获取成功',$rand);
}else{
return $this->getJsonData(500,'获取失败',null);
}
}
public function logindo(Request $request){
$phone=$request->get('phone');
$code=$request->get('xcode');
$session_code=Cache::get('code');
$user=WechatUser::where('phone',$phone)->first()->toArray();
$token = $this->createToken($user['id']);
if ($code==$session_code){
return $this->getJsonData(200,'登录成功',$token);
}else{
return $this->getJsonData(500,'登录失败',null);
}
}
$('#dyMobileButton').click(function () {
var time = 60;
var phone = $('#prependedInput').val();
setInterval(function () {
time--;
if (time > 0) {
$('#dyMobileButton').html('重新发送(' + time + ')秒');
$('#dyMobileButton').prop('disabled', true);
} else {
$('#dyMobileButton').html('发送验证码');
$('#dyMobileButton').prop('disabled', false);
}
}, 1000);
2.ajax上传 接值还是input接
<script>
$('#button').click(function () {
var token="{$Think.session.token}";
var name=$('#name').val();
var price=$('#price').val();
var formData=new FormData();
var img=document.getElementById('img').files[0];
formData.append('name',name);
formData.append('price',price);
formData.append('img',img);
$.ajax({
url:"/addajax?token="+"{$Think.session.token}",
data:formData,
type:'post',
dataType:'json',
processData:false,
contentType:false,
success:function (res) {
if (res.code==200){
alert(res.msg);
location.href="/show?token="+token;
}
}
})
})
</script>
3.七牛云上传 接收文件值只能用$_FILES接值,否则tp框架接值需要处理接到的值。files[‘tmp_name’]一定要看清接到的值。imageurl是在线地址。
$file = $_FILES;
$localFilePath = $file['img']['tmp_name'];
$suffix = strtolower(substr($file['img']['name'],strpos($file['img']['name'],'.')));
$fileName = md5($file['img']['name']) . date('s',time()) . rand(1,9999999);
$fileName .= $suffix;
$accessKey = 'FNbcGeNVSydTXAmq5gp';
$secretKey = 'zA8AeRR0j9Tf1KlUgEc';
$auth = new Auth($accessKey, $secretKey);
$bucket = 'gaodewen';
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, $fileName, $localFilePath);
if ($err != null) {
$this->error('上传文件失败');
}
$imageUrl = 'http://qwot0f374.hd-bkt.clouddn.com/' . $fileName;
$data['img']=$imageUrl;
$res=\app\admin\model\Goods::add($data);
$token=session('token');
if ($res){
return $this->success('添加成功','/show?token='.$token);
}
3.layui搜索展示和分页 layui引用官网的模板,写上容器ID,limit,limits,三个参数。表单字段改成自己对应的字段,去掉下面的key,加上where
public function getShow(){
$page=input('page')? input('page') :1;
$limit=input('limit')? input('limit') :3;
$offset=($page-1)*$limit;
$where=[];
$key=input('name')? input('name'): [];
if (!empty($key)){
$where['name']=['like','%'.$key.'%'];
}
$count=\app\admin\model\Goods::getCount($offset,$limit,$where);
$data=\app\admin\model\Goods::show($offset,$limit,$where);
return getJsonData(0,'查询成功',$data,$count);
}