首頁  >  文章  >  後端開發  >  寫了一個存取微信的程式碼,總是出錯,求教

寫了一個存取微信的程式碼,總是出錯,求教

WBOY
WBOY原創
2016-08-04 09:21:321444瀏覽

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=cooo#wechat_redoect# ";
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";

雷雷

$access_token=$jsonobj['access_token'];
$openid=$jsonobj['openid'];
//檢查資料庫中是否有openid
mysql_select_db("sjk", $dzcon); utf8',$dzcon);
$sqlcha="從weixinopenid=$openid 的使用者中選擇id";
if (is_null(mysql_query($sqlcha, $dzcon))) {
雷雷

}其他{

雷雷

$userobj=json_decode($res,true);

$nickname=$userobj['nickname'];

//日期

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

//新增資料

$sqlzhuce="插入使用者(weixinhao,weixinniheng,zhucetime)values('$openid','$nickname','$date')";

if (!mysql_query($sqlzhuce,$dzcon)) {
if (!mysql_query($sqlzhuce,$dzcon)) {

雷雷

}
$sqldenglu="select id from user where weixinhao=$openid";
$userids=mysql_query($sqldenglu,$dzcon);
$userid=mysql_fetch_array($userids); _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=cooo#wechat_redoect# ";
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";

雷雷
$access_token=$jsonobj['access_token'];
$openid=$jsonobj['openid'];

//檢查資料庫中是否有openid

mysql_select_db("sjk", $dzcon); utf8',$dzcon);
$sqlcha="從使用者中選取id,其中weixinopenid=$openid";
if (is_null(mysql_query($sqlcha, $dzcon))) {
雷雷
}其他{
雷雷
$userobj=json_decode($res,true);

$nickname=$userobj['nickname'];

//日期

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

//新增資料


$sqlzhuce="插入使用者(weixinhao,weixinniheng,zhucetime)values('$openid','$nickname','$date')";

if (!mysql_query($sqlzhuce,$dzcon)) {

if (!mysql_query($sqlzhuce,$dzcon)) {

雷雷

}
$sqldenglu="select id from user where weixinhao=$openid";

$userids=mysql_query($sqldenglu,$dzcon);

$userid=mysql_fetch_array($userids); _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