使用Easywechat实现小程序获取openid
一 安装
点击此处进入官方文档链接
composer require overtrue/wechat:~5.0 -vvv
二 后台获取 openid的实现
$code = $request->get('code'); //接收前端传入的code值
$config = [
'app_id' => '配置文件中的wx_app_id',
'secret' => '配置文件中的app_secret',
'token' => '配置文件中的token',
'aes_key' => '配置文件中的aes_key',
'response_type' => 'array',
];
$app = new MiniProgram($config);
$data = $app->auth->session($code);
if (isset($data['openid']) && $data['openid']) {
return $data['openid'];
}else{
return '';
}