Prechádzať zdrojové kódy

Merge branch 'develop' of http://git.caihongxingqiu.net/rainbow/shop-service into develop

zhangchangchun 6 rokov pred
rodič
commit
9746c04b33

+ 6 - 1
.env.example

@@ -21,4 +21,9 @@ QUEUE_CONNECTION=sync
 ELASTICSEARCH_HOST=localhost
 ELASTICSEARCH_PORT=9200
 ELASTICSEARCH_USER=
-ELASTICSEARCH_PASS=
+ELASTICSEARCH_PASS=
+
+APP_ID=chxq-platform
+CLUSTER=default
+APOLLO_NAMESPACES="application,shop-service"
+APOLLO_CONFIG_SERVER=http://47.92.174.125:18080

+ 2 - 1
.gitignore

@@ -4,4 +4,5 @@ Homestead.json
 Homestead.yaml
 .env
 /storage/*
-composer.lock
+composer.lock
+/config/customer.php

+ 84 - 0
.rocketeer/config.php

@@ -0,0 +1,84 @@
+<?php
+
+use Rocketeer\Services\Connections\ConnectionsHandler;
+
+return [
+
+    // The name of the application to deploy
+    // This will create a folder of the same name in the root directory
+    // configured above, so be careful about the characters used
+    'application_name' => 'shop-service',
+
+    // Plugins
+    ////////////////////////////////////////////////////////////////////
+
+    // The plugins to load
+    'plugins'          => [// 'Rocketeer\Plugins\Slack\RocketeerSlack',
+    ],
+
+    // Logging
+    ////////////////////////////////////////////////////////////////////
+
+    // The schema to use to name log files
+    'logs'             => function (ConnectionsHandler $connections) {
+        return sprintf('%s-%s-%s.log', $connections->getConnection(), $connections->getStage(), date('Ymd'));
+    },
+
+    // Remote access
+    //
+    // You can either use a single connection or an array of connections
+    ////////////////////////////////////////////////////////////////////
+
+    // The default remote connection(s) to execute tasks on
+    'default'          => ['production'],
+
+    // The various connections you defined
+    // You can leave all of this empty or remove it entirely if you don't want
+    // to track files with credentials : Rocketeer will prompt you for your credentials
+    // and store them locally
+    'connections'      => [
+        'production' => [
+            'host'      => '47.92.174.125:2345',
+            'username'  => 'root',
+            'password'  => '',
+            'key'       => '/root/.ssh/id_rsa',
+            'keyphrase' => '',
+            'agent'     => '',
+            'db_role'   => true,
+        ],
+    ],
+
+    /*
+     * In most multiserver scenarios, migrations must be run in an exclusive server.
+     * In the event of not having a separate database server (in which case it can
+     * be handled through connections), you can assign a 'db_role' => true to the
+     * server's configuration and it will only run the migrations in that specific
+     * server at the time of deployment.
+     */
+    'use_roles'        => false,
+
+    // Contextual options
+    //
+    // In this section you can fine-tune the above configuration according
+    // to the stage or connection currently in use.
+    // Per example :
+    // 'stages' => array(
+    // 	'staging' => array(
+    // 		'scm' => array('branch' => 'staging'),
+    // 	),
+    //  'production' => array(
+    //    'scm' => array('branch' => 'master'),
+    //  ),
+    // ),
+    ////////////////////////////////////////////////////////////////////
+
+    'on'               => [
+
+        // Stages configurations
+        'stages'      => [],
+        // Connections configuration
+        'connections' => [],
+
+    ],
+
+];

+ 40 - 0
.rocketeer/hooks.php

