墨香年少 32 发布于 2022年2月26日 <?php $appid = 'wx111112222222233333'; $secret = 'qwertyuiasdfghj23456789fcdgvhbjnk'; $callback = urlencode('https://wx.abcdef.com/get_openid/request.php'); if(!isset($_GET['code'])) { $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$callback."&response_type=code&scope=snsapi_base&state=123#wechat_redirect"; go($url); } else { $code = $_GET['code']; $api = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code"; $ret = http($api); $arr = json_decode($ret,true); echo '<meta content="width=device-width, initial-scale=1" name="viewport" />'; print_r($arr['openid']);die(); } function go($url) { header('location:'.$url); exit(); } function http($url, $data = null) { $curl = curl_init (); curl_setopt ( $curl, CURLOPT_URL, $url ); curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, FALSE ); if (! empty ( $data )) { curl_setopt ( $curl, CURLOPT_POST, 1 ); curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data ); } curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 ); $output = curl_exec ( $curl ); curl_close ( $curl ); return $output; } 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点