You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers\API\Mp;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use JWT;
class LoginController
{
//微信登录授权获取openid
public function wxGetOpenid()
{
$code = request('code');
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . config('app.globals.WxAppid') . "&secret=" . config('app.globals.WxAppSecret') . "&js_code=" . $code . "&grant_type=authorization_code";
$response = Http::get($url);
if ($response->successful()) {
$data = $response->json(); // 获取响应的 JSON 数据
// var_dump($data);
if (isset($data['openid'])) {
$openid = $data['openid'];
$member = DB::table('members')->where('openid', $openid)->first();
$url="https://www.baidu.com";
return \Yz::Return(true, '获取openid成功', ['openid' => $openid, 'member' => $member,'url'=>$url]);
} else {
return \Yz::echoError1('获取openid失败');
}
} else {
return \Yz::echoError1('获取openid失败');
}
}
}