Laravel 微信小程序后端搭建步骤详解

1. 新建个 laravel 项目

laravel new aaaa

2. 执行命令运行起站点来

php artisan key:generate

3. 登录装着 mysql 服务的远程服务器,创建数据库及用户名

(1)登录 ssh root@218.45.23.456

(2)登录 mysql 输入命令 mysql -u root -p,输入密码登录成功显示 mysql>

(3)创建数据库 create database aaaaaaaa charset utf8mb4;

(4)创建远程用户 create user aaaa@‘%' identified by ‘密码';

(5)赋权 grant all privileges on aaaaaaaa.* to aaaa@“%”;

4. 改下 database/migrations 目录下的 **users_table.php 文件,添加上微信开放的字段

//微信资料 $table->string(‘weapp_openid')->nullable()->comment(‘微信开放id'); $table->string(‘weapp_session_key')->nullable()->comment(‘微信session_key'); $table->string(‘nickname')->nullable()->comment(‘昵称'); $table->string(‘weapp_avatar')->nullable()->comment(‘微信头像'); $table->string(‘country')->nullable()->comment(‘国家'); $table->string(‘province')->nullable()->comment(‘省份'); $table->string(‘city')->nullable()->comment(‘所在城市'); $table->string(‘language')->nullable()->comment(‘语言'); $table->json(‘location')->nullable()->comment(‘当前地理信息'); $table->enum(‘gender', [‘1', ‘2'])->default(‘1')->comment(‘性别默认男'); $table->string(‘phone')->nullable()->unique();

5. 打开 config/app.php 把时区、语言换下

‘timezone' => ‘Asia/Shanghai', ‘locale' => ‘zh-CN', ‘fallback_locale' => ‘zh-CN', ‘faker_locale' => ‘zh-CN',

6. 打开 composer.json

require 里添加下面几个包

“require”: { “php”: “^7.1.3”, “fideloper/proxy”: “^4.0”, “laravel/framework”: “5.8.*”, “laravel/tinker”: “^1.0”, “jellybool/flysystem-upyun”: “^1.0”, “laravel/passport”: “^7.2”, “overtrue/laravel-wechat”: “~5.0” },

7. 命令行执行 composer update

打开参照链接配置下

(1)又拍云参照配置 https://github.com/JellyBool/flysystem-upyun

(2)easywechart 参照配置 GitHub - overtrue/laravel-wechat: 微信 SDK for Laravel, 基于 overtrue/wechat

8.app/Http/Kernel.php 接口设置次数多些

‘api' => [ ‘throttle:60000,1', ‘bindings', ],

9. 打开.env 文件,配置好数据库和小程序、又拍云的保密信息

DB_CONNECTION=mysql DB_HOST=218.45.23.456 DB_PORT=3306 DB_DATABASE=aaaaaaaa DB_USERNAME=aaaa DB_PASSWORD=密码 UP_OPERATOR_NAME=又拍云ftp用户名 UP_OPERATOR_PASSWORD=又拍云ftp密码 WECHAT_MINI_PROGRAM_APPID=小程序APPID WECHAT_MINI_PROGRAM_SECRET=小程序SECRET

10. 执行 php artisan migrate,生成数据库表 7 张表

Migration table created successfully. Migrated: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_100000_create_password_resets_table Migrated: 2016_06_01_000001_create_oauth_auth_codes_table Migrated: 2016_06_01_000002_create_oauth_access_tokens_table Migrated: 2016_06_01_000003_create_oauth_refresh_tokens_table Migrated: 2016_06_01_000004_create_oauth_clients_table Migrated: 000005_create_oauth_personal_access_clients_table

11. 执行命令 php artisan passport:install

Client ID: 1 Client secret: Password grant client created successfully. Client ID: 2 Client secret:

12.config/auth.php,API 的 dirver 改成 passport

'api' => [ 'driver' => 'passport', 'provider' => 'users', 'hash' => false, ],

一开始差不多就这些吧

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e9aecdb8d72a5d486842f4f194c41401.html