@@ -0,0 +1,40 @@
+<?php
+
+return [
+
+    // Tasks
+    //
+    // Here you can define in the `before` and `after` array, Tasks to execute
+    // before or after the core Rocketeer Tasks. You can either put a simple command,
+    // a closure which receives a $task object, or the name of a class extending
+    // the Rocketeer\Abstracts\AbstractTask class
+    //
+    // In the `custom` array you can list custom Tasks classes to be added
+    // to Rocketeer. Those will then be available in the command line
+    // with all the other tasks
+    //////////////////////////////////////////////////////////////////////
+
+    // Tasks to execute before the core Rocketeer Tasks
+    'before' => [
+        'setup'   => [],
+        'deploy'  => [],
+        'cleanup' => [],
+    ],
+
+    // Tasks to execute after the core Rocketeer Tasks
+    'after'  => [
+        'setup'   => [],
+        'deploy'  => [
+            'composer dumpautoload',
+            'php artisan route:clear',
+            'chmod -R 777 bootstrap',
+            'chmod -R 777 storage',
+            'chmod -R 777 public'
+        ],
+        'cleanup' => [],
+    ],
+
+    // Custom Tasks to register with Rocketeer
+    'custom' => [],
+
+];

+ 24 - 0
.rocketeer/paths.php

@@ -0,0 +1,24 @@
+<?php
+
+return [
+
+    // Configurable paths
+    //
+    // Here you can manually set paths to some commands Rocketeer
+    // might try to use, if you leave those empty it will try to find them
+    // manually or assume they're in the root folder
+    //
+    // You can also add in this file custom paths for any command or binary
+    // Rocketeer might go looking for
+    ////////////////////////////////////////////////////////////////////
+
+    // Path to the PHP binary
+    'php'      => '/usr/local/php/bin/php',
+
+    // Path to Composer
+    'composer' => '/usr/local/bin/composer',
+
+    // Path to the Artisan CLI
+    'artisan'  => 'artisan',
+
+];

+ 80 - 0
.rocketeer/remote.php

@@ -0,0 +1,80 @@
+<?php
+
+return [
+
+    // Remote server
+    //////////////////////////////////////////////////////////////////////
+
+    // Variables about the servers. Those can be guessed but in
+    // case of problem it's best to input those manually
+    'variables'      => [
+        'directory_separator' => '/',
+        'line_endings'        => "\n",
+    ],
+
+    // The number of releases to keep at all times
+    'keep_releases'  => 4,
+
+    // Folders
+    ////////////////////////////////////////////////////////////////////
+
+    // The root directory where your applications will be deployed
+    // This path *needs* to start at the root, ie. start with a /
+    'root_directory' => '/data/wwwroot/beta',
+
+    // The folder the application will be cloned in
+    // Leave empty to use `application_name` as your folder name
+    'app_directory'  => '',
+
+    // A list of folders/file to be shared between releases
+    // Use this to list folders that need to keep their state, like
+    // user uploaded data, file-based databases, etc.
+    'shared'         => [
+        'storage',
+        'vendor',
+        '.env',
+    ],
+
+    // Execution
+    //////////////////////////////////////////////////////////////////////
+
+    // If enabled will force a shell to be created
+    // which is required for some tools like RVM or NVM
+    'shell'          => false,
+
+    // An array of commands to run under shell
+    'shelled'        => ['which', 'ruby', 'npm', 'bower', 'bundle', 'grunt'],
+
+    // Enable use of sudo for some commands
+    // You can specify a sudo user by doing
+    // 'sudo' => 'the_user'
+    'sudo' => false,
+
+    // An array of commands to run under sudo
+    'sudoed' => [],
+
+    // Permissions$
+    ////////////////////////////////////////////////////////////////////
+
+    'permissions'    => [
+
+        // The folders and files to set as web writable
+        'files'    => [
+            'bootstrap/cache',
+            'storage',
+        ],
+
+        // Here you can configure what actions will be executed to set
+        // permissions on the folder above. The Closure can return
+        // a single command as a string or an array of commands
+        'callback' => function ($task, $file) {
+            return [
+                sprintf('chmod -R 777 %s', $file),
+                sprintf('chmod -R g+s %s', $file),
+                sprintf('chown -R www:www %s', $file),
+            ];
+        },
+
+    ],
+
+];

+ 35 - 0
.rocketeer/scm.php

