|

5精币
PHP 获取OPENID 为什么强制结束微信后重新登录才能取到IPENID 不强制结束获取不到
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
if (!isset($_SESSION)) {
session_start();
}
$hostname_conn = "sql.h131.123.com";
$database_conn = "123";
$username_conn = "123";
$password_conn = "123";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(), E_USER_ERROR);
if (!$_SESSION['openid']) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
if ($_GET['code'] && !$_SESSION['openid']) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxb02040b8121zzxcc&secret=ce62f5b6d337ghgcd62b81a44d5e31d1&code=' . $_GET['code'] . '&grant_type=authorization_code');
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, '0');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, '0');
$data = curl_exec($curl);
curl_close($curl);
$retdata = json_decode($data, 1);
if (isset($retdata['openid'])) {
$_SESSION['openid'] = $retdata['openid'];
mysql_select_db($database_conn, $conn);
$sql = "select * from yuangongxinxi where openid='" . $retdata['openid'] . "'";
$result = mysql_query($sql, $conn);
$result_detail = mysql_fetch_array($result);
if ($result_detail['openid'] == $retdata['openid']) {
$_SESSION['MM_Username'] = $result_detail['xingming'];
$_SESSION['MM_UserGroup'] = '';
$MM_redirectLoginSuccess = "main.php";
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess);
}else{
var_dump($retdata, $result_detail);
}
}else{
var_dump($retdata);
}
} else {
$root_url = 'http://www.qimao.fun';
$url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb0204012321cf0c&redirect_uri=' . urlencode($root_url) . '&response_type=code&scope=snsapi_base#wechat_redirect';
header('Location: ' . $url);
exit;
}
}
}
|
|