Laravel 微信小程序后端搭建步骤详解
1.新建个laravel项目
laravelnewaaaa
2.执行命令运行起站点来
phpartisankey:generate
3.登录装着mysql服务的远程服务器,创建数据库及用户名
(1)登录sshroot@218.45.23.456
(2)登录mysql输入命令mysql-uroot-p,输入密码登录成功显示mysql>
(3)创建数据库createdatabaseaaaaaaaacharsetutf8mb4;
(4)创建远程用户createuseraaaa@‘%'identifiedby‘密码';
(5)赋权grantallprivilegesonaaaaaaaa.*toaaaa@“%”;
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.命令行执行composerupdate
打开参照链接配置下
(1)又拍云参照配置https://github.com/JellyBool/flysystem-upyun
(2)easywechart参照配置GitHub-overtrue/laravel-wechat:微信SDKforLaravel,基于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.执行phpartisanmigrate,生成数据库表7张表
Migrationtablecreatedsuccessfully. 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.执行命令phpartisanpassport:install
ClientID:1 Clientsecret: Passwordgrantclientcreatedsuccessfully. ClientID:2 Clientsecret:
12.config/auth.php,API的dirver改成passport
'api'=>[ 'driver'=>'passport', 'provider'=>'users', 'hash'=>false, ],
一开始差不多就这些吧
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。