@@ -0,0 +1,35 @@
+<?php
+
+return [
+
+    // SCM repository
+    //////////////////////////////////////////////////////////////////////
+
+    // The SCM used (supported: "git", "svn")
+    'scm'        => 'git',
+
+    // The SSH/HTTPS address to your repository
+    // Example: https://github.com/vendor/website.git
+    'repository' => 'http://caihongxingqiu:Ch20151002@git.caihongxingqiu.net/rainbow/shop-service.git',
+
+    // The repository credentials : you can leave those empty
+    // if you're using SSH or if your repository is public
+    // In other cases you can leave this empty too, and you will
+    // be prompted for the credentials on deploy. If you don't want
+    // to be prompted (public repo, etc) set the values to null
+    'username'   => 'null',
+    'password'   => 'null',
+
+    // The branch to deploy
+    'branch'     => 'master',
+
+    // Whether your SCM should do a "shallow" clone of the repository
+    // or not – this means a clone with just the latest state of your
+    // application (no history)
+    // If you're having problems cloning, try setting this to false
+    'shallow'    => true,
+
+    // Recursively pull in submodules. Works only with GIT.
+    'submodules' => true,
+
+];

+ 19 - 0
.rocketeer/stages.php

@@ -0,0 +1,19 @@
+<?php
+
+return [
+
+    // Stages
+    //
+    // The multiples stages of your application
+    // if you don't know what this does, then you don't need it
+    //////////////////////////////////////////////////////////////////////
+
+    // Adding entries to this array will split the remote folder in stages
+    // Like /var/www/yourapp/staging and /var/www/yourapp/production
+    'stages'  => [],
+
+    // The default stage to execute tasks on when --stage is not provided
+    // Falsey means all of them
+    'default' => '',
+
+];

+ 61 - 0
.rocketeer/strategies.php

@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * This file is part of Rocketeer
+ *
+ * (c) Maxime Fabre <ehtnam6@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+use Rocketeer\Binaries\PackageManagers\Composer;
+use Rocketeer\Tasks\Subtasks\Primer;
+
+return [
+
+    // Task strategies
+    //
+    // Here you can configure in a modular way which tasks to use to
+    // execute various core parts of your deployment's flow
+    //////////////////////////////////////////////////////////////////////
+
+    // Which strategy to use to check the server
+    'check'        => 'Php',
+
+    // Which strategy to use to create a new release
+    'deploy'       => 'Clone',
+
+    // Which strategy to use to test your application
+    'test'         => 'Phpunit',
+
+    // Which strategy to use to migrate your database
+    'migrate'      => 'Artisan',
+
+    // Which strategy to use to install your application's dependencies
+    'dependencies' => 'Composer',
+
+    // Execution hooks
+    //////////////////////////////////////////////////////////////////////
+
+    'composer'     => [
+        'install' => function (Composer $composer, $task) {
+            return $composer->install([], ['--no-interaction' => null, '--prefer-dist' => null]);
+        },
+        'update'  => function (Composer $composer) {
+            return $composer->update();
+        },
+    ],
+
+    // Here you can configure the Primer tasks
+    // which will run a set of commands on the local
+    // machine, determining whether the deploy can proceed
+    // or not
+    'primer'       => function (Primer $task) {
+        return [
+            // $task->executeTask('Test'),
+            // $task->binary('grunt')->execute('lint'),
+        ];
+    },
+
+];

+ 85 - 0
app/Console/Commands/apollo.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use Org\Multilinguals\Apollo\Client\ApolloClient;
+
+class Apollo extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'apollo';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Apollo配置服务';
+
+
+    private $apollo;
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->save_dir = storage_path('apollo');
+        $this->config_tpl = config_path() . '/customer.tpl';
+        $this->config_file = config_path() . '/customer.php';
+
+        $this->apollo = new ApolloClient(
+            config('apollo.config_server'),
+            config('apollo.app_id'),
+            config('apollo.namespaces')
+        );
+        $this->apollo->save_dir = $this->save_dir;
+        if(!is_dir($this->save_dir)){
+            mkdir($this->save_dir);
+        }
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line('apollo配置服务开启');
+        $restart = true; //失败自动重启
+        do {
+            $error = $this->apollo->start(function () {
+                $list = glob($this->save_dir . DIRECTORY_SEPARATOR . 'apolloConfig.*');
+                $apollo = [];
+                foreach ($list as $l) {
+                    $config = require $l;
+                    if (is_array($config) && isset($config['configurations'])) {
+                        $apollo = array_merge($apollo, $config['configurations']);
+                    }
+                }
+                if (!$apollo) {
+                    Log::error('Load Apollo Config Failed, no config available');
+                }
+                $tpl = file_get_contents($this->config_tpl);
+                foreach ($apollo as $key =>$value){
+                    $tpl = str_replace('{'.$key.'}',$value,$tpl);
+                }
+                file_put_contents($this->config_file,$tpl);
+            }); //此处传入回调
+            if ($error) {
+                Log::info("Apollo Hand error :" . $error);
+            }
+        } while ($error && $restart);
+    }
+}

