mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-22 14:27:21 +08:00
uniapp【优化】: 支付宝登录功能
This commit is contained in:
@@ -53,3 +53,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.alipay-btn {
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
width: 100%;
|
||||||
|
font-size: 14px;
|
||||||
|
position: absolute;
|
||||||
|
left: 0px;
|
||||||
|
top: 0px;
|
||||||
|
z-index: 99;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
.btn-tit{
|
||||||
|
display: block;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,8 +32,19 @@
|
|||||||
text="暂不授权"></uv-button>
|
text="暂不授权"></uv-button>
|
||||||
</view>
|
</view>
|
||||||
<view class="btn">
|
<view class="btn">
|
||||||
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
<uv-button v-if="state.agreement" :customStyle="{ 'width': '100%' }" openType="getPhoneNumber"
|
<uv-button v-if="state.agreement" :customStyle="{ 'width': '100%' }" openType="getPhoneNumber"
|
||||||
@getphonenumber="getPhoneNumber" type="success" size="normal" text="确定授权"></uv-button>
|
@getphonenumber="getPhoneNumber" type="success" size="normal" text="确定授权"></uv-button>
|
||||||
|
<!-- #endif -->
|
||||||
|
<!-- #ifdef MP-ALIPAY -->
|
||||||
|
<uv-button v-if="state.agreement" :customStyle="{ 'width': '100%' ,'position':'relative'}"
|
||||||
|
type="success" size="normal">
|
||||||
|
<button class="alipay-btn" type="success" size="mini" open-type="getAuthorize"
|
||||||
|
scope="phoneNumber" @getAuthorize="getAliPhoneNumber" v-if="state.agreement">
|
||||||
|
<view class="btn-tit">确定授权</view>
|
||||||
|
</button>
|
||||||
|
</uv-button>
|
||||||
|
<!-- #endif -->
|
||||||
<uv-button v-else @click="handleClickOk" :customStyle="{ 'width': '100%' }" type="success"
|
<uv-button v-else @click="handleClickOk" :customStyle="{ 'width': '100%' }" type="success"
|
||||||
size="normal" text="确定授权"></uv-button>
|
size="normal" text="确定授权"></uv-button>
|
||||||
</view>
|
</view>
|
||||||
@@ -46,7 +57,7 @@
|
|||||||
import { useShopConfigStore, useUserInfoStore } from '@/core/store';
|
import { useShopConfigStore, useUserInfoStore } from '@/core/store';
|
||||||
import type { Response } from '@/core/models';
|
import type { Response } from '@/core/models';
|
||||||
import { Invitecode, UserToken } from '@/core/consts';
|
import { Invitecode, UserToken } from '@/core/consts';
|
||||||
import { queryLoginPhoneNumber, queryLogin, queryAliPayAppAuthTokenBYCode } from '@/core/api';
|
import { queryLoginPhoneNumber, queryLogin, queryAliPayAppAuthTokenBYCode ,queryDecryptPhoneNumberByAli} from '@/core/api';
|
||||||
import { loginGetCode, handleShowToast, handleRouteNavigateTo } from '@/core/utils';
|
import { loginGetCode, handleShowToast, handleRouteNavigateTo } from '@/core/utils';
|
||||||
|
|
||||||
/** 获取项目配置 */
|
/** 获取项目配置 */
|
||||||
@@ -97,7 +108,7 @@
|
|||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP-ALIPAY
|
// #ifdef MP-ALIPAY
|
||||||
const login : Response<any> = await queryAliPayAppAuthTokenBYCode({id:code});
|
const login : Response<any> = await queryAliPayAppAuthTokenBYCode({ id: code });
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
if (login.status) {
|
if (login.status) {
|
||||||
@@ -137,7 +148,7 @@
|
|||||||
state.agreement = false;
|
state.agreement = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取授权手机号 */
|
/** 微信获取授权手机号 */
|
||||||
const getPhoneNumber = (e : any) => {
|
const getPhoneNumber = (e : any) => {
|
||||||
emits('handleChangePopup', false);
|
emits('handleChangePopup', false);
|
||||||
if (e.errMsg.includes('ok')) {
|
if (e.errMsg.includes('ok')) {
|
||||||
@@ -156,9 +167,37 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 支付宝获取授权手机号 */
|
||||||
|
const getAliPhoneNumber = () => {
|
||||||
|
emits('handleChangePopup', false);
|
||||||
|
my.getPhoneNumber({
|
||||||
|
success: (res : any) => {
|
||||||
|
let encryptedData = JSON.parse(res.response);
|
||||||
|
let data = {
|
||||||
|
sessionAuthId: state.sessionAuthIdTool,
|
||||||
|
sign: encryptedData.sign,
|
||||||
|
encryptedData: encryptedData.response,
|
||||||
|
}
|
||||||
|
/** 有推荐码的话,带上 */
|
||||||
|
if (uni.getStorageSync(Invitecode)) {
|
||||||
|
data['invitecode'] = uni.getStorageSync(Invitecode);
|
||||||
|
}
|
||||||
|
handleLogin(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** 去登录获取数据 */
|
/** 去登录获取数据 */
|
||||||
const handleLogin = async (data : any) => {
|
const handleLogin = async (data : any) => {
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
const phoneNumber : Response<any> = await queryLoginPhoneNumber(data);
|
const phoneNumber : Response<any> = await queryLoginPhoneNumber(data);
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-ALIPAY
|
||||||
|
const phoneNumber : Response<any> = await queryDecryptPhoneNumberByAli(data);
|
||||||
|
// #endif
|
||||||
|
|
||||||
if (phoneNumber.status && phoneNumber.data.token) {
|
if (phoneNumber.status && phoneNumber.data.token) {
|
||||||
uni.setStorageSync(UserToken, phoneNumber.data.token);
|
uni.setStorageSync(UserToken, phoneNumber.data.token);
|
||||||
if (phoneNumber.otherData) {
|
if (phoneNumber.otherData) {
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
import { post } from '@/core/utils/http';
|
import { post } from '@/core/utils/http';
|
||||||
import type { Response } from '@/core/models';
|
import type { Response } from '@/core/models';
|
||||||
|
|
||||||
/** 获取商品分类配置 */
|
/** 小程序手机授权(拉取手机号码) */
|
||||||
export const queryLoginPhoneNumber = (data : any) : Promise<Response<any>> => {
|
export const queryLoginPhoneNumber = (data : any) : Promise<Response<any>> => {
|
||||||
return post('Api/User/DecryptPhoneNumber', {
|
return post('Api/User/DecryptPhoneNumber', {
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 支付宝小程序手机授权(拉取手机号码) */
|
||||||
|
export const queryDecryptPhoneNumberByAli = (data : any) : Promise<Response<any>> => {
|
||||||
|
return post('Api/User/DecryptPhoneNumberByAli', {
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** 小程序解析code */
|
/** 小程序解析code */
|
||||||
export const queryLogin = (data : any) : Promise<Response<any>> => {
|
export const queryLogin = (data : any) : Promise<Response<any>> => {
|
||||||
return post('Api/User/OnLogin', {
|
return post('Api/User/OnLogin', {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<!-- #ifndef MP-ALIPAY -->
|
<coreshop-navbar :isBack="false" mode="left" title="购物车"> </coreshop-navbar>
|
||||||
<coreshop-navbar :isBack="false" mode="left" title="购物车"> </coreshop-navbar>
|
|
||||||
<!-- #endif -->
|
|
||||||
<view class="content-box p-25 page-bg">
|
<view class="content-box p-25 page-bg">
|
||||||
<view class="cart-box" v-if="state.cartList.length > 0">
|
<view class="cart-box" v-if="state.cartList.length > 0">
|
||||||
<view class="all-select" :style="{ 'top': `${statusBarHeight}px` }">
|
<view class="all-select" :style="{ 'top': `${statusBarHeight}px` }">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<coreshop-page :title="state.isScrollToTop ? '' :userInfoStore.userInfo?.nickName" :placeholder="false"
|
<coreshop-page :title="state.isScrollToTop ? '' :userInfoStore.userInfo?.nickName" :placeholder="false"
|
||||||
titleColor="#fff" mode="left" bgColor="#d33123" :isShowStatusBarHeight="false" :isBack="false"
|
titleColor="#fff" mode="left" :bgColor="state.isScrollToTop ? 'rgba(0,0,0,0)':'#d33123'" :isShowStatusBarHeight="false" :isBack="false"
|
||||||
showLoginModalDom>
|
showLoginModalDom>
|
||||||
<view class="layout-member-page">
|
<view class="layout-member-page">
|
||||||
<view class="member-head">
|
<view class="member-head">
|
||||||
|
|||||||
Reference in New Issue
Block a user