Przeglądaj źródła

Merge branch 'develop'

xielin 5 lat temu
rodzic
commit
9075692dfa

+ 0 - 1
.rocketeer/hooks.php

@@ -26,7 +26,6 @@ return [
         'setup'   => [],
         'deploy'  => [
             'composer dumpautoload',
-            'php artisan route:clear',
             'chmod -R 777 bootstrap',
             'chmod -R 777 storage',
             'chmod -R 777 public'

+ 1 - 0
app/Http/Controllers/ConfigController.php

@@ -33,6 +33,7 @@ class ConfigController extends Controller
             'find_friend_img' => config('customer.find_friend_img'),
             'suggest_img' => config('customer.suggest_img'),
             'share_post_bean' => (int) config('customer.share_post_bean'),
+            'share_invite_bean' => (int) config('customer.share_invite_bean'),
         ];
         return $this->jsonSuccess($data, '成功');
     }

+ 2 - 4
app/Http/Controllers/UploadController.php

@@ -25,9 +25,7 @@ class UploadController extends Controller
                 $width = Image::make($filePath)->width();
                 $height = Image::make($filePath)->height();
                 //要保存的文件名 时间+扩展名
-                $filename = time() . '_' . uniqid() . '*' . $width . '_' . $height . '.' . $kuoname;
-                //todo 等待客户端更新后替换为下列规则
-                //$filename = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
+                $filename = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
             } else {
                 //要保存的文件名 时间+扩展名
                 $filename = time() . '_' . uniqid() . '.' . $kuoname;
@@ -59,7 +57,7 @@ class UploadController extends Controller
                 $width = Image::make($filePath)->width();
                 $height = Image::make($filePath)->height();
                 //要保存的文件名 时间+扩展名
-                $filename = time() . '_' . uniqid() . '*' . $width . '_' . $height . '.' . $kuoname;
+                $filename = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
             } else {
                 //要保存的文件名 时间+扩展名
                 $filename = time() . '_' . uniqid() . '.' . $kuoname;

+ 30 - 0
app/Http/Controllers/WechatController.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use App\Services\WechatService;
+use Illuminate\Support\Facades\Validator;
+
+class WechatController extends Controller
+{
+    public function __construct(WechatService $wechatService)
+    {
+        $this->wechatService = $wechatService;
+    }
+
+    /**
+     * 公众号分享
+     */
+    public function share(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'url' => 'required|string',
+        ]);
+        if ($validator->fails()) {
+            return jsonError($validator->errors()->first());
+        }
+        $res = $this->wechatService->share($request->all());
+        return jsonSuccess(json_decode($res,true));
+    }
+}

+ 38 - 0
app/Http/Middleware/SqlMiddleware.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use Illuminate\Support\Facades\DB;
+
+class SqlMiddleware
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request $request
+     * @param  \Closure $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        if ($request->sql_debug==1) {
+            DB::connection()->enableQueryLog();
+        }
+
+        $response = $next($request);
+        if ($request->get('sql_debug')) {
+            $queries = DB::getQueryLog();
+
+            if (!empty($queries)) {
+                foreach ($queries as &$query) {
+                    $query['full_query'] = vsprintf(str_replace('?', '%s', $query['query']), $query['bindings']);
+                }
+            }
+
+            dd($queries);exit;
+        }
+
+        return $response;
+    }
+}

+ 30 - 0
app/Services/WechatService.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Services;
+
+use EasyWeChat\Factory;
+
+class WechatService
+{
+
+    public function __construct()
+    {
+        $config = [
+            'app_id'    => config('customer.wechat_id'),
+            'secret'    => config('customer.wechat_secret'),
+        ];
+        $this->app = Factory::officialAccount($config);
+    }
+
+    public function share($request)
+    {
+        $type = true;
+        if(env('APP_ENV') == 'production'){
+            $type =false;
+        }
+
+        $this->app->jssdk->setUrl($request['url']);
+
+        return $this->app->jssdk->buildConfig(['updateAppMessageShareData', 'updateTimelineShareData'], $type);
+    }
+}

+ 4 - 0
bootstrap/app.php

@@ -64,6 +64,10 @@ $app->singleton(
 |
 */
 
+$app->middleware([
+    App\Http\Middleware\SqlMiddleware::class
+]);
+
 $app->routeMiddleware([
     'auth' => App\Http\Middleware\Authenticate::class,
     'chxq_jwt_auth' => App\Http\Middleware\JwtAuthMiddleware::class,

+ 3 - 2
composer.json

@@ -8,6 +8,7 @@
         "php": ">=7.1.3",
         "dingo/api": "^2.2",
         "doctrine/dbal": "^2.9",
+        "guzzlehttp/guzzle": "^6.3",
         "hhxsv5/laravel-s": "~3.4.0",
         "illuminate/redis": "^5.8",
         "intervention/image": "^2.4",
@@ -16,10 +17,10 @@
         "laravel/lumen-framework": "5.8.*",
         "league/fractal": "^0.17.0",
         "multilinguals/apollo-client": "^0.1.2",
+        "overtrue/wechat": "~4.0",
         "predis/predis": "^1.1",
-        "tymon/jwt-auth": "1.0.0-rc.4.1",
-        "guzzlehttp/guzzle": "^6.3",
         "simplesoftwareio/simple-qrcode": "^2.0",
+        "tymon/jwt-auth": "1.0.0-rc.4.1",
         "vlucas/phpdotenv": "^3.3"
     },
     "require-dev": {

+ 2 - 0
config/customer.tpl

@@ -16,4 +16,6 @@ return [
     'find_friend_img' => '{find_friend_img}',
     'suggest_img' => '{suggest_img}',
     'app_upgrade_info' => '{app_upgrade_info}',
+    'wechat_id' => '{wechat_id}',
+    'wechat_secret' => '{wechat_secret}',
 ];

+ 2 - 0
routes/api.php

@@ -36,6 +36,8 @@ $api->version('v1', [
     });
     //公共配置
     $api->get('/config', 'ConfigController@index');
+    //公众号分享
+    $api->get('wechat/share', 'WechatController@share');
 
     //仅验签
     $api->group(['middleware' => 'chxq_sign'], function ($api) {