欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-29 20:15:40
1. 新建个 laravel 项目 laravel new aaaa 2. 执行命令运行起站点来 php artisan key:generate 3...

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 identified by ‘密码';

(5)赋权 grant all privileges on aaaaaaaa.* to ”;

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,
  ],

一开始差不多就这些吧

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。