" . var_export($token_url,true)."\n",FILE_APPEND); $token = json_decode(file_get_contents($token_url)); if (isset($token->errcode)) { echo '

错误:

'.$token->errcode; echo '

错误信息:

'.$token->errmsg; exit; } $backurl_tmp = $_GET['backurl']; $backurl = base64_decode($backurl_tmp); file_put_contents('author.txt',"3==========>" . var_export($backurl,true)."\n",FILE_APPEND); $tmpUrl = parse_url($backurl); file_put_contents('author.txt',"4==========>" . var_export($tmpUrl,true)."\n",FILE_APPEND); $openId = $token->openid; file_put_contents('author.txt',"4==========>" . var_export($openId,true)."\n",FILE_APPEND); $time = time(); $openId = encodeOpenid($openId,$time); $unionid = encodeOpenid($token->unionid,$time);//$token->unionid; file_put_contents('author.txt',"5==========>" . var_export($openId,true)."\n",FILE_APPEND); if($tmpUrl['query']){ $urls = $tmpUrl['scheme'] . "://" . $tmpUrl['host'] . $tmpUrl['path'] . "?" . $tmpUrl['query'] . "&o=" . $openId . "&unionid=" . $unionid . "×tamp=".$time; }else{ $urls = $tmpUrl['scheme'] . "://" . $tmpUrl['host'] . $tmpUrl['path'] . "?" . "o=" . $openId . "&unionid=" . $unionid . "×tamp=".$time; } header('location:'.$urls); }else{ $backurl = $_REQUEST['backurl']; $scope = $_REQUEST['scope'] ? $_REQUEST['scope'] : "snsapi_base"; $url = 'https://'.$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?backurl=" . base64_encode($backurl); $autho_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri=".urlencode($url)."&response_type=code&scope=".$scope."&state=123#wechat_redirect"; file_put_contents('author.txt',"1==========>" . var_export($autho_url,true)."\n",FILE_APPEND); header('location:'.$autho_url); } function encodeOpenid($o,$timestamp){ $str = serialize(base64_encode($o) . $timestamp); $returnOData = base64_encode("MK_" . $str); return $returnOData; }