Error_reporting (E_all);
Require "conn.php";
$appid = ' xxxxx ';
$redirect _uri=urlencode ("http://www.xxxxx.com/weixin/rukou.php/");
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=". $appid. " &redirect_uri= ". $redirect _uri." &response_type=code&scope=snsapi_base&state=coo#wechat_redirect ";
Header (' location ', $url);
$appsecret = ' xxxxx ';
$code = $_get[' code ');
$get _token_url= "https://api.weixin.qq.com/sns/oauth2/access_token?appid=". $appid. " &secret= ". $appsecret." &code= ". $code." &grant_type=authorization_code ";
$ch=curl_init();curl_setopt($ch, CURLOPT_URL, $get_token_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);$res=curl_exec($ch);curl_close($ch); $jsonobj=json_decode($res,ture);
$access _token= $jsonobj [' Access_token '];
$openid = $jsonobj [' OpenID '];
Check if there is an OpenID in the database
mysql_select_db ("SJK", $dzcon);
mysql_query (' Set names UTF8 ', $dzcon);
$sqlcha = "SELECT id from user where weixinopenid= $openid";
if (Is_null (mysql_query ($sqlcha, $dzcon))) {
$userids=mysql_query($sqlcha, $dzcon);$userid=mysql_fetch_array($userids);
}else{
$get_user_info_url="https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN";$ch=curl_init();curl_setopt($ch, CURLOPT_URL, $get_token_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);$res=curl_exec($ch);curl_close($ch);
$userobj =json_decode ($res, true);
$nickname = $userobj [' nickname '];
Date
$date =date ("y-m-d h:i:s");
Add data
$sqlzhuce = "INSERT into user (Weixinhao,weixinnicheng,zhucetime) VALUES (' $openid ', ' $nickname ', ' $date ')";
if (!mysql_query ($sqlzhuce, $dzcon)) {
echo "提交失败";die('Error:'.mysql_error());
}
$sqldenglu = "SELECT id from user where weixinhao= $openid";
$userids =mysql_query ($sqldenglu, $dzcon);
$userid =mysql_fetch_array ($userids);
}
Session_Start ();
$_session[' userid ']= $userid [0];
echo "";
Mysql_close ($dzcon);
?>
Reply content:
Error_reporting (E_all);
Require "conn.php";
$appid = ' xxxxx ';
$redirect _uri=urlencode ("http://www.xxxxx.com/weixin/rukou.php/");
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=". $appid. " &redirect_uri= ". $redirect _uri." &response_type=code&scope=snsapi_base&state=coo#wechat_redirect ";
Header (' location ', $url);
$appsecret = ' xxxxx ';
$code = $_get[' code ');
$get _token_url= "https://api.weixin.qq.com/sns/oauth2/access_token?appid=". $appid. " &secret= ". $appsecret." &code= ". $code." &grant_type=authorization_code ";
$ch=curl_init();curl_setopt($ch, CURLOPT_URL, $get_token_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);$res=curl_exec($ch);curl_close($ch); $jsonobj=json_decode($res,ture);
$access _token= $jsonobj [' Access_token '];
$openid = $jsonobj [' OpenID '];
Check if there is an OpenID in the database
mysql_select_db ("SJK", $dzcon);
mysql_query (' Set names UTF8 ', $dzcon);
$sqlcha = "SELECT id from user where weixinopenid= $openid";
if (Is_null (mysql_query ($sqlcha, $dzcon))) {
$userids=mysql_query($sqlcha, $dzcon);$userid=mysql_fetch_array($userids);
}else{
$get_user_info_url="https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN";$ch=curl_init();curl_setopt($ch, CURLOPT_URL, $get_token_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);$res=curl_exec($ch);curl_close($ch);
$userobj =json_decode ($res, true);
$nickname = $userobj [' nickname '];
Date
$date =date ("y-m-d h:i:s");
Add data
$sqlzhuce = "INSERT into user (Weixinhao,weixinnicheng,zhucetime) VALUES (' $openid ', ' $nickname ', ' $date ')";
if (!mysql_query ($sqlzhuce, $dzcon)) {
echo "提交失败";die('Error:'.mysql_error());
}
$sqldenglu = "SELECT id from user where weixinhao= $openid";
$userids =mysql_query ($sqldenglu, $dzcon);
$userid =mysql_fetch_array ($userids);
}
Session_Start ();
$_session[' userid ']= $userid [0];
echo "";
Mysql_close ($dzcon);
?>
What is the error, put in http://mp.weixin.qq.com/debug/debug error