$appid = "wx25767979a61a2385"; $secret = "***********18"; if (! isset ( $_GET [‘code‘] )) { $local_url = "http://{$_SERVER [‘HTTP_HOST‘]}{$_SERVER[‘PHP_SELF‘]}"; $local_url = urlencode ( $local_url ); $sit = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$local_url}&response_type=code&scope=snsapi_base&state=1#wechat_redirect"; header ( "Location:" . $sit ); } else { $code = $_GET [‘code‘]; $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code"; $json = json_decode ( file_get_contents ( $url ), true ); $openid=$json [‘openid‘]; }
时间: 2024-11-07 12:46:29