Explorar el Código

生成二维码

刘忠健 hace 2 años
padre
commit
516b108d97

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/api/composer.lock

+ 6 - 55
api/README.md

@@ -1,56 +1,7 @@
-ThinkPHP 6.0
-===============
+# 宇宸API系统 
+提供各类服务,如生成二维码,获取微信 TOKEN等
+### 安装依赖
 
-> 运行环境要求PHP7.1+,兼容PHP8.0。
-
-[官方应用服务市场](https://market.topthink.com) | [`ThinkAPI`——官方统一API服务](https://docs.topthink.com/think-api)
-
-ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。
-
-## 主要新特性
-
-* 采用`PHP7`强类型(严格模式)
-* 支持更多的`PSR`规范
-* 原生多应用支持
-* 更强大和易用的查询
-* 全新的事件系统
-* 模型事件和数据库事件统一纳入事件系统
-* 模板引擎分离出核心
-* 内部功能中间件化
-* SESSION/Cookie机制改进
-* 对Swoole以及协程支持改进
-* 对IDE更加友好
-* 统一和精简大量用法
-
-## 安装
-
-~~~
-composer create-project topthink/think tp 6.0.*
-~~~
-
-如果需要更新框架使用
-~~~
-composer update topthink/framework
-~~~
-
-## 文档
-
-[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
-
-## 参与开发
-
-请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。
-
-## 版权信息
-
-ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
-
-本项目包含的第三方源码和二进制文件之版权信息另行标注。
-
-版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn)
-
-All rights reserved。
-
-ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
-
-更多细节参阅 [LICENSE.txt](LICENSE.txt)
+```
+composer install --no-dev
+```

+ 11 - 7
api/app/api/controller/Base.php

@@ -17,20 +17,22 @@ class Base
 {
 
     protected $checkTokenOpen = false;//是否校验token
+    protected $checkApiSignOpen = false;//是否校验签名
     public $user;//用户
 
 
     public function __construct()
     {
-        Log::record("---------------------------", "info");
+        Log::record("-------------start--------------", "info");
         Log::record($_SERVER['REQUEST_METHOD'] . '  ' . getUrl(), 'info');
         Log::record('REFERER  ' . (array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : ""), 'info');
         Log::record('GET  ' . json_encode($_GET, JSON_UNESCAPED_UNICODE), 'info');
         Log::record('POST  ' . json_encode($_POST, JSON_UNESCAPED_UNICODE), 'info');
         Log::record('cookie  ' . json_encode($_COOKIE, JSON_UNESCAPED_UNICODE), 'info');
         Log::record('input  ' . json_encode(input('param.'), JSON_UNESCAPED_UNICODE), 'info');
-        $this->checkApiSign();
-
+        if($this->checkApiSignOpen){
+            $this->checkApiSign();
+        }
         if ($this->checkTokenOpen) {
             $this->checkToken();
         }
@@ -79,11 +81,11 @@ class Base
         //以下部分根据自己的业务实现
 
         //$field = "id,login_name,valid,last_login_time,login_count,token";
-        $user = \app\common\model\User::where("token", "=", $token)->find();//找到token
+        /*$user = \app\common\model\User::where("token", "=", $token)->find();//找到token
         if (!$user) {
             $this->error(ErrorCode::getError(ErrorCode::CODE_TOKEN_ERR), ErrorCode::CODE_TOKEN_ERR);
         }
-        $this->user = $user;
+        $this->user = $user;*/
 
     }
 
@@ -98,6 +100,7 @@ class Base
         $res = returnFormat(0, $msg, $data);
 
         Log::record("response:" . mb_substr(json_encode($res, JSON_UNESCAPED_UNICODE), 0, 1000) . ",code:0", "debug");
+        Log::record("-------------start--------------", "info");
         throw new HttpResponseException(Response::create($res, "json"));
     }
 
@@ -120,6 +123,7 @@ class Base
     {
         $res = returnFormat($code, $msg, $data);
         Log::record("response:" . mb_substr(json_encode($res, JSON_UNESCAPED_UNICODE), 0, 1000) . ",code:" . $code, "debug");
+        Log::record("-------------start--------------", "info");
         throw new HttpResponseException(Response::create($res, "json"));
     }
 
@@ -166,8 +170,8 @@ class Base
 
         if ($sign !== $sign2) {
             Log::record("签名错误:sign: $sign sign2: $sign2", "debug");
-            Log::record("sign2 签名key:".$secret,"debug");
-            Log::record("sign2 签名字符串:".$signStr,"debug");
+            Log::record("sign2 签名key:" . $secret, "debug");
+            Log::record("sign2 签名字符串:" . $signStr, "debug");
             $this->error("签名错误。" . $signStr);
         }
     }