+ 2 - 1
app/Console/Kernel.php

@@ -2,6 +2,7 @@
 
 namespace App\Console;
 
+use App\Console\Commands\Apollo;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
 
@@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
      * @var array
      */
     protected $commands = [
-        //
+        Apollo::class
     ];
 
     /**

+ 14 - 0
app/Helper/helper.php

@@ -3,6 +3,20 @@
  * 添加自定义辅助函数
  */
 
+if ( ! function_exists('config_path'))
+{
+    /**
+     * Get the configuration path.
+     *
+     * @param string $path
+     * @return string
+     */
+    function config_path($path = '')
+    {
+        return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
+    }
+}
+
 /**
  * 参数签名校验
  * @param array $params

+ 17 - 2
app/Http/Middleware/JwtAuthMiddleware.php

@@ -5,8 +5,8 @@ namespace App\Http\Middleware;
 use Closure;
 use Tymon\JWTAuth\Exceptions\JWTException;
 use Tymon\JWTAuth\Exceptions\TokenExpiredException;
+use Tymon\JWTAuth\Exceptions\TokenInvalidException;
 use Tymon\JWTAuth\Facades\JWTAuth;
-use Tymon\JWTAuth\Http\Middleware\BaseMiddleware;
 
 class JwtAuthMiddleware
 {
@@ -21,7 +21,15 @@ class JwtAuthMiddleware
     {
 
         try {
-            $data = JWTAuth::decode(JWTAuth::getToken())['user'];
+            $token = JWTAuth::getToken();
+            if(empty($token)){
+                $error = [
+                    'message' => 'token is required',
+                    'code' => 401,
+                ];
+                return response()->json($error);
+            }
+            $data = JWTAuth::decode($token)['user'];
             if ($data->sign !== md5($data->uid . env('JWT_SECRET'))) {
                 $error = [
                     'message' => 'request is not allow',
@@ -46,6 +54,13 @@ class JwtAuthMiddleware
                 'message' => $e->getMessage(),
                 'code' => 401,
             ];
+
+            return response()->json($error)->setStatusCode(401);
+        }catch (\Exception $e){
+            $error = [
+                'message' => $e->getMessage(),
+                'code' => 401,
+            ];
             return response()->json($error)->setStatusCode(401);
         }
         return $next($request);

+ 1 - 0
bootstrap/app.php

@@ -26,6 +26,7 @@ $app->withFacades();
 $app->withEloquent();
 
 $app->configure('api');
+$app->configure('apollo');
 $app->configure('auth');
 $app->configure('jwt');
 $app->configure('customer');

+ 1 - 0
composer.json

@@ -16,6 +16,7 @@
         "predis/predis": "^1.1",
         "tymon/jwt-auth": "1.0.0-rc.4.1",
         "vlucas/phpdotenv": "^3.3",
+        "multilinguals/apollo-client": "^0.1.2",
         "yansongda/laravel-pay": "^2.0"
     },
     "require-dev": {

+ 10 - 0
config/apollo.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'namespaces' => explode(',', env('APOLLO_NAMESPACES')),
+    'cluster' => env('APOLLO_CLUSTER'),
+    'save_dir' => storage_path('apollo'),
+    'config_server' => env('APOLLO_CONFIG_SERVER'),
+    'app_id' => env('APP_ID'),
+    'timeout_interval' => 70
+];

+ 0 - 6
config/customer.php

@@ -1,6 +0,0 @@
-<?php
-//此文件为apollo配置文件模板,禁止修改移动
-return [
-    'app_secret' => 'aaaaaaaaaaa',
-    'app_service_url' =>'https://api.dev.caihongxingqiu.com'
-];

+ 7 - 0
config/customer.tpl

@@ -0,0 +1,7 @@
+<?php
+//此文件为apollo配置文件模板,禁止修改移动
+return [
+    'app_secret' => '{app_secret}',
+    'jwt_secret' => '{jwt_secret}',
+    'app_service_url' => '{app_service_url}',
+];

+ 1 - 1
config/jwt.php

@@ -25,7 +25,7 @@ return [
     |
     */
 
