wordpress里的modown主题开发抖音小程序,但是提交审核时官方说明要加上抖音授权登录,下面模板兔给出相关逻辑代码供参考:
小程序端js:
tt.login({ force: true, success(res) { //console.log(`login 调用成功${res.code} ${res.anonymousCode}`); if (res.code) { wx.request({ url: app.globalData.appUrl, data: { action: "login", code: res.code, aff: aff }, method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res2) { console.log(res2.data); wx.hideToast(); if (res2.data.errCode == '0'){ }else{ wx.showToast({ title: '登录失败', icon: 'none', duration: 3000 }); } }, fail: function(){ wx.showToast({ title: '登录失败', icon: 'none', duration: 3000 }); } }) } }, fail(res) { }, });
网站服务端php
$erphpapp_dyappid = get_option("erphpapp_dyappid"); $erphpapp_dyappsecret = get_option("erphpapp_dyappsecret"); $url='https://developer.toutiao.com/api/apps/v2/jscode2session'; $data=[ 'appid'=>$erphpapp_dyappid, 'secret'=>$erphpapp_dyappsecret, 'code'=>$code ]; $jscode2session=erphpapp_http($url,json_encode($data),'POST'); $arr=json_decode($jscode2session,true); $result = array(); $result['errMsg'] = ''; $result['errCode'] = 0; if($arr['err_no']==0){ $openid = $arr['data']['openid']; $unionid = $arr['data']['unionid']; }
0 个评论