diff --git a/app/Http/Controllers/Api/AuthenticateController.php b/app/Http/Controllers/Api/AuthenticateController.php index b6b3773..a32f566 100644 --- a/app/Http/Controllers/Api/AuthenticateController.php +++ b/app/Http/Controllers/Api/AuthenticateController.php @@ -2,16 +2,13 @@ namespace App\Http\Controllers\Api; +use App\User; use Carbon\Carbon; use Illuminate\Foundation\Auth\AuthenticatesUsers; -use Illuminate\Support\Facades\Auth; -use Laravel\Passport\Client; -use Socialite; -use GuzzleHttp\Client as HttpClient; -use App\User; use Illuminate\Http\Request; +use Socialite; use Validator; -use EasyWeChat\Factory; +use EasyWeChat; class AuthenticateController extends ApiController { @@ -32,14 +29,15 @@ class AuthenticateController extends ApiController public function easyWechatGetSession($code) { - $config = config('wechat.mini_program.default'); - $app = Factory::miniProgram($config); - return $app->auth->session($code); + // $config = config('wechat.mini_program.default'); + // $app = Facade::miniProgram($config); + // return $app->auth->session($code); } /** * 处理小程序的自动登陆和注册 - * @param $oauth + * @param Request $request + * @return mixed */ public function auto_login(Request $request) { @@ -48,6 +46,12 @@ class AuthenticateController extends ApiController $wx_info = $this->easyWechatGetSession($request->code); } + + + $mini = EasyWeChat::miniProgram(); + + return $wx_info; + if (!$request->openid && empty($wx_info['openid'])) { return $this->failed('用户openid没有获取到', 401); } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 366f865..5ea0865 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -25,7 +25,7 @@ class AuthServiceProvider extends ServiceProvider public function boot() { $this->registerPolicies(); + Passport::routes(); - // } } diff --git a/app/User.php b/app/User.php index 3b318f5..08ef5b8 100644 --- a/app/User.php +++ b/app/User.php @@ -4,9 +4,9 @@ namespace App; use App\Models\Dorm; use App\Models\ServiceRange; -use Laravel\Passport\HasApiTokens; -use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; +use Laravel\Passport\HasApiTokens; class User extends Authenticatable { diff --git a/composer.json b/composer.json index a25177e..c3bcf7f 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,13 @@ "doctrine/dbal": "^2.5", "encore/laravel-admin": "1.5.*", "fideloper/proxy": "~3.3", + "jacobcyl/ali-oss-storage": "^2.0", "laravel/framework": "5.5.*", "laravel/passport": "~4.0", "laravel/tinker": "~1.0", - "overtrue/laravel-wechat": "~4.0", - "jacobcyl/ali-oss-storage": "^2.0", "orangehill/iseed": "dev-master", - "xethron/migrations-generator":"^2.0" + "overtrue/laravel-wechat": "^4.0", + "xethron/migrations-generator": "^2.0" }, "require-dev": { "filp/whoops": "~2.0", diff --git a/mini/app.js b/mini/app.js index 0385a5f..2db4b73 100644 --- a/mini/app.js +++ b/mini/app.js @@ -1,34 +1,57 @@ var util = require('./utils/util.js'); - var api = require('./config/api.js'); +var api = require('./config/api.js'); var user = require('./services/user.js'); App({ onLaunch: function () { + // wx.getLocation({ + // success: function(res) { + // console.log(res); + // }, + // }) + + // wx.openLocation({ + // latitude: 35.06151, + // longitude: 118.33705, + // success: res => { + // console.log('ai'); + // }, + // fail: error => { + // console.log(error); + // } + // }) + + // wx.chooseLocation({ + // success: function(res) { + // console.log(res); + // }, + // }) + // 获取用户信息 - wx.getSetting({ - success: res => { - if (res.authSetting['scope.userInfo']) { - // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 - wx.getUserInfo({ - success: res => { - console.log('success'); - // 可以将 res 发送给后台解码出 unionId - this.globalData.userInfo = res.userInfo + // wx.getSetting({ + // success: res => { + // if (res.authSetting['scope.userInfo']) { + // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + // wx.getUserInfo({ + // success: res => { + // console.log('success'); + // // 可以将 res 发送给后台解码出 unionId + // this.globalData.userInfo = res.userInfo - // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 - // 所以此处加入 callback 以防止这种情况 - if (this.userInfoReadyCallback) { - this.userInfoReadyCallback(res) - } - }, - fail: error => { - console.log('error:'); - } - }) - } - } - }); + // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // // 所以此处加入 callback 以防止这种情况 + // if (this.userInfoReadyCallback) { + // this.userInfoReadyCallback(res) + // } + // }, + // fail: error => { + // console.log('error:'); + // } + // }) + // } + // } + // }); wx.login({ success: function (res) { @@ -36,7 +59,7 @@ App({ if (res.code) { //发起网络请求 wx.request({ - url: 'https://mp.fengyuexingzi.top/api/login', + url: 'http://127.0.0.1:8000/api/login', data: { code: res.code }, diff --git a/mini/app.json b/mini/app.json index b975298..224ee13 100644 --- a/mini/app.json +++ b/mini/app.json @@ -55,12 +55,6 @@ "selectedIconPath": "static/images/ic_menu_choice_pressed.png", "text": "首页" }, - { - "pagePath": "pages/topic/topic", - "iconPath": "static/images/ic_menu_topic_nor.png", - "selectedIconPath": "static/images/ic_menu_topic_pressed.png", - "text": "专题" - }, { "pagePath": "pages/catalog/catalog", "iconPath": "static/images/ic_menu_sort_nor.png", diff --git a/mini/config/api.js b/mini/config/api.js index 1383433..936f08d 100644 --- a/mini/config/api.js +++ b/mini/config/api.js @@ -1,4 +1,5 @@ -const ApiRootUrl ='https://mp.fengyuexingzi.top/api/'; +//const ApiRootUrl ='https://mp.fengyuexingzi.top/api/'; +const ApiRootUrl = 'http://127.0.0.1:8000/api/'; module.exports = { IndexUrl: ApiRootUrl + 'index', //首页数据接口 -- diff --git a/mini/pages/index/index.js b/mini/pages/index/index.js index 69ff653..025b966 100644 --- a/mini/pages/index/index.js +++ b/mini/pages/index/index.js @@ -39,7 +39,7 @@ Page({ }); }, onLoad: function (options) { - this.getIndexData(); + //this.getIndexData(); }, onReady: function () { // 页面渲染完成 diff --git a/mini/pages/index/index.wxss b/mini/pages/index/index.wxss index 3c26e41..b1a2dec 100644 --- a/mini/pages/index/index.wxss +++ b/mini/pages/index/index.wxss @@ -60,7 +60,7 @@ .a-section .h .txt { padding-right: 30rpx; - background: url("http://ac-3yr0g9cz.clouddn.com/2cdba05369e10f934e54.png") right 4rpx no-repeat; + background: url("https://www.baidu.com/img/bd_logo1.png") right 4rpx no-repeat; background-size: 16.656rpx 27rpx; display: inline-block; height: 36rpx; diff --git a/mini/utils/util.js b/mini/utils/util.js index 5cbfc56..fbd31fd 100644 --- a/mini/utils/util.js +++ b/mini/utils/util.js @@ -112,6 +112,7 @@ function checkSession() { * 调用微信登录 */ function login() { + console.log('util login'); return new Promise(function (resolve, reject) { wx.login({ success: function (res) { diff --git a/routes/api.php b/routes/api.php index 782ea0b..eeebae9 100644 --- a/routes/api.php +++ b/routes/api.php @@ -18,6 +18,10 @@ Route::middleware('auth:api')->get('/user', function (Request $request) { }); Route::namespace('Api')->group(function () { + + // 用户登录 + Route::any('/login','AuthenticateController@auto_login')->name('login'); + // 在 "App\Http\Controllers\Api" 命名空间下的控制器 Route::any('/order-notify','PaymentController@notify'); // 项目估价json @@ -25,7 +29,6 @@ Route::namespace('Api')->group(function () { Route::any('/project_json/func-types', 'ProjectJsonController@getProjectFuncTypesByTypeId'); Route::any('/project_json/models', 'ProjectJsonController@getProjectModelsByFunctypeId'); - // 需要用户信息的 Route::middleware('auth:api')->group(function () { Route::get('/index','IndexController@index'); @@ -99,8 +102,6 @@ Route::namespace('Api')->group(function () { Route::get('/footprint-list','ShopFootprintController@getList');// 获取足迹列表 }); - Route::any('/login','AuthenticateController@auto_login')->name('login'); - // 测试小程序登录 Route::any('mini',function(Request $request){ $mini = EasyWeChat::miniProgram();