docs/src/6.x/work/oauth.md
此文档为企业微信内部应用开发的网页授权,非第三方应用网页授权
创建实例:
use EasyWeChat\Work\Application;
$config = [
'corp_id' => 'xxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxx', // 应用的 secret
];
$app = new Application($config);
// $callbackUrl 为授权回调地址
$callbackUrl = 'https://xxx.xxx'; // 需设置可信域名
// 返回授权跳转链接
$redirectUrl = $app->getOAuth()->redirect($callbackUrl);
在回调页面中,你可以使用以下方式获取授权者信息:
$code = "回调URL中的code";
$user = $app->getOAuth()->detailed()->userFromCode($code);
// 获取用户信息
$user->getId(); // 对应企业微信英文名(userid)
$user->getRaw(); // 获取企业微信接口返回的原始信息
:book: OAuth 详情请参考:网页授权
获取用户其他信息需调用通讯录接口,参考:企业微信通讯录 API