个人信息:增加读取社交信息的接口

pull/32/MERGE
YunaiV 2023-12-23 22:04:11 +08:00
parent f968397ad8
commit 4d9343d2db
6 changed files with 121 additions and 49 deletions

View File

@ -127,9 +127,9 @@
</view> </view>
</uni-forms> </uni-forms>
<!-- 当前社交平台的绑定关系只处理 wechat 微信场景 -->
<view v-if="sheep.$platform.name !== 'H5'"> <view v-if="sheep.$platform.name !== 'H5'">
<view class="title-box ss-p-l-30">第三方账号绑定</view> <view class="title-box ss-p-l-30">第三方账号绑定</view>
<view class="account-list ss-flex ss-row-between"> <view class="account-list ss-flex ss-row-between">
<view v-if="'WechatOfficialAccount' === sheep.$platform.name" class="ss-flex ss-col-center"> <view v-if="'WechatOfficialAccount' === sheep.$platform.name" class="ss-flex ss-col-center">
<image <image
@ -153,16 +153,16 @@
<text class="list-name">微信开放平台</text> <text class="list-name">微信开放平台</text>
</view> </view>
<view class="ss-flex ss-col-center"> <view class="ss-flex ss-col-center">
<view class="info ss-flex ss-col-center" v-if="state.thirdOauthInfo"> <view class="info ss-flex ss-col-center" v-if="state.thirdInfo">
<image <image
class="avatar ss-m-r-20" class="avatar ss-m-r-20"
:src="sheep.$url.cdn(state.thirdOauthInfo.avatar)" :src="sheep.$url.cdn(state.thirdInfo.avatar)"
></image> />
<text class="name">{{ state.thirdOauthInfo.nickname }}</text> <text class="name">{{ state.thirdInfo.nickname }}</text>
</view> </view>
<view class="bind-box ss-m-l-20"> <view class="bind-box ss-m-l-20">
<button <button
v-if="state.thirdOauthInfo" v-if="state.thirdInfo.openid"
class="ss-reset-button relieve-btn" class="ss-reset-button relieve-btn"
@tap="unBindThirdOauth" @tap="unBindThirdOauth"
> >
@ -193,7 +193,7 @@
const state = reactive({ const state = reactive({
model: {}, // model: {}, //
rules: {}, rules: {},
thirdOauthInfo: null, thirdInfo: {}, //
}); });
const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal'; const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
@ -210,17 +210,17 @@
const userInfo = computed(() => sheep.$store('user').userInfo); const userInfo = computed(() => sheep.$store('user').userInfo);
// TODO //
function onChangeGender(e) { function onChangeGender(e) {
state.model.sex = e.detail.value; state.model.sex = e.detail.value;
} }
// TODO //
const onChangeMobile = () => { const onChangeMobile = () => {
showAuthModal('changeMobile'); showAuthModal('changeMobile');
}; };
// TODO //
function onChooseAvatar(e) { function onChooseAvatar(e) {
const tempUrl = e.detail.avatarUrl || ''; const tempUrl = e.detail.avatarUrl || '';
uploadAvatar(tempUrl); uploadAvatar(tempUrl);
@ -258,7 +258,7 @@
} }
} }
// TODO //
function unBindThirdOauth() { function unBindThirdOauth() {
uni.showModal({ uni.showModal({
title: '解绑提醒', title: '解绑提醒',
@ -266,11 +266,12 @@
cancelText: '再想想', cancelText: '再想想',
confirmText: '确定', confirmText: '确定',
success: async function (res) { success: async function (res) {
if (res.confirm) { if (!res.confirm) {
const result = await sheep.$platform.useProvider('wechat').unbind(); return;
if (result) { }
getUserInfo(); const result = await sheep.$platform.useProvider('wechat').unbind(state.thirdInfo.openid);
} if (result) {
await getUserInfo();
} }
}, },
}); });
@ -294,14 +295,10 @@
const userInfo = await sheep.$store('user').getInfo(); const userInfo = await sheep.$store('user').getInfo();
state.model = clone(userInfo); state.model = clone(userInfo);
// TODO //
if (sheep.$platform.name !== 'H5') { if (sheep.$platform.name !== 'H5') {
return; const result = await sheep.$platform.useProvider('wechat').getInfo();
// ,, state.thirdInfo = result || {};
let { data, error } = await sheep.$api.user.thirdOauthInfo();
if (error === 0) {
state.thirdOauthInfo = data;
}
} }
}; };

View File

