Commit 34a4c3aa by banice

code换取sessionkey,返回用户手机号,验证用户是否已存在

parent d8b990c3
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午3:24
*/
namespace Lib\redis;
class RedisKeyName
{
/**
* 微信用户openid与sessionkey的hash表
*/
const USER_OPENID_SESSIONKEY = 'hdg:user:openid_sessionkey:hash';
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/15
* Time: 上午10:38
*/
namespace Lib\redis;
class RedisSingle
{
/**
* @var \Redis
*/
private static $redis = null;
/**
* @return \Redis
*/
public static function getRedis() : \Redis
{
if(is_null(static::$redis))
{
static::instance();
}
return static::$redis;
}
/**
* @return \Redis
*/
public static function instance()
{
if (is_null(static::$redis)) {
static::$redis = new \Redis();
static::$redis->connect(env('REDIS_HOST'));
static::$redis->select(4);
}
return static::$redis;
}
public static function __callStatic($name, $arguments)
{
static::instance();
return call_user_func_array([static::$redis, $name], $arguments);
}
public static function pipe()
{
static::instance();
static::$redis = static::$redis->multi(2);
}
/**
* @return array
*/
public static function exec()
{
static::instance();
return static::$redis->exec();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午3:27
*/
namespace Lib\wx;
class Decode
{
private $input = '';
private $output = [];
public static $OK = 1;
public static $IllegalAesKey = -41001;
public static $IllegalIv = -41002;
public static $IllegalBuffer = -41003;
public static $DecodeBase64Error = -41004;
/**
* @param string $input
* @param string $sessionKey
* @param string $iv
* @return int
*/
public function decode(string $input, string $sessionKey, string $iv)
{
$input = base64_decode($input);
$sessionKey = base64_decode($sessionKey);
$iv = base64_decode($iv);
$result = openssl_decrypt($input, 'aes-128-cbc', $sessionKey, 1, $iv);
$dataObj = json_decode($result);
if ($dataObj == NULL) {
return static::$IllegalBuffer;
}
if ($dataObj->watermark->appid != env('WX_APP_ID')) {
return static::$IllegalBuffer;
}
$this->output = json_decode($result, true);
return static::$OK;
}
/**
* @return string
*/
public function getInput(): string
{
return $this->input;
}
/**
* @param string $input
*/
public function setInput(string $input): void
{
$this->input = $input;
}
/**
* @return array
*/
public function getOutput(): array
{
return $this->output;
}
/**
* @param array $output
*/
public function setOutput(array $output): void
{
$this->output = $output;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午3:43
*/
namespace Lib\wx;
class User
{
private $openId = '';
private $sessionId = '';
/**
* @return string
*/
public function getOpenId(): string
{
return $this->openId;
}
/**
* @param string $openId
*/
public function setOpenId(string $openId): void
{
$this->openId = $openId;
}
/**
* @return string
*/
public function getSessionId(): string
{
return $this->sessionId;
}
/**
* @param string $sessionId
*/
public function setSessionId(string $sessionId): void
{
$this->sessionId = $sessionId;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午3:12
*/
namespace Lib\wx;
/**
* 验证请求微信接口是否成功
*
* Trait ValidateError
* @package Lib\wx
*/
trait ValidateError
{
private $errorCode = '';
private $errorMessage = '';
/**
* @param array $response
* @return bool
*/
public function isError(array $response)
{
$result = false;
if (isset($response['errcode']) === true) {
$result = true;
$this->errorCode = $response['errcode'];
$this->errorMessage = $response['errmsg'];
}
return $result;
}
/**
* @return string
*/
public function getErrorCode(): string
{
return $this->errorCode;
}
/**
* @param string $errorCode
*/
public function setErrorCode(string $errorCode): void
{
$this->errorCode = $errorCode;
}
/**
* @return string
*/
public function getErrorMessage(): string
{
return $this->errorMessage;
}
/**
* @param string $errorMessage
*/
public function setErrorMessage(string $errorMessage): void
{
$this->errorMessage = $errorMessage;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午2:54
*/
namespace Lib\wx\login;
use GuzzleHttp\Client;
use Lib\redis\RedisKeyName;
use Lib\redis\RedisSingle;
use Lib\wx\ValidateError;
/**
* 微信小程序code登录
*
* Class Login
* @package Lib\wx\login
*/
class Login
{
use ValidateError;
const HOST = 'https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code';
private $code = '';
private $openId = '';
private $unionId = '';
private $sessionKey = '';
public function __construct(string $code)
{
$this->code = $code;
}
/**
* @return bool
*/
public function request()
{
$client = new Client([
]);
$response = $client->get(sprintf(self::HOST, env('WX_APP_ID'), env('WX_APP_SECRET'), $this->code));
if ($response->getStatusCode() === 200) {
$body = $response->getBody();
$body = json_decode($body, true);
if ($this->isError($body) === true) {
abort(500, $this->getErrorMessage());
}
if (isset($body['openid']) === true) {
$this->openId = $body['openid'];
}
if (isset($body['unionid']) === true) {
$this->unionId = $body['unionid'];
}
if (isset($body['session_key']) === true) {
$this->sessionKey = $body['session_key'];
}
if (filled($this->sessionKey) && filled($this->openId)) {
$redis = RedisSingle::getRedis();
$redis->hSet(RedisKeyName::USER_OPENID_SESSIONKEY, $this->openId, $this->sessionKey);
}
return true;
}else{
return false;
}
}
/**
* @return string
*/
public function getCode(): string
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode(string $code): void
{
$this->code = $code;
}
/**
* @return string
*/
public function getOpenId(): string
{
return $this->openId;
}
/**
* @param string $openId
*/
public function setOpenId(string $openId): void
{
$this->openId = $openId;
}
/**
* @return string
*/
public function getUnionId(): string
{
return $this->unionId;
}
/**
* @param string $unionId
*/
public function setUnionId(string $unionId): void
{
$this->unionId = $unionId;
}
/**
* @return string
*/
public function getSessionKey(): string
{
return $this->sessionKey;
}
/**
* @param string $sessionKey
*/
public function setSessionKey(string $sessionKey): void
{
$this->sessionKey = $sessionKey;
}
}
\ No newline at end of file
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Dingo\Api\Routing\Helpers;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController class Controller extends BaseController
{ {
// //
use Helpers;
} }
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午2:17
*/
namespace App\Http\Controllers\v1;
use App\Http\Controllers\Controller;
class TestController extends Controller
{
public function test()
{
return '123';
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午2:30
*/
namespace App\Http\Controllers\v1\wx\auth;
use App\Http\Controllers\Controller;
use App\model\UserModel;
use Dingo\Api\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Lib\wx\Decode;
use Lib\wx\login\Login;
use Lib\wx\User;
use Auth;
use Log;
class CodeController extends Controller
{
public function login(Request $request, Decode $decode)
{
$code = $request->get('code');
// return $this->response->array(['sfsds']);
$validator = Validator::make($request->all(), [
'code' => 'required',
'user_info' => '',
'encode' => 'required',
'iv' => 'required'
]);
if ($validator->fails() === true) {
abort(400, $validator->errors()->first());
}
$login = new Login($code);
if ($login->request() === true) {
$userModel = new UserModel();
$wxUser = new User();
$openId = $login->getOpenId();
$sessionKey = $login->getSessionKey();
if($userModel->where('openid',$openId)->get())
{
}
$wxUser->setOpenId($openId);
$wxUser->setSessionId($sessionKey);
if ($userModel->addWxUser($wxUser) === false) {
abort(500, 'add new user fail');
}
$iv = $request->get('iv');
if ($decode->decode($request->get('encode'), $sessionKey, $iv) === 1) {
$output = $decode->getOutput();
Log::debug('',$output);
}
$token = Auth::login($userModel);
return $this->response->array([
'token' => $token,
'output' => $output
]);
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午3:36
*/
namespace App\Http\Controllers\v1\wx\auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Lib\wx\Decode;
class UserController extends Controller
{
public function getUserInfo(Request $request, Decode $decode)
{
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 下午4:43
*/
namespace App\Http\Middleware;
use Closure;
use Lib\wx\login\Login;
use Log;
class AddResultCodeMiddleware
{
public function handle($request, Closure $next)
{
$response = $next($request);
// 执行动作
return $response;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/9
* Time: 下午2:43
*/
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class CorsMiddleware
{
/**
*
* @param Request $request
* @param Closure $next
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function handle(Request $request,Closure $next)
{
$headers = [
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Max-Age' => '86400',
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, X-Requested-With'
];
if ($request->isMethod('OPTIONS'))
{
return response()->json('{"method":"OPTIONS"}', 200, $headers);
}
$response = $next($request);
foreach($headers as $key => $value)
{
$response->header($key, $value);
}
return $response;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/7
* Time: 上午11:37
*/
namespace App\model;
use Illuminate\Database\Eloquent\Model;
use Lib\wx\User;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Auth\Authenticatable;
use Illuminate\Support\Facades\Log;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
class UserModel extends Model implements JWTSubject, AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable;
protected $table = 'guests';
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [
];
}
public function addWxUser(User $user)
{
$this->openid = $user->getOpenId();
$this->session_key = $user->getSessionId();
return $this->save();
}
}
\ No newline at end of file
<?php <?php
require_once __DIR__.'/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
try { try {
(new Dotenv\Dotenv(__DIR__.'/../'))->load(); (new Dotenv\Dotenv(__DIR__ . '/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) { } catch (Dotenv\Exception\InvalidPathException $e) {
// //
} }
...@@ -20,12 +20,17 @@ try { ...@@ -20,12 +20,17 @@ try {
*/ */
$app = new Laravel\Lumen\Application( $app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../') realpath(__DIR__ . '/../')
); );
// $app->withFacades();
// $app->withEloquent(); $app->configure('auth');
$app->configure('logging');
$app->withFacades();
$app->withEloquent();
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -59,6 +64,19 @@ $app->singleton( ...@@ -59,6 +64,19 @@ $app->singleton(
| |
*/ */
$app->middleware([
\App\Http\Middleware\CorsMiddleware::class,
]);
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
'addResultCode' => \App\Http\Middleware\AddResultCodeMiddleware::class,
]);
// $app->middleware([ // $app->middleware([
// App\Http\Middleware\ExampleMiddleware::class // App\Http\Middleware\ExampleMiddleware::class
// ]); // ]);
...@@ -78,9 +96,13 @@ $app->singleton( ...@@ -78,9 +96,13 @@ $app->singleton(
| |
*/ */
// $app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class); $app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
$app->register(Dingo\Api\Provider\LumenServiceProvider::class);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -93,10 +115,30 @@ $app->singleton( ...@@ -93,10 +115,30 @@ $app->singleton(
| |
*/ */
$app['Dingo\Api\Auth\Auth']->extend('oauth', function ($app) {
return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
});
app('Dingo\Api\Transformer\Factory')->setAdapter(function ($app) {
return new Dingo\Api\Transformer\Adapter\Fractal(new League\Fractal\Manager, 'include', ',');
});
$app['Dingo\Api\Exception\Handler']->setErrorFormat([
'error_message' => ':message',
'return_code' => ':status_code',
'debug' => ':debug',
]);
$app->router->group([ $app->router->group([
'namespace' => 'App\Http\Controllers', 'namespace' => 'App\Http\Controllers',
], function ($router) { ], function ($router) {
require __DIR__.'/../routes/web.php'; require __DIR__ . '/../routes/web.php';
}); });
return $app; return $app;
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
"require": { "require": {
"php": ">=5.6.4", "php": ">=5.6.4",
"laravel/lumen-framework": "5.5.*", "laravel/lumen-framework": "5.5.*",
"vlucas/phpdotenv": "~2.2" "vlucas/phpdotenv": "~2.2",
"dingo/api": "2.0.0-alpha1",
"tymon/jwt-auth": "^1.0@dev",
"guzzlehttp/guzzle": "~6.0"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "~1.4", "fzaninotto/faker": "~1.4",
...@@ -16,7 +19,8 @@ ...@@ -16,7 +19,8 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/",
"Lib\\": "Lib/"
} }
}, },
"autoload-dev": { "autoload-dev": {
......
<?php
return [
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is used by the Illuminate encrypter service and should be set
| to a random, 32 character string, otherwise these encrypted strings
| will not be safe. Please do this before deploying an application!
|
*/
'key' => env('APP_KEY', 'UqYFWOkD4q6L9duemwxrF5yGX2TF8XzN'),
'cipher' => 'AES-256-CBC',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => env('APP_LOCALE', 'en'),
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
// 'aliases' => [
// 'Validator' => \Illuminate\Support\Facades\Validator::class
// ]
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => env('AUTH_GUARD', 'api'),
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "token"
|
*/
'guards' => [
'api' => ['driver' => 'jwt','provider' => 'users'],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
//
'users' => [
'driver' => 'eloquent',
'model' => \App\model\UserModel::class
]
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
//
],
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
*/
'default' => env('BROADCAST_DRIVER', 'pusher'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
],
'redis' => [
'driver' => 'redis',
'connection' => env('BROADCAST_REDIS_CONNECTION', 'default'),
],
'log' => [
'driver' => 'log',
],
],
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Cache Store
|--------------------------------------------------------------------------
|
| This option controls the default cache connection that gets used while
| using this caching library. This connection is used when another is
| not explicitly specified when executing a given caching function.
|
*/
'default' => env('CACHE_DRIVER', 'redis'),
/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may define all of the cache "stores" for your application as
| well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches.
|
*/
'stores' => [
'apc' => [
'driver' => 'apc',
],
'array' => [
'driver' => 'array',
],
'database' => [
'driver' => 'database',
'table' => env('CACHE_DATABASE_TABLE', 'cache'),
'connection' => env('CACHE_DATABASE_CONNECTION', null),
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache'),
],
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'), 'port' => env('MEMCACHED_PORT', 11211), 'weight' => 100,
],
],
],
'redis' => [
'driver' => 'redis',
'connection' => env('CACHE_REDIS_CONNECTION', 'default'),
],
],
/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing a RAM based store such as APC or Memcached, there might
| be other applications utilizing the same cache. So, we'll specify a
| value to get prefixed to all our keys so we can avoid collisions.
|
*/
'prefix' => env('CACHE_PREFIX', 'laravel'),
];
<?php
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
],
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', base_path('database/database.sqlite')),
'prefix' => env('DB_PREFIX', ''),
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => env('DB_PREFIX', ''),
'timezone' => env('DB_TIMEZONE', '+08:00'),
'strict' => env('DB_STRICT_MODE', false),
],
'old_cdz' => [
'driver' => 'mysql',
'host' => env('PRE_DB_HOST'),
'port' => env('PRE_DB_PORT', 3306),
'database' => env('PRE_DB_DATABASE'),
'username' => env('PRE_DB_USERNAME'),
'password' => env('PRE_DB_PASSWORD'),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => env('DB_PREFIX', ''),
'timezone' => env('DB_TIMEZONE', '+08:00'),
'strict' => env('DB_STRICT_MODE', false),
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 5432),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => env('DB_PREFIX', ''),
'schema' => env('DB_SCHEMA', 'public'),
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => env('DB_PREFIX', ''),
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'cluster' => env('REDIS_CLUSTER', false),
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 4),
'password' => env('REDIS_PASSWORD', null),
],
],
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env('LOG_CHANNEL', 'daily'),
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/lumen.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/lumen.log'),
'level' => 'debug',
'days' => 7,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Lumen Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Queue Driver
|--------------------------------------------------------------------------
|
| The Laravel queue API supports a variety of back-ends via an unified
| API, giving you convenient access to each back-end using the same
| syntax for each one. Here you may set the default queue driver.
|
| Supported: "null", "sync", "database", "beanstalkd", "sqs", "redis"
|
*/
'default' => env('QUEUE_DRIVER', 'sync'),
/*
|--------------------------------------------------------------------------
| Queue Connections
|--------------------------------------------------------------------------
|
| Here you may configure the connection information for each server that
| is used by your application. A default configuration has been added
| for each back-end shipped with Laravel. You are free to add more.
|
*/
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'queue' => 'your-queue-url',
'region' => 'us-east-1',
],
'redis' => [
'driver' => 'redis',
'connection' => env('QUEUE_REDIS_CONNECTION', 'default'),
'queue' => 'default',
'retry_after' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Failed Queue Jobs
|--------------------------------------------------------------------------
|
| These options configure the behavior of failed queue job logging so you
| can control which database and table are used to store the jobs that
| have failed. You may change them to any database / table you wish.
|
*/
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => env('QUEUE_FAILED_TABLE', 'failed_jobs'),
],
];
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/4
* Time: 上午10:05
*/
return [
'host' => env('RABBIT_HOST'),
'port' => env('RABBIT_PORT'),
'login' => env('RABBIT_LOGIN'),
'password' => env('RABBIT_PASSWORD'),
'vhost' => env('RABBIT_VHOST'),
];
<?php
return [
/*
|--------------------------------------------------------------------------
| View Storage Paths
|--------------------------------------------------------------------------
|
| Most templating systems load templates from disk. Here you may specify
| an array of paths that should be checked for your views. Of course
| the usual Laravel view path has already been registered for you.
|
*/
'paths' => [
realpath(base_path('resources/views')),
],
/*
|--------------------------------------------------------------------------
| Compiled View Path
|--------------------------------------------------------------------------
|
| This option determines where all the compiled Blade templates will be
| stored for your application. Typically, this is within the storage
| directory. However, as usual, you are free to change this value.
|
*/
'compiled' => realpath(storage_path('framework/views')),
];
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/4/27
* Time: 上午9:05
*/
return [
// 'appId' => 'wx2d049ccbde322c2e',
// 'appId' => 'wx72a0a0591e4e2539',
// 'appSecret' => '41e2827de3927f2c3de392c2800b90bf',
// 'appSecret' => '075401bcb54ae99b62cd9755f4bd939f',
// 'mch_id' => '1480201542',
'cache_user_token' => 'wx_user_token_',
'appId' => env('WX_APP_ID'),
'appSecret' => env('WX_APP_SECRET'),
'mch_id' => env('WX_MCH_ID'),
'lang' => env('WX_LANG'),
];
\ No newline at end of file
...@@ -14,3 +14,16 @@ ...@@ -14,3 +14,16 @@
$router->get('/', function () use ($router) { $router->get('/', function () use ($router) {
return $router->app->version(); return $router->app->version();
}); });
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['namespace' => 'App\Http\Controllers\v1\wx', 'prefix' => 'api/wx','middleware' => ['addResultCode']], function ($api) {
$api->get('code', 'auth\CodeController@login');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment