微学网

热门关键词:   as  thinkphp  ecshop  商务通  xxx  www.ymwears.cn
热门: ASP.NET PHP编程 ASP编程 JSP编程 Python

淘宝客app渠道授权

发布时间:2020-10-08 来源:未知 点击:

关于淘客的渠道授权这里先简单介绍下

主要流程,先获取淘宝私域用户权限,百度淘宝私域用户填写申请表

详细流程,https://blog.csdn.net/wm5i5i/article/details/86691296

 

//后端代码 仅供参考

public function taoBao()
{
    $param = $this->request->param();
    $code = $param['code'];
    $uid = Db::name('members')->where('token', $param['token'])->value('id');
    $collect_config = json_decode(get_db_config('collect'), true);
    //从配置文件中读取
    $appkey = $collect_config['appkey'];
    $secret = $collect_config['secret'];
    include EXTEND_PATH . 'tbk1/TopSdk.php';
    include EXTEND_PATH . 'tbk1/top/request/TopAuthTokenCreateRequest.php';
    include EXTEND_PATH . 'tbk1/top/request/TbkScPublisherInfoSaveRequest.php';
    $c = new \TopClient();
    $c->appkey = $appkey;
    $c->secretKey = $secret;
    $c->format = 'json';
    $url = 'https://oauth.taobao.com/token';
    $postfields = [
        'client_id' => $appkey,
        'client_secret' => $secret,
        'grant_type' => 'authorization_code',
        'code' => $code,
        'redirect_uri' => $this->request->domain() . "/api/auth/tbToken",
        'view' => 'wap'
    ];
    $post_data = '';
    foreach ($postfields as $key => $value) {
        $post_data .= "$key=" . urlencode($value) . "&";
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_data, 0, -1));
    $output = curl_exec($ch);
    curl_close($ch);
    $arr = json_decode($output, true);
    $show_msg = "授权失败,请重新授权";
    if (isset($arr['access_token'])) {
        $sessionKey = $arr['access_token'];
        $yq_code = (new QudaoController())->get_yq_code();      //渠道邀请码
        $req = new \TbkScPublisherInfoSaveRequest;
        $req->setRelationFrom("1");
        $req->setOfflineScene("1");
        $req->setOnlineScene("1");
        $req->setInviterCode($yq_code);
        $req->setInfoType("1");
        $req->setNote("tangguoguo");
        $req->setRegisterInfo("{}");
        $resp = $c->execute($req, $sessionKey);
        $str = json_encode($resp, JSON_FORCE_OBJECT);
        $info = json_decode($str, true);
        //var_dump($info);
        if (isset($info['data']['relation_id'])) {
            $relation_id = $info['data']['relation_id'];
            $account_name = $info['data']['account_name'];
            $up = Db::name('members')->where('id', $uid)->update(['relation_id' => $relation_id, 'tb_nick' => $account_name]);
            if ($up) {
                $show_msg = '授权成功';
            }
        } else if (isset($info['sub_msg'])) {
            $show_msg = $info['sub_msg'];
        }
    }
    config('default_return_type', 'html');
    $this->assign("show_msg", $show_msg);
    return $this->fetch('qudao/back_bind');
}

 

//前端代码 获取授权登录页面

isAuth: function () {
    let that = this;
    http(taobaoAuth, 'post', {},
        function (ret) {
            if (ret.code == 0) {
                api.toast({
                    msg: "已授权",
                    duration: 2000,
                    location: 'bottom'
                });
            } else {
                let install = that.bai_chuan.is_instll();
                if(install){
                    //alert(1);
                    //安装了手淘,走正常路径....
                    that.bai_chuan.showLogin({
                        openType: 2,
                    }, function(ret, err){
                        if (ret.code == 0) {
                            let userInfo = $api.getStorage('userInfo');
                            let redirect_uri = baseUrl + "auth/taoBao?token=" + userInfo.token;
                            let url = 'https://oauth.taobao.com/authorize?response_type=code&client_id=29322258&view=wap&redirect_uri='+redirect_uri
                            console.log(url)
                            that.bai_chuan.showUrlPage({ url: url});
                        } else {
                            alert(JSON.stringify(err));
                        }
                    });
                }else{
                    //没安装手淘,调用apiCloud内置方法打开网页
                    alert('请先安装淘宝app')
                    // api.openWin({
                    //     name: 'url_'+Math.random(),
                    //     url: url,
                    // });
                }
            }
        })

},

 



这就是微学网-程序员之家为你提供的"淘宝客app渠道授权"希望对你有所帮助.本文来自网络,转载请注明出处:http://www.weixuecn.cn/article/14048.html
网络编程 | 前端制作 | 数据库 | CMS教程 | 脚本编程 | 框架 | 服务器 | 微信开发 | APP开发 |

凡本网站转载的文章、图片等资料的版权归版权所有人所有,因无法和版权所有者一一联系,如果本网站选取的文/图威胁到您的权益,请您及时和本网站联系。 我们会在第一时间内采取措施,避免给双方造 成不必要的损失。
© 2015-2018 微学网 版权所有,并保留所有权利。 备案号:粤ICP备09051474号-1

菜鸟教程,提供各类程序编程入门,技巧