【uniapp】开发支付宝小程序 — 注意事项

button 边框有黑线 解决办法
btn{ border: 1px solid transparent; }

css 复制代码
.btn{ 
    padding: 0; margin: 0; border: 1px solid transparent;
    line-height: initial; height: initial;
}
.btn::after{ display: none; }

自定义导航栏问题
自定义导航栏时Title为空: "navigationBarTitleText": "",
page.json代码 globalStyle中引入

"mp-alipay": {
"allowsBounceVertical": "NO", //是否允许向下拉拽。支持 YES / NO

"transparentTitle": "always",//导航栏透明设置 always一直透明 / auto 滑动自适应 / none 不透明

"titlePenetrate": "YES" //设置小程序导航栏为透明

}


禁止页面下拉拖动
其中有allowsBounceVertical属性 :是否允许向下拉拽。支持 YES / NO

授权支付宝头像、昵称

cpp 复制代码
<template>
  <view>
    <!-- #ifdef MP-ALIPAY -->
	<button open-type="getAuthorize" scope='userInfo' 
	@getAuthorize="onGetAuthorize" @error="onAuthError" 
	class="btn2 btn font-32 h-90 fcc radius10">授权支付宝头像、昵称登录</button>
	<!-- #endif -->
  </view>
</template>
 
<script>
export default {
  methods: {
    onGetAuthorize() {
      my.getAuthCode({
        scopes: 'auth_user',
        success: (authCodeRes) => {
          const authCode = authCodeRes.authCode;
          // 继续获取用户信息
          my.getOpenUserInfo({
            success: (userInfoRes) => {
              const userInfo = JSON.parse(userInfoRes.response).response;
              console.log('User Info:', userInfo);
              // 将用户信息发送到后端
              this.ali_login(authCode, userInfo);
            },
            fail: (error) => {
              console.error('获取用户信息失败', error);
            }
          });
        },
        fail: (error) => {
          console.error('获取授权码失败', error);
        }
      });
    },
	ali_login:function(authCode, userInfo){
		console.log(authCode, userInfo);
		var that=this;
		// 请求接口
		uni.showLoading({ title: '登录中...' });
		uni.request({
			method: 'POST',
			url: '后端接口地址',
			data: {
				code: authCode,
				nickName: userInfo.nickName, gender: 0, avatarUrl: userInfo.avatar,
				referid: uni.getStorageSync('referid') || that.referid || 0
			},
			header: { 'app-type':uni.getStorageSync('app-type')||"" },
			success: (res) => {
				uni.hideLoading();
				if (res.header) {
					uni.setStorageSync('token', res.header['token']||'');
				}
				if (res.data.code == 1) {
					uni.setStorageSync('gl_login_status',true);
					setTimeout(()=>{
						// uni.switchTab({ url: '/pages/index/index' });
					},100);	
				}else{
					that.toast(res.data.msg);
				}
			}
		});
	},
	onAuthError(e){ console.log(e); }, // 授权报错
  }
}
</script>
相关推荐
古韵9 小时前
你的 uni-app 分页,一个 hook 搞定竞态和加载
javascript·vue.js·uni-app
游戏开发爱好者815 小时前
iOS应用加固方案全解析:源码加固与IPA在线加固对比
android·macos·ios·小程序·uni-app·cocoa·iphone
满栀58517 小时前
uni-app 小程序开发实战:从路由踩坑、数据对接到 UI 优化的全方位复盘
ui·uni-app·notepad++
2301_810313181 天前
宠物服务APP开发宠物社交上门喂养洗护商城系统源码搭建
小程序·团队开发·软件需求·宠物
momodira81 天前
防溺水作品投票小程序选哪个?
小程序·投票工具·线上制作教程
鲁Q同志2 天前
微信小程序【uni-file-picker文件预览】
微信小程序·小程序
他叫自己MR张2 天前
uni-app 应用启动报uni-ad业务状态异常(-9002)【已解决】
uni-app
2601_963869952 天前
【计算机毕业设计】基于微信小程序的拼车服务系统设计与实现
微信小程序·小程序·课程设计
2501_915909062 天前
iOS应用性能监控 Instruments工具与崩溃日志分析完整指南
android·ios·小程序·https·uni-app·iphone·webview
人脸核身安全官2 天前
人脸核身SDK接入实测:H5/小程序常见兼容问题与通过率优化
小程序·人脸识别·人脸比对·活体检测·实人认证·h5人脸核验·旷视