ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ <?php ~~~ /** * H5获取授权链接 * @return void */ public function getAuthUrl() { $url = $this->request->param('url'); $platform = $this->request->param('platform','wechat'); if (!$url || !$platform || !isset($this->config[$platform])) { $this->error('参数错误'); } $this->config[$platform]['callback'] = $url; $this->app = new Application($this->config); // if (!$this->app->{$platform}) { $this->error(__('Invalid parameters')); } $this->success('', $this->app->{$platform}->getAuthorizeUrl()); } ~~~ /** * 微信 */ class Wechat { const GET_AUTH_CODE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize"; /** * 获取authorize_url */ public function getAuthorizeUrl() { $state = md5(uniqid(rand(), true)); Session::set('state', $state); $queryarr = array( "appid" => $this->config['app_id'], "redirect_uri" => $this->config['callback'], "response_type" => "code", "scope" => $this->config['scope'], "state" => $state, ); request()->isMobile() && $queryarr['display'] = 'mobile'; $url = self::GET_AUTH_CODE_URL . '?' . http_build_query($queryarr) . '#wechat_redirect'; return $url; } } ~~~