过程
1、通过微信小程序页面获取手机号码相关的code
2、后端通过 获取access_token
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
3、后端获取手机号码:
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"code": "e31968a7f94cc5ee25fafc2aef2773f0bb8c3937b22520eb8ee345274d00c144"}' https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=ACCESS_TOKEN
uni-app登录页面
<template>
<view>
<button type="default" open-type="getPhoneNumber" @getphonenumber="getLoginphone">获取手机号code</button>
<input v-model="wxPhoneCode" />
</view>
</template>
<script>
export default {
data() {
return {
wxPhoneCode: ''
}
},
methods: {
getLoginphone(e) {
console.log(e);
this.wxPhoneCode = e.detail.code;
}
}
}
</script>