self::gauth($code), 'mode' => $mode]; $image = MediaService::getQrcode(sysuri('wechat/api.login/oauth', $data, false, $domain)); return ['code' => $code, 'auth' => $data['auth'], 'image' => $image->getDataUri()]; } /** * 发起网页授权处理. * @param string $auth 授权编号 * @param int $mode 授权模式 * @throws InvalidResponseException * @throws LocalCacheException * @throws Exception */ public static function oauth(string $auth = '', int $mode = 0): bool { if (stripos($auth, self::prefix) === 0) { $url = Library::$sapp->request->url(true); $fans = WechatService::getWebOauthInfo($url, $mode); if (isset($fans['openid'])) { Library::$sapp->cache->set($auth, $fans, self::expire); return true; } } return false; } /** * 检查是否授权. * @param string $code 请求编号 */ public static function query(string $code): ?array { return Library::$sapp->cache->get(self::gauth($code)); } /** * 删除授权缓存. */ public static function remove(string $code): bool { return Library::$sapp->cache->delete(self::gauth($code)); } }