【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>
相关推荐
毕设源码-邱学长1 小时前
【开题答辩全过程】以 基于微信小程序的宠物领养系统为例,包含答辩的问题和答案
微信小程序·小程序·宠物
canglingyue2 小时前
微信小程序日历事件添加实现
微信小程序·小程序
毕设源码-邱学长6 小时前
【开题答辩全过程】以 基于微信小程序校园综合服务平台的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
從南走到北6 小时前
JAVA同城打车小程序APP打车顺风车滴滴车跑腿源码微信小程序打车源码
java·开发语言·微信·微信小程序·小程序
canglingyue9 小时前
微信小程序截屏与录屏功能详解
微信小程序·小程序
微三云-轩10 小时前
区块链系统:解决549 亿元积分商城是否违法的问题
大数据·小程序·重构·区块链·生活
D1555408805813 小时前
电竞护航小程序成品搭建三角洲行动护航小程序开发俱乐部点单小程序成品游戏派单小程序定制
游戏·小程序
说私域1 天前
兴趣电商内容数据洞察未来市场走向研究——基于开源AI智能名片链动2+1模式S2B2C商城小程序的实践
人工智能·小程序
吴传逞1 天前
记一次uniapp微信小程序开发scss变量失效的问题
微信小程序·uni-app·scss
wmsj05781 天前
小程序图片批量保存太麻烦?用这款工具一键搞定,附工具教程!
小程序