赞
踩
- $ composer require tymon/jwt-auth
- $ composer require overtrue/wechat:~5.0 -vvv
$ php artisan jwt:secret
- public function auth(Request $request)
- {
- $code = $request->get('code');
- $rawData = $request->get('rawData');
- $config = Configs::first()->toArray();
-
- $config = [
- 'app_id' => $config['app_id'] ?? env('WECHAT_APP_ID'), // 这里需要自行修改
- 'secret' => $config['secret'] ?? env('WECHAT_APP_SECRET'), // 这里需要自行修改
- ];
-
- $app = Factory::miniProgram($config);
- $data = $app->auth->session($code);
-
- //判断code是否过期
- if (isset($data['errcode'])) {
- return ['code' => 404, 'massage' => 'code已过期或不正确'];
- }
- $weappOpenid = $data['openid'];
- $weixinSessionKey = $data['session_key'];
-
- $wechat = json_decode($rawData, true);
- $user = Members::UpdateOrCreate(['openid' => $weappOpenid], [
- 'openid' => $weappOpenid,
- 'nickname' => $wechat['nickName'],
- // 'gender' => $wechat['gender'],
- // 'city' => $wechat['city'], // 'Wenzhou',
- // 'province' => $wechat['province'], // 'Zhejiang',
- // 'country' => $wechat['country'], // 'China',
- 'avatar' => $wechat['avatarUrl'],
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。