Silent 6 yıl önce
ebeveyn
işleme
2311d15deb

+ 0 - 16
app/Http/Controllers/Api/LoginController.php

xqd
@@ -1,16 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api;
-
-use Illuminate\Http\Request;
-use App\Http\Controllers\Controller;
-use Illuminate\Support\Facades\Log;
-
-class LoginController extends Controller
-{
-    public function login(Request $request)
-    {
-        dd('ok');
-        Log::info($request->all());
-    }
-}

+ 24 - 0
app/Http/Controllers/WeChat/LoginController.php

xqd
@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Http\Controllers\WeChat;
+
+use Illuminate\Http\Request;
+use App\Http\Controllers\Controller;
+use Illuminate\Support\Facades\Log;
+
+class LoginController extends Controller
+{
+    public function login(Request $request)
+    {
+        if(empty($request->input('code')) || empty($request->input('iv')) || empty($request->input('encryptData'))) {
+            return response()->json(['status' => 'error', 'info' => '参数错误']);
+        }
+        $code = $request->input('code');
+        $iv = $request->input('iv');
+        $encryptData = $request->input('encryptData');
+        $app = app('wechat.mini_program');
+        $res = $app->auth->session($code);
+        Log::info($res);
+        return response()->json(['status' => 'success', 'info' => '操作成功']);
+    }
+}

+ 1 - 1
app/Http/Middleware/VerifyCsrfToken.php

xqd
@@ -16,7 +16,7 @@ class VerifyCsrfToken extends BaseVerifier
         "notify",
         "admin/Base/Attachment/*",
         'admin/upload/*',
-        'api/*'
+        'wechat/*'
     ];
 
 }

+ 13 - 1
app/Providers/RouteServiceProvider.php

xqd xqd xqd xqd
@@ -18,6 +18,8 @@ class RouteServiceProvider extends ServiceProvider
 
     protected $api_namespace = 'App\Http\Controllers\Api';
 
