star7th 6 år sedan
förälder
incheckning
a9376b61b4

BIN
Sqlite/showdoc.db.php


+ 37 - 0
server/Application/Api/Controller/CommonController.class.php

@@ -41,4 +41,41 @@ class CommonController extends BaseController {
       ImageDestroy($im);
     }
 
+    public function createCaptcha(){
+        $captcha = rand(1000, 9999) ;
+        $data = array(
+          "mobile" =>"",
+          "captcha" =>$captcha,
+          "expire_time" =>time()+60*10,
+          );
+        $captcha_id = D("Captcha")->add($data);
+        $this->sendResult(array("captcha_id"=>$captcha_id));
+    }
+
+    public function showCaptcha(){
+      $captcha_id = I("captcha_id/d");
+      $captcha = D("Captcha")->where("captcha_id = '$captcha_id' ")->find();
+
+      $numArray  = array_map('intval', str_split($captcha['captcha']));
+      //生成验证码图片
+      Header("Content-type: image/PNG");
+      $im = imagecreate(44,18); // 画一张指定宽高的图片
+      $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色
+      imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中
+      srand((double)microtime()*1000000);
+      //生成4位数字
+      for($i=0;$i<4;$i++){
+        $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色
+        imagestring($im, 5, 2+$i*10, 1, $numArray[$i], $font);
+      }
+      for($i=0;$i<200;$i++) //加入干扰象素
+      {
+        $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
+        imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数
+      }
+      ImagePNG($im);
+      ImageDestroy($im);
+
+    }
+    
 }

+ 23 - 0
server/Application/Api/Model/CaptchaModel.class.php

@@ -0,0 +1,23 @@
+<?php
+namespace Api\Model;
+use Api\Model\BaseModel;
+/**
+ * 
+ * @author star7th      
+ */
+class CaptchaModel extends BaseModel {
+
+	public function check($captcha_id , $captcha){
+		$time = time() ;
+		$captcha_array = $this->where(" captcha_id = '$captcha_id' and expire_time > $time ")->find();
+		if ($captcha_array['captcha'] && $captcha_array['captcha'] == $captcha) {
+			//检查完就设置该验证码过期
+			$this->where(" captcha_id = '$captcha_id'")->save(array("expire_time"=>0));
+			return true ;
+		}else{
+			//删除掉所有过期的二维码
+			//$this->where(" expire_time < '$time' ")->delete();
+		}
+		return false;
+	}
+}

+ 11 - 1
server/Application/Home/Controller/UpdateController.class.php

@@ -215,7 +215,17 @@ class UpdateController extends BaseController {
         `unique_key` CHAR(200) NOT NULL DEFAULT '',
         `page_id` int(11) NOT NULL DEFAULT '0'
         )";
-        D("UserToken")->execute($sql);
+        D("User")->execute($sql);
+
+        //创建captcha表
+        $sql = "CREATE TABLE IF NOT EXISTS `captcha` (
+        `captcha_id`  INTEGER PRIMARY KEY ,
+        `mobile` CHAR(200) NOT NULL DEFAULT '',
+        `captcha` CHAR(200) NOT NULL DEFAULT '',
+        `expire_time` int(11) NOT NULL DEFAULT '0'
+        )";
+        D("User")->execute($sql);
+
 
         echo "OK!\n";
     }