|
本帖最后由 千帆开发王文才 于 2016-11-24 16:21 编辑
Dz需要自定义修改,仅限获取了unionid调用权限的开发者账号
修改之前,注意备份《《《
以discuzX3.2源码为例
1.修改文件
DZ_X3.2\source\plugin\qqconnect\connect\connect_login.php
大概142行起需要增加代码
- //----------------------------2016-11-22新增--------------------------------------------
- if($conuintoken)
- {
- $requestUrl = 'https://graph.qq.com/oauth2.0/me?access_token='.$conuintoken.'&unionid=1';
- $res = @dfsockopen($requestUrl, 0,array(), '', 0, '', 1, 1, 'URLENCODE', 1, 0);
- if(strpos($res, "callback") === false)
- {
- $unionid = '';
- }else{
- $lpos = strpos($res, "(");
- $rpos = strrpos($res, ")");
- $res = substr($res, $lpos + 1, $rpos - $lpos - 1);
- $res = json_decode($res);
- $unionid = $res->unionid;
- }
- $response['unionid'] = $unionid;
- }
- if($conopenid && $response['unionid'])
- {
- $uid = DB::result_first( "SELECT uid FROM %t WHERE conopenid = %s LIMIT 1", array('common_member_connect', $conopenid) );
- $uid1 = DB::result_first( "SELECT uid FROM %t WHERE unionid = %s AND weibotype = %s LIMIT 1", array('thirdbind', $response['unionid'] , 'qq' ) );
- // 如果app先绑定qq,且unionid已注册,此时以论坛为准,openid取不到数据,需要修改openid为论坛的openid
- if(!$uid && $uid1)
- {
- if($appopenid = DB::result_first( "SELECT conopenid FROM %t WHERE uid = %s LIMIT 1", array('common_member_connect', $uid1) ))
- {
- C::t('common_member_connect')->update($uid1,array('conopenid'=>$conopenid));
- }
- }
- // 如果app先绑定qq,且unionid未注册, 这个不能做关联 phonebind是没记录的 论坛的openid是移动端appid的openid
- if(!$uid && !$uid1)
- {
- //已登录用户绑定unionid
- //先登录app,自行绑定unionid,再登陆论坛才行,
- if($_G['uid'])
- {
- $auser = getuserbyuid($_G['uid']);
- $nickname = $auser['username'] ? $auser['username'] : '';
- $params = array(
- 'uid'=>$_G['uid'],
- 'weibotype'=>'qq',
- 'nickname'=>$nickname,
- 'openid'=>$conopenid,
- 'unionid'=>$response['unionid'],
- 'dateline'=>time()
- );
- DB::insert('thirdbind',$params,true);
- }
- }
- //如果论坛先绑定qq,或者都没绑定的话,那unionid需要注册,其他正常进行。app登陆时做好兼容只查unionid
- if($uid)
- {
- $qqunionid = DB::result_first( "SELECT unionid FROM %t WHERE uid = %s AND weibotype = %s LIMIT 1", array('thirdbind', $uid , 'qq' ) );
- if($qqunionid == false)
- {
- //没记录,需插入第三方绑定数据
- $auser = getuserbyuid($uid);
- $nickname = $auser['username'] ? $auser['username'] : '';
- $params = array(
- 'uid'=>$uid,
- 'weibotype'=>'qq',
- 'nickname'=>$nickname,
- 'openid'=>$conopenid,
- 'unionid'=>$response['unionid'],
- 'dateline'=>time()
- );
- DB::insert('thirdbind',$params,true);
- }elseif($qqunionid == '')
- {
- //有记录,但未注册unionid
- DB::update("thirdbind", array("unionid" => $response['unionid']), array('uid'=>$uid, 'weibotype'=>'qq'));
- }
- }
- }
复制代码
2.需要更新qianfan插件
qianfan/protected/controllers/MemberController.php
文件
MemberController.zip
(13.08 KB, 下载次数: 445)
|
|