1. 信任登陆开发

在b2b2c中添加新的信任登陆 1: 配置文件修改

bbc/config/userAuth.php
return array(
    'trustLogins' => [
        'weibo',
        'qq',
        'renren',
        'weixin',
        'wapweixin',
    ],
);
如果要新加一个就在后面加上需要添加的名字

2: 运营后台的配置(以qq为列子)

(1)在bbc/app/sysuser/lib/plugin/ 新建qq.php

class sysuser_plugin_qq extends sysuser_plugin_abstract implements sysuser_interface_trust
{
    public $name = 'QQ登陆'; //名称
    public $flag = 'qq'; //标示
    public $version = '2.0'; //版本 
    public $platform = ['web','wap']; //显示终端
    public $authUrls = ['web' => ['authorize' => 'https://graph.qq.com/oauth2.0/authorize',
                                  'token' => 'https://graph.qq.com/oauth2.0/token',
                                  'openid' => 'https://graph.qq.com/oauth2.0/me',
                                  'userinfo' => 'https://graph.qq.com/user/get_user_info']]; //qq提供的获取code  tocken   openid  以及用户信息的接口

    //生成前端登陆那块的连接
    public function getAuthorizeUrl($state)
    {
        ......
    }
    //通过code获取tocken
    public function generateAccessToken($code)
    {
        ......   
    }
    //获取openid 根据tocken
    public function generateOpenId()
    {
        ......
    }
    //获取用户信息 根据tocken  openid  key
    public function generateUserInfo()
    {
        ......
    }
    protected function convertStandardUserInfo($trustUserInfo)
    {
        return $userInfo = ['openid' => $this->getOpenId(),
                            'access_token' => $this->getAccessToken(),
                            'nickname' => $trustUserInfo['nickname'],
                            'figureurl' => $trustUserInfo['figureurl']];
    }

(2):在bbc/app/sysuser/view/trust/ 新建qq.html 用于运营后台配置

    <form id="trustlogin" name="trustlogin"  method='post' action='?app=sysuser&ctl=admin_trustlogincfg&act=saveCfg'>
    <div id="x-g-basic" class="goods-detail">
            <input type="hidden" name="libclass" value="<{$libclass}>">
            <div class="tableform">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <th><em class="red">*</em><{t}>appid:<{/t}></th>
                      <td><{input type="text" name="data[appid]"  required="true" vtype='required' value=$data.appid}></td>
                    </tr>
                    <tr>
                      <th><em class="red">*</em><{t}>appkey:<{/t}></th>
                      <td><{input type="text" name="data[appkey]" required="true" vtype='required' value=$data.appkey}></td>
                    </tr>
                    <tr>
                      <th><em><font color='red'>*</font></em><{t}>启用状态:<{/t}></th>
                      <td><{input type="bool" name="data[status]" value=$data.status}></td>
                    </tr>
                </table>
            </div>
    </div>
    <table cellspacing="0" cellpadding="0" class="table-action">
          <tbody><tr valign="middle">
            <td>
                    <{assign var="___a"  value="关  闭"}>
                    <{assign var="___c"  value=$___trustlogin='确定退出?'|t:'trustlogin'}>
                    <{button label=$___trustlogin="保存并关闭窗口"|t:'trustlogin' class="btn-primary" type="button" isclosedialogbtn="1" onclick="submitForm(event,2)"}>
                    <!--<{button label="保  存" class="btn-primary" onclick="submitForm(event,1)"}>-->
                    <{button label=$___trustlogin=$___a|t:'trustlogin' class="btn-secondary" type="button" isclosedialogbtn="1"}>
            </td>
            </tr>
            </tbody></table>
    </form>
    <script>
          var submitForm = function (event,sign){
            var _form=$('trustlogin');
            switch (sign){
                case 1:
                var target={
                    onComplete:function(){
                        location.reload();
                }};
                break;
                case 2:
                var target={
                    onComplete:function(rs){
                        if(rs&&!!JSON.decode(rs).success){
                            try{
                                window.opener.finderGroup['<{$env.get.finder_id}>'].refresh();
                                window.close();
                            }catch(e){}
                        }
                }};
                break;
            }
            _form.store('target',target);
            _form.fireEvent('submit',new Event(event));
        };
    </script>

3:调试流程

(1):前台调用的地方:bbc/app/topc/controller/passport.php  sigin()
(1):回调的方法:bbc/app/topc/controller/trustlogin.php callback()

4:流程

(1):买家登陆处信任登陆按钮
(2):跳转到第三方授权登陆
(3):调用第三方的接口获取用户信息
(4):把第三方的信息存到系统,系统生成新的用户名密码
(5):系统做登陆操作

results matching ""

    No results matching ""