+    protected $wechat_namespace = 'App\Http\Controllers\WeChat';
+
     /**
      * Define your route model bindings, pattern filters, etc.
      *
@@ -45,6 +47,8 @@ class RouteServiceProvider extends ServiceProvider
         $this->mapAdminRoutes();
 
         $this->mapTeacherRoutes();
+
+        $this->mapWeChatRoutes();
     }
 
     public function mapAdminRoutes()
@@ -63,6 +67,14 @@ class RouteServiceProvider extends ServiceProvider
             ->group(base_path('routes/teacher.php'));
     }
 
+    public function mapWeChatRoutes()
+    {
+        Route::prefix('wechat')
+            ->middleware('web')
+            ->namespace($this->wechat_namespace)
+            ->group(base_path('routes/wechat.php'));
+    }
+
     /**
      * Define the "web" routes for the application.
      *
@@ -87,7 +99,7 @@ class RouteServiceProvider extends ServiceProvider
     protected function mapApiRoutes()
     {
         Route::prefix('api')
-             ->middleware('web')
+             ->middleware('api')
              ->namespace($this->api_namespace)
              ->group(base_path('routes/api.php'));
     }

+ 3 - 1
composer.json

xqd xqd
@@ -12,7 +12,8 @@
         "intervention/image": "^2.4",
         "laravel/framework": "5.5.*",
         "laravel/passport": "^2.0",
-        "laravel/tinker": "~1.0"
+        "laravel/tinker": "~1.0",
+        "overtrue/laravel-wechat": "~4.0"
     },
     "require-dev": {
         "barryvdh/laravel-ide-helper": "^2.4",
@@ -42,6 +43,7 @@
     "extra": {
         "laravel": {
             "dont-discover": [
+                "laravel/dusk"
             ]
         }
     },

+ 4 - 2
config/app.php

xqd xqd
@@ -180,7 +180,8 @@ return [
         Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
         Laravel\Passport\PassportServiceProvider::class,
         Intervention\Image\ImageServiceProvider::class,
-        Germey\Geetest\GeetestServiceProvider::class
+        Germey\Geetest\GeetestServiceProvider::class,
+        Overtrue\LaravelWeChat\ServiceProvider::class,
     ],
 
     /*
@@ -230,7 +231,8 @@ return [
         'Validator' => Illuminate\Support\Facades\Validator::class,
         'View' => Illuminate\Support\Facades\View::class,
         'Image' => Intervention\Image\Facades\Image::class,
-        'Geetest' => Germey\Geetest\Geetest::class
+        'Geetest' => Germey\Geetest\Geetest::class,
+        'EasyWeChat' => Overtrue\LaravelWeChat\Facade::class,
     ],
 
 ];

+ 131 - 0
config/wechat.php

xqd
@@ -0,0 +1,131 @@
+<?php
+
+/*
+ * This file is part of the overtrue/laravel-wechat.
+ *
+ * (c) overtrue <i@overtrue.me>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+return [
+    /*
+     * 默认配置,将会合并到各模块中
+     */
+    'defaults' => [
+        /*
+         * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
+         */
+        'response_type' => 'array',
+
+        /*
+         * 使用 Laravel 的缓存系统
+         */
+        'use_laravel_cache' => true,
+
+        /*
+         * 日志配置
+         *
+         * level: 日志级别,可选为:
+         *                 debug/info/notice/warning/error/critical/alert/emergency
+         * file:日志文件位置(绝对路径!!!),要求可写权限
+         */
+        'log' => [
+            'level' => env('WECHAT_LOG_LEVEL', 'debug'),
+            'file' => env('WECHAT_LOG_FILE', storage_path('logs/wechat.log')),
+        ],
+    ],
+
+    /*
+     * 路由配置
+     */
+    'route' => [
+        /*
+         * 开放平台第三方平台路由配置
+         */
+        // 'open_platform' => [
+        //     'uri' => 'serve',
+        //     'action' => Overtrue\LaravelWeChat\Controllers\OpenPlatformController::class,
+        //     'attributes' => [
+        //         'prefix' => 'open-platform',
+        //         'middleware' => null,
+        //     ],
+        // ],
+    ],
+
+    /*
+     * 公众号
+     */
+    'official_account' => [
+        'default' => [
+            'app_id' => env('WECHAT_OFFICIAL_ACCOUNT_APPID', 'your-app-id'),         // AppID
+            'secret' => env('WECHAT_OFFICIAL_ACCOUNT_SECRET', 'your-app-secret'),    // AppSecret
+            'token' => env('WECHAT_OFFICIAL_ACCOUNT_TOKEN', 'your-token'),           // Token
+            'aes_key' => env('WECHAT_OFFICIAL_ACCOUNT_AES_KEY', ''),                 // EncodingAESKey
+
+            /*
+             * OAuth 配置
+             *
+             * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
+             * callback:OAuth授权完成后的回调页地址(如果使用中间件,则随便填写。。。)
+             */
+            // 'oauth' => [
+            //     'scopes'   => array_map('trim', explode(',', env('WECHAT_OFFICIAL_ACCOUNT_OAUTH_SCOPES', 'snsapi_userinfo'))),
+            //     'callback' => env('WECHAT_OFFICIAL_ACCOUNT_OAUTH_CALLBACK', '/examples/oauth_callback.php'),
+            // ],
+        ],
+    ],
+
+    /*
+     * 开放平台第三方平台
+     */
+    // 'open_platform' => [
+    //     'default' => [
+    //         'app_id'  => env('WECHAT_OPEN_PLATFORM_APPID', ''),
+    //         'secret'  => env('WECHAT_OPEN_PLATFORM_SECRET', ''),
+    //         'token'   => env('WECHAT_OPEN_PLATFORM_TOKEN', ''),
+    //         'aes_key' => env('WECHAT_OPEN_PLATFORM_AES_KEY', ''),
+    //     ],
+    // ],
+
+    /*
+     * 小程序
+     */
+     'mini_program' => [
+         'default' => [
+             'app_id'  => env('WECHAT_MINI_PROGRAM_APPID', ''),
+             'secret'  => env('WECHAT_MINI_PROGRAM_SECRET', ''),
+             'token'   => env('WECHAT_MINI_PROGRAM_TOKEN', ''),
+             'aes_key' => env('WECHAT_MINI_PROGRAM_AES_KEY', ''),
+         ],
+     ],
+
+    /*
+     * 微信支付
+     */
+    // 'payment' => [
+    //     'default' => [
+    //         'sandbox'            => env('WECHAT_PAYMENT_SANDBOX', false),
+    //         'app_id'             => env('WECHAT_PAYMENT_APPID', ''),
+    //         'mch_id'             => env('WECHAT_PAYMENT_MCH_ID', 'your-mch-id'),
+    //         'key'                => env('WECHAT_PAYMENT_KEY', 'key-for-signature'),
+    //         'cert_path'          => env('WECHAT_PAYMENT_CERT_PATH', 'path/to/cert/apiclient_cert.pem'),    // XXX: 绝对路径!!!!
+    //         'key_path'           => env('WECHAT_PAYMENT_KEY_PATH', 'path/to/cert/apiclient_key.pem'),      // XXX: 绝对路径!!!!
+    //         'notify_url'         => 'http://example.com/payments/wechat-notify',                           // 默认支付结果通知地址
+    //     ],
+    //     // ...
+    // ],
+
+    /*
+     * 企业微信
+     */
+    // 'work' => [
+    //     'default' => [
+    //         'corp_id' => 'xxxxxxxxxxxxxxxxx',
+    ///        'agent_id' => 100020,
+    //         'secret'   => env('WECHAT_WORK_AGENT_CONTACTS_SECRET', ''),
+    //          //...
+    //      ],
+    // ],
+];

+ 0 - 4
routes/api.php

xqd
@@ -18,10 +18,6 @@
 //    return $request->user();
 //});
 
-Route::get('login', function () {
-    return 'ok';
-});
-
 //
 //$api = app('Dingo\Api\Routing\Router');
 //

+ 4 - 0
routes/wechat.php

xqd
@@ -0,0 +1,4 @@
+<?php
+use \Illuminate\Support\Facades\Route;
+
+Route::post('login', 'LoginController@login');