-    'secret' => env('JWT_SECRET'),
+    'secret' => env('JWT_SECRET',config('customer.jwt_secret')),
 
     /*
     |--------------------------------------------------------------------------

+ 20 - 0
deploy/nginx/conf.d/app.beta.conf

@@ -0,0 +1,20 @@
+server {
+    listen 80;
+    index index.php index.html;
+    error_log  /var/log/nginx/error.log;
+    access_log /var/log/nginx/access.log;
+    root /var/www/public;
+    location ~ \.php$ {
+        try_files $uri =404;
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
+        fastcgi_pass app_shop_service_beta:9000;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+        fastcgi_param PATH_INFO $fastcgi_path_info;
+    }
+    location / {
+        try_files $uri $uri/ /index.php?$query_string;
+        gzip_static on;
+    }
+}

+ 20 - 0
deploy/nginx/conf.d/app.dev.conf

@@ -0,0 +1,20 @@
+server {
+    listen 80;
+    index index.php index.html;
+    error_log  /var/log/nginx/error.log;
+    access_log /var/log/nginx/access.log;
+    root /var/www/public;
+    location ~ \.php$ {
+        try_files $uri =404;
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
+        fastcgi_pass app_shop_service_dev:9000;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+        fastcgi_param PATH_INFO $fastcgi_path_info;
+    }
+    location / {
+        try_files $uri $uri/ /index.php?$query_string;
+        gzip_static on;
+    }
+}

+ 2 - 0
deploy/php/local.ini

@@ -0,0 +1,2 @@
+upload_max_filesize=40M
+post_max_size=40M

+ 32 - 0
docker-compose-beta.yml

@@ -0,0 +1,32 @@
+version: '3'
+
+services:
+  app_shop_service_beta:
+    image: harbor.caihongxingqiu.com:9401/library/php:latest
+    tty: true
+    working_dir: /var/www
+    volumes:
+      - ./:/var/www
+      - ./deploy/php/local.ini:/usr/local/etc/php/conf.d/local.ini
+      - /data/wwwroot/beta/shop-service:/data/wwwroot/beta/shop-service
+    networks:
+      - chxq
+
+  server_shop_service_beta:
+    image: harbor.caihongxingqiu.com:9401/library/nginx:latest
+    tty: true
+    depends_on:
+      - app_shop_service_beta
+    ports:
+      - "28209:80"
+    volumes:
+      - ./:/var/www
+      - ./deploy/nginx/conf.d/app.beta.conf:/etc/nginx/conf.d/app.beta.conf
+    networks:
+      - chxq
+
+#docker networks
+#docker network create --driver overlay chxq
+networks:
+  chxq:
+    external: true

+ 31 - 0
docker-compose-dev.yml

@@ -0,0 +1,31 @@
+version: '3'
+
+services:
+  app_shop_service_dev:
+    image: harbor.caihongxingqiu.com:9401/library/php:latest
+    tty: true
+    working_dir: /var/www
+    volumes:
+      - ./:/var/www
+      - ./deploy/php/local.ini:/usr/local/etc/php/conf.d/local.ini
+    networks:
+      - chxq
+
+  server_shop_service_dev:
+    image: harbor.caihongxingqiu.com:9401/library/nginx:latest
+    tty: true
+    depends_on:
+      - app_shop_service_dev
+    ports:
+      - "18209:80"
+    volumes:
+      - ./:/var/www
+      - ./deploy/nginx/conf.d/app.dev.conf:/etc/nginx/conf.d/app.dev.conf
+    networks:
+      - chxq
+
+#docker networks
+#docker network create --driver overlay chxq
+networks:
+  chxq:
+    external: true