1、下载 qq 互联 php 版开发包 http://wiki.open.qq.com/wiki/website/SDK下载
2、把文件夹 API、install和文件index.php 复制到 expansion 文件加下。
3、地址栏输入" 域名/expansion/qq/" 按提示执行相关配置。回调地址:passport/qqdenglu.php
4、
<?php
require_once("../expansion/qq/API/qqConnectAPI.php");
require('../common/incfiles/function.inc.php');
define('APP_NAME', 'jtbc_');
define('COOKIES_PATH', '/');
$qc = new QC();
$access_token = $qc->qq_callback();
$openid = $qc->get_openid();
$qcc = new QC($access_token,$openid);
$arr = $qcc->get_user_info();
if (!is_null($arr))
{
$access_token = md5($access_token);
$_SESSION[APP_NAME . 'access_token'] = $access_token;
$dialog_url = "=" . $arr["nickname"] . "&sex=" . $arr["gender"] . "&openid=" . $openid . "&access_token=" . $access_token ;
echo '<meta charset="UTF-8">';
echo("<script> top.location.href='" . $dialog_url . "'</script>");
exit();
}
else
{
echo "<script>alert('登陆失败');</script>";
}
?>
5、加处理函数passport/common/incfiles/interface_config.inc.php, 注意:加处跳转代码,请自行添加。
<?php
function jtbc_cms_interface_qq_denglu()
{
$sex = ii_unescape(ii_get_safecode($_GET['sex']));
$name = ii_unescape(ii_get_safecode($_GET['name']));
$openid = ii_get_safecode($_GET['openid']);
$access_token = ii_unescape(ii_get_safecode($_GET['access_token']));
if $access_token != $_SESSION[APP_NAME . 'access_token'] die('forbidden');
global $conn;
global $ndatabase, $nidfield, $nfpre;
$zucehao = $openid;
$zucema = $access_token;
if (ap_check_isuser($zucehao) == 0)
{
$tsqlstr = "insert into $ndatabase (
" . ii_cfname('username') . ",
" . ii_cfname('password') . ",
" . ii_cfname('name') . ",
" . ii_cfname('time') . "
) values (
'$zucehao',
'$zucema',
'$name',
'" . ii_now() . "'
)";
$trs = ii_conn_query($tsqlstr, $conn);
}
else
{
$tsqlstr = "update $ndatabase set " . ii_cfname('password') . "='$zucema' ," . ii_cfname('pretime') . "=" . ii_cfname('lasttime') . "," . ii_cfname('lasttime') . "='" . ii_now() . "' where " . ii_cfname('username') . "='$zucehao'";
$trs = ii_conn_query($tsqlstr, $conn);
}
if ($trs)
{
setcookie(APP_NAME . 'user[username]', $zucehao, 0, COOKIES_PATH);
setcookie(APP_NAME . 'user[password]', $access_token, 0, COOKIES_PATH);
$_SESSION[APP_NAME . 'username'] = $openid;
header('location:http://域名');
}
else
{
echo "<script>alert('系统出错');</script>";
}
}
6、添加登陆链接文件 expansion/qq/login.php
<?php
require_once("API/qqConnectAPI.php");
$qc = new QC();
$qc->qq_login();
7、删除 expansion/qq/ 下 install 文件夹 index.php 文件
来源:http://qihui.name/bian_cheng/96.html