>  기사  >  백엔드 개발  >  위챗에 연결하는 코드를 작성했는데 항상 오류가 나네요. 조언 부탁드립니다.

위챗에 연결하는 코드를 작성했는데 항상 오류가 나네요. 조언 부탁드립니다.

WBOY
WBOY원래의
2016-08-04 09:21:321499검색

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";
헤더('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";

<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);</code>

$access_token=$jsonobj['access_token'];
$openid=$jsonobj['openid'];
//检查数据库中是否유openid
mysql_select_db("sjk", $dzcon );
mysql_query('set names utf8',$dzcon);
$sqlcha="weixinopenid=$openid인 사용자에서 ID 선택";
if (is_null(mysql_query($sqlcha, $dzcon) )) {

<code>$userids=mysql_query($sqlcha, $dzcon);
$userid=mysql_fetch_array($userids);</code>

}그 외{

<code>$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);</code>

$userobj=json_decode($res,true);
$nickname=$userobj['nickname'];

//날짜
$date=date("y-m-d h:i:s");

//데이터 추가

$sqlzhuce="사용자 (weixinhao,weixinnicheng,zhucetime) 값에 삽입('$openid','$nickname','$date')";
if (!mysql_query($sqlzhuce,$dzcon) ) {

<code>echo "提交失败";
die('Error:'.mysql_error());</code>

}
$sqldenglu="weixinhao=$openid인 사용자에서 ID 선택";
$userids=mysql_query($sqldenglu,$dzcon);
$userid=mysql_fetch_array($userids);
}
session_start();
$_SESSION['userid']=$userid[0];
echo "<script>window.location.href=index.php?userid=". $_SESSION['userid']";</script>";
mysql_close($dzcon);

?>

回复内容:

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";
헤더('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";

<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);</code>

$access_token=$jsonobj['access_token'];
$openid=$jsonobj['openid'];
//检查数据库中是否유openid
mysql_select_db("sjk", $dzcon );
mysql_query('set names utf8',$dzcon);
$sqlcha="weixinopenid=$openid인 사용자에서 ID 선택";
if (is_null(mysql_query($sqlcha, $dzcon) )) {

<code>$userids=mysql_query($sqlcha, $dzcon);
$userid=mysql_fetch_array($userids);</code>

}그 외{

<code>$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);</code>

$userobj=json_decode($res,true);
$nickname=$userobj['nickname'];

//날짜
$date=date("y-m-d h:i:s");

//데이터 추가

$sqlzhuce="사용자 (weixinhao,weixinnicheng,zhucetime) 값에 삽입('$openid','$nickname','$date')";
if (!mysql_query($sqlzhuce,$dzcon) ) {

<code>echo "提交失败";
die('Error:'.mysql_error());</code>

}
$sqldenglu="weixinhao=$openid인 사용자에서 ID 선택";
$userids=mysql_query($sqldenglu,$dzcon);
$userid=mysql_fetch_array($userids);
}
session_start();
$_SESSION['userid']=$userid[0];
echo "<script>window.location.href=index.php?userid=". $_SESSION['userid']";</script>";
mysql_close($dzcon);

?>

报错是什么,放재http://mp.weixin.qq.com/debug/调试下报错

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.