@ -0,0 +1,54 @@
import request from '@/sheep/request';
const SocialApi = {
// 获得社交用户
getSocialUser: (type) => {
return request({
url: '/app-api/member/social-user/get',
method: 'GET',
params: {
type
},
custom: {
showLoading: false,
},
});
},
// 社交绑定
socialBind: (type, code, state) => {
return request({
url: '/app-api/member/social-user/bind',
method: 'POST',
data: {
type,
code,
state
},
custom: {
custom: {
showSuccess: true,
loadingMsg: '绑定中',
successMsg: '绑定成功',
},
},
});
},
// 社交绑定
socialUnbind: (type, openid) => {
return request({
url: '/app-api/member/social-user/unbind',
method: 'DELETE',
data: {
type,
openid
},
custom: {
showLoading: false,
loadingMsg: '解除绑定',
successMsg: '解绑成功',
},
});
},
};
export default SocialApi;

View File

@ -28,18 +28,6 @@ export default {
}, },
}), }),
// 解除绑定微信
unbind: (data) =>
request({
url: 'third/wechat/unbind',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '解除绑定',
},
}),
// 公众号授权 // 公众号授权
oauthLogin: (data) => oauthLogin: (data) =>
request({ request({

View File

@ -1,6 +1,6 @@
import third from '@/sheep/api/third'; import third from '@/sheep/api/third';
import $store from '@/sheep/store';
import AuthUtil from '@/sheep/api/member/auth'; import AuthUtil from '@/sheep/api/member/auth';
import SocialApi from '@/sheep/api/member/social';
const socialType = 34; // 社交类型 - 微信小程序 const socialType = 34; // 社交类型 - 微信小程序
@ -83,11 +83,9 @@ const bind = () => {
}; };
// 微信小程序解除绑定 // 微信小程序解除绑定
const unbind = async () => { const unbind = async (openid) => {
const { error } = await third.wechat.unbind({ const { code } = await SocialApi.socialUnbind(socialType, openid);
platform: 'miniProgram', return code === 0;
});
return !error;
}; };
// 小程序更新 // 小程序更新
@ -183,13 +181,22 @@ function setOpenid(openid) {
uni.setStorageSync('openid', openid); uni.setStorageSync('openid', openid);
} }
// 获得社交信息
async function getInfo() {
const { code, data } = await SocialApi.getSocialUser(socialType);
if (code !== 0) {
return undefined;
}
return data;
}
export default { export default {
load, load,
login, login,
bind, bind,
unbind, unbind,
checkUpdate,
bindUserPhoneNumber, bindUserPhoneNumber,
mobileLogin, mobileLogin,
getInfo,
subscribeMessage, subscribeMessage,
}; };

View File

@ -2,6 +2,7 @@ import third from '@/sheep/api/third';
import $wxsdk from '@/sheep/libs/sdk-h5-weixin'; import $wxsdk from '@/sheep/libs/sdk-h5-weixin';
import { getRootUrl } from '@/sheep/helper'; import { getRootUrl } from '@/sheep/helper';
import AuthUtil from '@/sheep/api/member/auth'; import AuthUtil from '@/sheep/api/member/auth';
import SocialApi from '@/sheep/api/member/social';
const socialType = 31; // 社交类型 - 微信公众号 const socialType = 31; // 社交类型 - 微信公众号
@ -51,13 +52,10 @@ async function bind(code = '') {
} }
// 微信公众号解除绑定 // 微信公众号解除绑定
async function unbind() { const unbind = async (openid) => {
debugger const { code } = await SocialApi.socialUnbind(socialType, openid);
const { error } = await third.wechat.unbind({ return code === 0;
platform: 'officialAccount', };
});
return Promise.resolve(!error);
}
// 获取公众号登陆地址 // 获取公众号登陆地址
async function getLoginUrl(event = 'login') { async function getLoginUrl(event = 'login') {
@ -104,10 +102,20 @@ function setOpenid(openid) {
uni.setStorageSync('openid', openid); uni.setStorageSync('openid', openid);
} }
// 获得社交信息
async function getInfo() {
const { code, data } = await SocialApi.getSocialUser(socialType);
if (code !== 0) {
return undefined;
}
return data;
}
export default { export default {
load, load,
login, login,
bind, bind,
unbind, unbind,
getInfo,
jssdk: $wxsdk, jssdk: $wxsdk,
}; };

View File

@ -1,7 +1,9 @@
// 登录 // 登录
import third from '@/sheep/api/third'; import third from '@/sheep/api/third';
import SocialApi from '@/sheep/api/member/social';
// TODO 芋艿:等后面搞 App 再弄 // TODO 芋艿:等后面搞 App 再弄
const socialType = 32; // 社交类型 - 微信开放平台
const load = async () => {}; const load = async () => {};
@ -37,7 +39,23 @@ const login = () => {
}); });
}; };
// 微信 App 解除绑定
const unbind = async (openid) => {
const { code } = await SocialApi.socialUnbind(socialType, openid);
return code === 0;
};
// 获得社交信息
async function getInfo() {
const { code, data } = await SocialApi.getSocialUser(socialType);
if (code !== 0) {
return undefined;
}
return data;
}
export default { export default {
load, load,
login, login,
getInfo
}; };