推送 云函数 一键登录

This commit is contained in:
haomingming
2025-09-30 16:42:25 +08:00
parent 570e47698c
commit 65b2d269c5
11 changed files with 203 additions and 48 deletions
+18 -1
View File
@@ -53,11 +53,28 @@ export default {
uni.onPushMessage((res)=>{
console.log("收到推送消息:", res)
uni.showModal({
uni.showModal({
title: res.data.title,
content: res.type,
showCancel: false
});
if(res.type === 'click' ){
}else{
uni.createPushMessage({
title: res.data.title,
content: res.data.content,
payload: res.data.payload,
delay: 1,
success: (res) => {
console.log("创建推送消息成功", res)
}
})
}
})
/** 设置语言 (此处为了方便demo切换语言,将其存到本地,实际需根据业务情况设置)*/
+4 -3
View File
@@ -2,8 +2,8 @@
"name" : "肝胆相照专家端",
"appid" : "__UNI__89F511F",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"versionName" : "4.1.5",
"versionCode" : 415,
"transformPx" : false,
"app-plus" : {
/* 5+App特有相关 */
@@ -59,7 +59,8 @@
"appid" : "wxbf3658f5e674667c",
"appsecret" : "c4505a04a9910c65efea8e11ffc93f92",
"UniversalLinks" : "https://doc.igandan.com/gdxzExpert/"
}
},
"univerify" : {}
},
"payment" : {
"weixin" : {
+7
View File
@@ -85,6 +85,13 @@
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path" : "pages/univerify/univerify",
"style" :
{
"navigationBarTitleText" : ""
}
}
],
+1 -1
View File
@@ -777,7 +777,6 @@ const switchPushPermissions = () => {
width: 120rpx;
height: 120rpx;
border-radius: 10rpx;
}
.user-info-content {
@@ -785,6 +784,7 @@ const switchPushPermissions = () => {
flex-direction: column;
align-items: flex-start;
gap: 10rpx;
margin-left: 10rpx;
.username {
color: $white;
+105
View File
@@ -0,0 +1,105 @@
<template>
<view>
</view>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
import { onShow, onLoad } from "@dcloudio/uni-app";
// 页面加载
onLoad(() => {
console.log('登录页面加载完成');
// #ifdef APP
console.log('一键登录');
uni.login({
provider: 'univerify',
univerifyStyle: {
"fullScreen": true, // 是否全屏显示,默认值: false
"backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
"backgroundImage": "", // 全屏显示的背景图片,默认值:"" (仅支持本地图片,只有全屏显示时支持)
"icon": {
"path": "static/xxx.png", // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo
"width": "60px", //图标宽度 默认值:60px
"height": "60px" //图标高度 默认值:60px
},
"closeIcon": {
"path": "static/xxx.png", // 自定义显示在授权框中的logo,仅支持本地图片
"width": "60px", //图标宽度 默认值:60px (HBuilderX 4.0+ 仅iOS支持)
"height": "60px" //图标高度 默认值:60px (HBuilderX 4.0+ 仅iOS支持)
},
"phoneNum": {
"color": "#202020" // 手机号文字颜色 默认值:#202020
},
"slogan": {
"color": "#BBBBBB" // slogan 字体颜色 默认值:#BBBBBB
},
"authButton": {
"normalColor": "#3479f5", // 授权按钮正常状态背景颜色 默认值:#3479f5
"highlightColor": "#2861c5", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
"disabledColor": "#73aaf5", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
"textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
"title": "本机号码一键登录", // 授权按钮文案 默认值:“本机号码一键登录”
"borderRadius": "24px" // 授权按钮圆角 默认值:"24px" (按钮高度的一半)
},
"otherLoginButton": {
"visible": true, // 是否显示其他登录按钮,默认值:true
"normalColor": "", // 其他登录按钮正常状态背景颜色 默认值:透明
"highlightColor": "", // 其他登录按钮按下状态背景颜色 默认值:透明
"textColor": "#656565", // 其他登录按钮文字颜色 默认值:#656565
"title": "其他登录方式", // 其他登录方式按钮文字 默认值:“其他登录方式”
"borderColor": "", //边框颜色 默认值:透明(仅iOS支持)
"borderRadius": "0px" // 其他登录按钮圆角 默认值:"24px" (按钮高度的一半)
},
"privacyTerms": {
"defaultCheckBoxState": true, // 条款勾选框初始状态 默认值: true
"isCenterHint": false, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
"uncheckedImage": "", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
"checkedImage": "", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
"checkBoxSize": 12, // 可选 条款勾选框大小
"textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
"termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3
"prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
"suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
"privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
{
"url": "https://", // 点击跳转的协议详情页面
"title": "用户服务协议" // 协议名称
}
]
},
"buttons": { // 自定义页面下方按钮仅全屏模式生效(3.1.14+ 版本支持)
"iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px
"list": [{
"provider": "apple",
"iconPath": "/static/apple.png" // 图标路径仅支持本地图片
},
{
"provider": "weixin",
"iconPath": "/static/wechat.png" // 图标路径仅支持本地图片
}
]
}
},
success(res) { // 登录成功
console.log(res.authResult); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
},
fail(res) { // 登录失败
console.log(res.errCode)
console.log(res.errMsg)
}
})
// #endif
});
// 页面显示
onShow(() => {
console.log('登录页面显示');
});
</script>
<style>
</style>
+36 -19
View File
@@ -138,25 +138,6 @@
}
console.log('一键登录');
uni.showLoading({
title: '登录中2...'
});
// 模拟登录过程
setTimeout(() => {
uni.hideLoading();
uni.showToast({
title: '登录成功',
icon: 'none'
});
// 跳转到首页
setTimeout(() => {
uni.switchTab({
url: '/pages/index/index'
});
}, 1500);
}, 2000);
};
// 短信验证码登录
@@ -342,6 +323,42 @@
// 页面加载
onLoad(() => {
console.log('登录页面加载完成');
// #ifdef APP
uni.getProvider({
service: 'oauth',
success: function (res) {
console.log(res.provider)// ['qq', 'univerify']
if(res.provider.indexOf('univerify') !== -1){
uni.preLogin({
provider: 'univerify',
success(){ //预登录成功
// 显示一键登录选项
uni.redirectTo({
url: '/pages/univerify/univerify'
});
},
fail(res){ // 预登录失败
// 不显示一键登录选项(或置灰)
// 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
console.log(res.errCode)
console.log(res.errMsg)
uni.redirectTo({
url: '/pages_app/smsLogin/smsLogin'
});
}
})
}else{
uni.redirectTo({
url: '/pages_app/smsLogin/smsLogin'
});
}
}
});
// #endif
});
// 页面显示
@@ -0,0 +1,8 @@
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
//返回数据给客户端
return event
};
@@ -0,0 +1,7 @@
{
"name": "univerify",
"dependencies": {},
"extensions": {
"uni-cloud-verify": {}
}
}
@@ -3,7 +3,7 @@
const uniPush = uniCloud.getPushManager({appId:"__UNI__89F511F"}) //注意这里需要传入你的应用appId
exports.main = async (event, context) => {
return await uniPush.sendMessage({
"push_clientid": "a297ac02dc531b7d43ff539f3163efcb", //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid
"push_clientid": "58614bcaadae8a6998d166a21e61772f", //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid
"force_notification":true, //填写true,客户端就会对在线消息自动创建“通知栏消息”。
"title": "通知栏显示的标题",
"content": "通知栏显示的内容",
@@ -14,27 +14,5 @@ exports.main = async (event, context) => {
"payload": {
"text":"体验一下uni-push2.0"
},
"category": {
//HarmonyOS NEXT系统(纯血鸿蒙、非安卓鸿蒙)的消息分类,要给鸿蒙设备推送时才必传
"harmony":"MARKETING"
},
"options":{
"HW": {
// 值为int 类型。1 表示华为测试消息,华为每个应用每日可发送该测试消息500条。此 target_user_type 参数请勿发布至线上。
"/message/android/target_user_type":1
} ,
"HO": {
//值为int 类型。1 表示测试推送,不填默认为0。荣耀每个应用每日可发送该测试消息1000条。此测试参数请勿发布至线上。
"/android/targetUserType": 1
} ,
"VV": {
//值为int 类型。0 表示正式推送;1 表示测试推送,不填默认为0。此 pushMode 参数请勿发布至线上。
"/pushMode":1
} ,
"XM": {
//新小米消息分类下,私信公信id都必须要传,否则请求小米厂商接口会被拦截
"/extra.channel_id": "填写小米平台申请的渠道id"
}
}
})
};
@@ -0,0 +1,8 @@
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
//返回数据给客户端
return event
};
@@ -0,0 +1,7 @@
{
"name": "univerify",
"dependencies": {},
"extensions": {
"uni-cloud-verify": {}
}
}