12345678910111213141516171819202122232425 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\User;
- use App\Models\WechatInfo;
- class WechatController extends Controller
- {
- public function index()
- {
- $wechat_user = session('wechat.oauth_user.default');
- if($wechat_user && isset($wechat_user['original'])) {
- $official_open_id = $wechat_user['original']['openid'];
- $union_id = $wechat_user['original']['unionid'];
- WechatInfo::firstOrCreate([
- 'official_open_id' => $official_open_id,
- 'union_id' => $union_id
- ]);
- User::where('union_id', $union_id)->update(['official_open_id' => $official_open_id]);
- return '授权成功';
- }
- return '授权失败';
- }
- }
|