您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

103 行
3.4 KiB

  1. <?php
  2. namespace Api\Controller;
  3. use Think\Controller;
  4. class CommonController extends BaseController {
  5. //生成二维码
  6. public function qrcode(){
  7. Vendor('Phpqrcode.phpqrcode');
  8. $url = I("url");
  9. $url = urldecode($url) ? urldecode($url) : $url;
  10. $size = I("size") ? I("size") : 6;
  11. $object = new \QRcode();
  12. $object->png($url, false, 3 , $size, 2);
  13. }
  14. //生成验证码
  15. public function verify(){
  16. //生成验证码图片
  17. Header("Content-type: image/PNG");
  18. $im = imagecreate(44,18); // 画一张指定宽高的图片
  19. $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色
  20. imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中
  21. $vcodes = "";
  22. srand((double)microtime()*1000000);
  23. //生成4位数字
  24. for($i=0;$i<4;$i++){
  25. $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色
  26. $authnum=rand(1,9);
  27. $vcodes.=$authnum;
  28. imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
  29. }
  30. $_SESSION['v_code'] = $vcodes;
  31. for($i=0;$i<200;$i++) //加入干扰象素
  32. {
  33. $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
  34. imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数
  35. }
  36. ImagePNG($im);
  37. ImageDestroy($im);
  38. }
  39. public function createCaptcha(){
  40. $captcha = rand(1000, 9999) ;
  41. $data = array(
  42. "mobile" =>"",
  43. "captcha" =>$captcha,
  44. "expire_time" =>time()+60*10,
  45. );
  46. $captcha_id = D("Captcha")->add($data);
  47. $this->sendResult(array("captcha_id"=>$captcha_id));
  48. }
  49. public function showCaptcha(){
  50. $captcha_id = I("captcha_id/d");
  51. $captcha = D("Captcha")->where("captcha_id = '$captcha_id' ")->find();
  52. $numArray = array_map('intval', str_split($captcha['captcha']));
  53. //生成验证码图片
  54. Header("Content-type: image/PNG");
  55. $im = imagecreate(44,18); // 画一张指定宽高的图片
  56. $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色
  57. imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中
  58. srand((double)microtime()*1000000);
  59. //生成4位数字
  60. for($i=0;$i<4;$i++){
  61. $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色
  62. imagestring($im, 5, 2+$i*10, 1, $numArray[$i], $font);
  63. }
  64. for($i=0;$i<200;$i++) //加入干扰象素
  65. {
  66. $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
  67. imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数
  68. }
  69. ImagePNG($im);
  70. ImageDestroy($im);
  71. }
  72. //获取网站首页配置
  73. public function homePageSetting(){
  74. $home_page = D("Options")->get("home_page" ) ;
  75. $home_item = D("Options")->get("home_item" ) ;
  76. $array = array(
  77. "home_page"=>$home_page ,
  78. "home_item"=>$home_item ,
  79. );
  80. $this->sendResult($array);
  81. }
  82. //返回showdoc版本
  83. public function version(){
  84. $file = file_get_contents('../composer.json');
  85. $json = json_decode($file , 1 );
  86. $this->sendResult(array("version"=>$json['version']));
  87. }
  88. //浏览附件
  89. public function visitFile(){
  90. R("Attachment/visitFile");
  91. }
  92. }