聯(lián)系官方銷售客服
1835022288
028-61286886
QQ小程序授權(quán)登入和微信小程序登入除了請(qǐng)求接口和APPid不同外其他的都是一樣的,我把微信小程序的API登入接口改成QQ的后就可以直接登入了,請(qǐng)問怎么在增加個(gè)登入接口,讓微信小程序登入和QQ小程序同時(shí)能用
下面這個(gè)是我把微信的請(qǐng)求接口和改成QQ了
// 小程序登錄 public function xcx() { if (IS_POST) { $json = json_decode($_POST['json'], true); if (!$json) { $this->_json(0, 'POST數(shù)據(jù)解析失敗'); } elseif (!$_POST['js_code']) { $this->_json(0, 'js_code數(shù)據(jù)獲取失敗'); } $url = "https://api.q.qq.com/sns/jscode2session?appid=" . $this->weixin['xcx']['appid'] . "&secret=".$this->weixin['xcx']['appsecret']."&js_code=". $_POST['js_code']."&grant_type=authorization_code"; $token = json_decode(dr_catcher_data($url), true); if (!$token) { $this->_json(0, 'jscode2session獲取失敗'); } elseif (isset($token['errcode']) && $token['errcode']) { $this->_json(0, 'jscode2session錯(cuò)誤代碼('.$token['errcode'].'):'.$token['errmsg'].' appid='.$this->weixin['xcx']['appid'].'&secret='.$this->weixin['xcx']['appsecret'].''); } elseif (!$token['openid']) { $this->_json(0, 'jscode2session:openid獲取失敗'); } $rt = \Phpcmf\Service::M('member')->insert_oauth(0, 'login', [ 'oid' => $token['openid'], 'oauth' => 'wxxcx', 'avatar' => $json['avatarUrl'], 'unionid' => (string)$token['unionid'], 'nickname' => dr_emoji2html($json['nickName']), 'expire_at' => SYS_TIME, 'access_token' => $token['session_key'], 'refresh_token' => '', ]); if (!$rt['code']) { $this->_json(0, $rt['msg']); } $oauth = \Phpcmf\Service::M()->table('member_oauth')->get($rt['code']); if (!$oauth) { $this->_json(0, '服務(wù)端儲(chǔ)存用戶失敗'); } elseif ($oauth['uid']) { $rt = \Phpcmf\Service::M('member')->login_uid($oauth, $oauth['uid']); if (!$rt['code']) { $this->_json(0, $rt['msg']); } $this->_json(1, 'login', $rt['data']); } if ($this->weixin['xcx']['login']) { // 直接登錄 $rt = \Phpcmf\Service::M('member')->register_oauth(0, $oauth); if ($rt['code']) { // 登錄成功 $this->_json(1, 'login', $rt['data']); } else { $this->_json(0, $rt['msg']); } } else { // 提示注冊(cè) $oauth['nickname'] = dr_html2emoji($oauth['nickname']); $this->_json(1, 'register', $oauth); } } else { $this->_json(0, '非POST提交'); } exit; } // 小程序綁定賬號(hào) public function xcx_bang() { if (IS_POST) { $oid = (int)\Phpcmf\Service::L('Input')->post('oid'); $post = \Phpcmf\Service::L('Input')->post('data', true); if (!$post) { $this->_json(0, 'POST數(shù)據(jù)解析失敗'); } elseif (!$oid) { $this->_json(0, '小程序OpenId為空'); } $oauth = \Phpcmf\Service::M()->table('member_oauth')->get($oid); if (!$oauth) { $this->_json(0, '服務(wù)端用戶不存在'); } elseif ($oauth['uid']) { $rt = \Phpcmf\Service::M('member')->login_uid($oauth, $oauth['uid']); if (!$rt['code']) { $this->_json(0, $rt['msg']); } $this->_json(1, 'ok', $rt['data']); } // 登錄綁定 if (empty($post['username']) || empty($post['password'])) { $this->_json(0, dr_lang('賬號(hào)或密碼必須填寫')); } else { $rt = \Phpcmf\Service::M('member')->login($post['username'], $post['password']); if ($rt['code']) { // 登錄成功 \Phpcmf\Service::M()->db->table('member_oauth')->where('id', $oid)->update(['uid' => $rt['data']['member']['id']]); $this->_json(1, 'ok', $rt['data']); } else { $this->_json(0, $rt['msg']); } } } else { $this->_json(0, '非POST提交'); } } // 小程序注冊(cè)賬號(hào) public function xcx_reg() { if (IS_POST) { $oid = (int)\Phpcmf\Service::L('Input')->post('oid'); $post = \Phpcmf\Service::L('Input')->post('data', true); if (!$post) { $this->_json(0, 'POST數(shù)據(jù)解析失敗'); } elseif (!$oid) { $this->_json(0, '小程序OpenId為空'); } $oauth = \Phpcmf\Service::M()->table('member_oauth')->get($oid); if (!$oauth) { $this->_json(0, '服務(wù)端用戶不存在'); } elseif ($oauth['uid']) { $rt = \Phpcmf\Service::M('member')->login_uid($oauth, $oauth['uid']); if (!$rt['code']) { $this->_json(0, $rt['msg']); } $this->_json(1, 'ok', $rt['data']); } // 注冊(cè) if (empty($post['password'])) { $this->_json(0, dr_lang('密碼必須填寫'), ['field' => 'password']); } elseif ($post['password'] != $post['password2']) { $this->_json(0, dr_lang('確認(rèn)密碼不一致'), ['field' => 'password2']); } else { $rt = \Phpcmf\Service::M('member')->register_oauth_bang($oauth, 0, [ 'username' => (string)$post['username'], 'phone' => (string)$post['phone'], 'email' => (string)$post['email'], 'password' => dr_safe_password($post['password']), 'name' => dr_safe_replace($post['name']), ]); if ($rt['code']) { // 注冊(cè)綁定成功 $this->_json(1, 'ok', $rt['data']); } else { $this->_json(0, $rt['msg'], ['field' => $rt['data']['field']]); } } } else { $this->_json(0, '非POST提交'); } }
新建新建一個(gè)php文件就不會(huì)沖突了,比如以前叫Xx.php,你復(fù)制一個(gè)改成Bb.php
回復(fù)@官方插件技術(shù)-實(shí)習(xí)
這個(gè)是微信插件里面的小程序配置文件呀!嘗試直接在這個(gè)php里復(fù)制份一樣的代碼后是不行的
復(fù)制后,還需要修改文件里面的類名,訪問時(shí)地址也要發(fā)生變化
回復(fù)@官方插件技術(shù)-實(shí)習(xí) 這個(gè)賬號(hào)設(shè)置頁面也有增加一個(gè),感覺好難,官方能不能加個(gè)QQ小程序的配置接口呀
目前微信插件沒有這種功能,需要你自己二次開發(fā)