千帆云

标题: qq互联新版方案,暂未使用,只是保存下 [打印本页]

作者: 千帆开发王文才    时间: 2016-11-22 15:00
标题: qq互联新版方案,暂未使用,只是保存下
本帖最后由 千帆开发王文才 于 2016-11-24 16:21 编辑

Dz需要自定义修改,仅限获取了unionid调用权限的开发者账号
修改之前,注意备份《《《
以discuzX3.2源码为例
1.修改文件
DZ_X3.2\source\plugin\qqconnect\connect\connect_login.php
大概142行起需要增加代码


  1. //----------------------------2016-11-22新增--------------------------------------------
  2.         if($conuintoken)
  3.         {
  4.                 $requestUrl = 'https://graph.qq.com/oauth2.0/me?access_token='.$conuintoken.'&unionid=1';
  5.                 $res = @dfsockopen($requestUrl, 0,array(), '', 0, '', 1, 1, 'URLENCODE', 1, 0);
  6.                 if(strpos($res, "callback") === false)
  7.                 {
  8.                         $unionid = '';
  9.                 }else{
  10.                         $lpos = strpos($res, "(");
  11.                         $rpos = strrpos($res, ")");
  12.                         $res = substr($res, $lpos + 1, $rpos - $lpos - 1);
  13.                         $res = json_decode($res);
  14.                         $unionid = $res->unionid;
  15.                 }
  16.                 $response['unionid'] = $unionid;

  17.         }

  18.         if($conopenid && $response['unionid'])
  19.         {
  20.                 $uid = DB::result_first( "SELECT uid FROM %t WHERE conopenid = %s LIMIT 1", array('common_member_connect', $conopenid) );
  21.                 $uid1 = DB::result_first( "SELECT uid FROM %t WHERE unionid = %s AND weibotype = %s LIMIT 1", array('thirdbind', $response['unionid'] , 'qq' ) );
  22.                 // 如果app先绑定qq,且unionid已注册,此时以论坛为准,openid取不到数据,需要修改openid为论坛的openid
  23.                 if(!$uid && $uid1)
  24.                 {
  25.                         if($appopenid = DB::result_first( "SELECT conopenid FROM %t WHERE uid = %s LIMIT 1", array('common_member_connect', $uid1) ))
  26.                         {
  27.                                 C::t('common_member_connect')->update($uid1,array('conopenid'=>$conopenid));
  28.                         }
  29.                 }
  30.                 // 如果app先绑定qq,且unionid未注册,   这个不能做关联  phonebind是没记录的 论坛的openid是移动端appid的openid
  31.                 if(!$uid && !$uid1)
  32.                 {
  33.                         //已登录用户绑定unionid
  34.                         //先登录app,自行绑定unionid,再登陆论坛才行,
  35.                         if($_G['uid'])
  36.                         {
  37.                                 $auser = getuserbyuid($_G['uid']);
  38.                                 $nickname = $auser['username'] ? $auser['username'] : '';
  39.                                 $params = array(
  40.                                                 'uid'=>$_G['uid'],
  41.                                                 'weibotype'=>'qq',
  42.                                                 'nickname'=>$nickname,
  43.                                                 'openid'=>$conopenid,
  44.                                                 'unionid'=>$response['unionid'],
  45.                                                 'dateline'=>time()
  46.                                 );
  47.                                 DB::insert('thirdbind',$params,true);
  48.                         }
  49.                 }
  50.                 //如果论坛先绑定qq,或者都没绑定的话,那unionid需要注册,其他正常进行。app登陆时做好兼容只查unionid
  51.                 if($uid)
  52.                 {
  53.                         $qqunionid = DB::result_first( "SELECT unionid FROM %t WHERE uid = %s AND weibotype = %s LIMIT 1", array('thirdbind', $uid , 'qq' ) );
  54.                         if($qqunionid == false)
  55.                         {
  56.                                 //没记录,需插入第三方绑定数据
  57.                                 $auser = getuserbyuid($uid);
  58.                                 $nickname = $auser['username'] ? $auser['username'] : '';
  59.                                 $params = array(
  60.                                                 'uid'=>$uid,
  61.                                                 'weibotype'=>'qq',
  62.                                                 'nickname'=>$nickname,
  63.                                                 'openid'=>$conopenid,
  64.                                                 'unionid'=>$response['unionid'],
  65.                                                 'dateline'=>time()
  66.                                 );
  67.                                 DB::insert('thirdbind',$params,true);
  68.                         }elseif($qqunionid == '')
  69.                         {
  70.                                 //有记录,但未注册unionid
  71.                                 DB::update("thirdbind", array("unionid" => $response['unionid']), array('uid'=>$uid, 'weibotype'=>'qq'));
  72.                         }
  73.                 }
  74.         }
复制代码


2.需要更新qianfan插件
qianfan/protected/controllers/MemberController.php
文件 MemberController.zip (13.08 KB, 下载次数: 434)















欢迎光临 千帆云 (http://bbs.qianfanyun.com/) Powered by Discuz! X3.2