# miniprogram_system **Repository Path**: blackeybaord/miniprogram_system ## Basic Information - **Project Name**: miniprogram_system - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2021-12-15 - **Last Updated**: 2023-05-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 框架基本运行操作 `shell>composer install `//依赖包安装,开发环境 可去除--no-dev `shell>npm install`//项目目录下执行该此,主要下载apidoc依赖包 ## 配置文件生成和基本配置 `shell>cp .env.example .env` //开发环境 可用.env.example 作为魔板 在.env 文件中配置 【数据库配置】 秘钥生成: `shell>php artisan key:generate` 生成jwt秘钥: `shell>php artisan jwt:secret` ``` # 开放平台第三方平台 相关配置 WECHAT_OPEN_PLATFORM_APPID= WECHAT_OPEN_PLATFORM_SECRET= WECHAT_OPEN_PLATFORM_TOKEN= WECHAT_OPEN_PLATFORM_AES_KEY= # 开放平台第三方平台相关缓存信息设置 WECHAT_OPEN_PLATFORM_CACHE_STORE=redis # 阿里云文件上传 ALI_OSS_ACCESS_KEY_ID= ALI_OSS_ACCESS_KEY_SECRET= ``` # dingo的api配置说明 在`.env`中的配置 资料:https://learnku.com/docs/dingo-api/2.0.0/Configuration/1444 ``` API_PREFIX=api #api接口路由前缀,不能为空,咋们一般设为api API_STANDARDS_TREE=vnd # 标准树,我们固定 vnd 就好,供应商树(vnd)主要表示公开发布的项目,未注册的树(x)主要表示本地和私有环境,私有树(prs)主要表示没有商业发布的项目 API_SUBTYPE=app #子类型通常是应用程序或项目的短名称,都是小写的。 API_VERSION=v1 #这个版本号是你的 API 的默认版本号,API_STRICT=false时有效,没有加Accept 头部时默认都走这个版本的接口,并且会在一些未提供版本号的情况下作为回调的默认值使用。在生成 API 文档时也会使用这个版本号作为默认值。 API_DEBUG=false #未处理的异常发生是否在响应中添加 debug属性字段,记得在生产环境中关闭 API_STRICT=false # 是否开启 严格模式,严格模式要求客户端发送 Accept 头,如果开启严格模式,发送非法的 Acceept 标头会抛出一个未处理的异常,Symfony\Component\HttpKernel\Exception\BadRequestHttpException,咋们一般设为false ``` 头部格式:`Accept: application/API_STANDARDS_TREE.YOUR_SUBTYPE.v*+json` # 异常处理说明 由于使用了dingo,异常都被dingo接收处理,可以通过在 `app/Providers/ErrorServiceProvider.php` 中自定义异常处理返回响应(在`app/Exceptions/Handler.php`处理是无效的,好像都被dingo接管了) 其他未捕获异常的输出响应格式在 `config/api.php` 中 `errorFormat` 配置, # rbac模板集成 见 `rbac/src/README.md` # 其他 ### (1)POST方式提交数据大小限制修改 在php.ini文件中修改: ``` post_max_size = 50M upload_max_filesize = 50M ``` 在nginx.conf文件中修改: ``` http{ server{ # other setting ... client_max_body_size 50m } } ``` ## Laravel API Boilerplate (JWT Edition) for Laravel 5.6 [![CryptoTip](https://img.shields.io/badge/Donate%20with-CryptoTip-blue.svg?style=flat-square&colorB=007bff)](https://cryptotip.it/p/francescomalatesta) Laravel API Boilerplate is a "starter kit" you can use to build your first API in seconds. As you can easily imagine, it is built on top of the awesome Laravel Framework. This version is built on Laravel 5.6! It is built on top of three big guys: * JWT-Auth - [tymondesigns/jwt-auth](https://github.com/tymondesigns/jwt-auth) * Dingo API - [dingo/api](https://github.com/dingo/api) * Laravel-CORS [barryvdh/laravel-cors](http://github.com/barryvdh/laravel-cors) What I made is really simple: an integration of these three packages and a setup of some authentication and credentials recovery methods. ## Installation 1. run `composer create-project francescomalatesta/laravel-api-boilerplate-jwt myNextProject`; 2. have a coffee, nothing to do here; Once the project creation procedure will be completed, run the `php artisan migrate` command to install the required tables. ## Usage I wrote a couple of articles on this project that explain how to write an entire sample application with this boilerplate. They cover the older version of this boilerplate, but all the concepts are the same. You can find them on Sitepoint: Just be aware that some options in the `config/boilerplate.php` file are changed, so take a look to it. * [How to Build an API-Only JWT-Powered Laravel App](https://www.sitepoint.com/how-to-build-an-api-only-jwt-powered-laravel-app/) * [How to Consume Laravel API with AngularJS](https://www.sitepoint.com/how-to-consume-laravel-api-with-angularjs/) **WARNING:** the articles are old and Laravel 5.1 related. Just use them as "inspiration". Even without updated tutorials, they should be enough. ## Main Features ### Ready-To-Use Authentication Controllers You don't have to worry about authentication and password recovery anymore. I created four controllers you can find in the `App\Api\V1\Controllers` for those operations. For each controller there's an already setup route in `routes/api.php` file: * `POST api/auth/login`, to do the login and get your access token; * `POST api/auth/refresh`, to refresh an existent access token by getting a new one; * `POST api/auth/signup`, to create a new user into your application; * `POST api/auth/recovery`, to recover your credentials; * `POST api/auth/reset`, to reset your password after the recovery; * `POST api/auth/logout`, to log out the user by invalidating the passed token; * `GET api/auth/me`, to get current user data; ### Separate File for Routes All the API routes can be found in the `routes/api.php` file. This also follow the Laravel 5.5 convention. ### Secrets Generation Every time you create a new project starting from this repository, the _php artisan jwt:generate_ command will be executed. ## Configuration You can find all the boilerplate specific settings in the `config/boilerplate.php` config file. ```php [ // this option must be set to true if you want to release a token // when your user successfully terminates the sign-in procedure 'release_token' => env('SIGN_UP_RELEASE_TOKEN', false), // here you can specify some validation rules for your sign-in request 'validation_rules' => [ 'name' => 'required', 'email' => 'required|email', 'password' => 'required' ] ], // these options are related to the login procedure 'login' => [ // here you can specify some validation rules for your login request 'validation_rules' => [ 'email' => 'required|email', 'password' => 'required' ] ], // these options are related to the password recovery procedure 'forgot_password' => [ // here you can specify some validation rules for your password recovery procedure 'validation_rules' => [ 'email' => 'required|email' ] ], // these options are related to the password recovery procedure 'reset_password' => [ // this option must be set to true if you want to release a token // when your user successfully terminates the password reset procedure 'release_token' => env('PASSWORD_RESET_RELEASE_TOKEN', false), // here you can specify some validation rules for your password recovery procedure 'validation_rules' => [ 'token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed' ] ] ]; ``` As I already said before, this boilerplate is based on _dingo/api_ and _tymondesigns/jwt-auth_ packages. So, you can find many informations about configuration here and here. However, there are some extra options that I placed in a _config/boilerplate.php_ file: * `sign_up.release_token`: set it to `true` if you want your app release the token right after the sign up process; * `reset_password.release_token`: set it to `true` if you want your app release the token right after the password reset process; There are also the validation rules for every action (login, sign up, recovery and reset). Feel free to customize it for your needs. ## Creating Endpoints You can create endpoints in the same way you could to with using the single _dingo/api_ package. You can read its documentation for details. After all, that's just a boilerplate! :) However, I added some example routes to the `routes/api.php` file to give you immediately an idea. ## Cross Origin Resource Sharing If you want to enable CORS for a specific route or routes group, you just have to use the _cors_ middleware on them. Thanks to the _barryvdh/laravel-cors_ package, you can handle CORS easily. Just check the docs at this page for more info. ## Tests If you want to contribute to this project, feel free to do it and open a PR. However, make sure you have tests for what you implement. In order to run tests: * create a `homestead_test` database on your machine; * run `vendor/bin/phpunit`; If you want to specify a different name for the test database, don't forget to change the value in the `phpunix.xml` file. ## Feedback I currently made this project for personal purposes. I decided to share it here to help anyone with the same needs. If you have any feedback to improve it, feel free to make a suggestion, or open a PR!