+ 32 - 0
api/app/api/controller/Qrcode.php

@@ -0,0 +1,32 @@
+<?php
+
+
+namespace app\api\controller;
+
+
+use Endroid\QrCode\Builder\Builder;
+use Endroid\QrCode\Writer\PngWriter;
+use think\facade\Log;
+
+class Qrcode extends Base
+{
+    public function online()
+    {
+        $param=input("param.");
+        $rules=[
+          "text"=>"require",
+          "size"=>"number|between:100,1000",
+        ];
+        $this->autoValid($rules,$param);
+        $text = input("text");
+        $size=input("size",300);
+        $label=input("label","");
+        if ($text) {
+            $text = urldecode2($text);
+        }
+        //二维码生成的包:https://packagist.org/packages/endroid/qr-code
+        $result = Builder::create()->writer(new PngWriter())->data($text)->labelText($label)->size($size)->build();
+        return response($result->getString(), 200)->contentType($result->getMimeType());
+    }
+
+}

+ 19 - 11
api/app/common.php

@@ -2,7 +2,17 @@
 // 应用公共文件
 
 
-
+if (!function_exists('urldecode2')) {
+    /**
+     * 2次URL解码
+     * @param $str
+     * @return string
+     */
+    function urldecode2($str)
+    {
+        return urldecode(urldecode($str));
+    }
+}
 
 if (!function_exists('returnFormat')) {
     /**
@@ -12,18 +22,16 @@ if (!function_exists('returnFormat')) {
      * @param array $data
      * @return mixed
      */
-    function returnFormat($code=0,$msg="",$data=[]){
-        $res['code']=$code;
-        $res['data']=$data;
-        $res['msg']=$msg;
+    function returnFormat($code = 0, $msg = "", $data = [])
+    {
+        $res['code'] = $code;
+        $res['data'] = $data;
+        $res['msg'] = $msg;
         return $res;
     }
 }
 
 
-
-
-
 if (!function_exists('each_item')) {
     function each_item(&$array)
     {
@@ -81,7 +89,7 @@ if (!function_exists('getUrl')) {
     }
 }
 
-if(!function_exists('number2chinese')){
+if (!function_exists('number2chinese')) {
 
     function number2chinese($num)
     {
@@ -203,8 +211,8 @@ if (!function_exists('randNum')) {
      */
     function randNum($length = 8)
     {
-        $min = pow(10, $length-1) + 1;
-        $max = pow(10, $length ) - 1;
+        $min = pow(10, $length - 1) + 1;
+        $max = pow(10, $length) - 1;
         $rand = rand($min, $max);
 //        echo "length: $length, min: $min ,max: $max ,rand: $rand \r\n <br/>";
         return $rand;

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 1
api/app/controller/Index.php


+ 2 - 1
api/composer.json

@@ -23,7 +23,8 @@
         "php": ">=7.1.0",
         "topthink/framework": "^6.0.0",
         "topthink/think-orm": "^2.0",
-        "topthink/think-multi-app": "^1.0"
+        "topthink/think-multi-app": "^1.0",
+        "endroid/qr-code": "^4.4"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2",

+ 0 - 1
api/route/app.php

@@ -14,4 +14,3 @@ Route::get('think', function () {
     return 'hello,ThinkPHP6!';
 });
 
-Route::get('hello/:name', 'index/hello');

+ 7 - 0
api/version.md

@@ -0,0 +1,7 @@
+#2022-06
+### v1.0.0
+2022-06-02 增加二维码在线生成接口,接口地址:
+```
+/api/qrcode/online/?text=1234&size=400&label=1234
+```
+