首页 > 编程语言 >小程序获取手机号(wepy)

小程序获取手机号(wepy)

时间:2023-06-19 10:59:15浏览次数:44  
标签:code 手机号 res wepy 获取 token data

1.方法一

export async function getPhoneNumber(data = {}) {
// 小程序的密钥 let SECRET = 'xxxxxxxxxxxxxxxxxxxxxx' return new Promise((resolve, reject) => { wepy.request({ url: `https://api.weixin.qq.com/cgi-bin/token`, data: { grant_type: 'client_credential', appid: 'xxxxxxxxxxxxxxxxxxxxx', secret: SECRET, }, }) .then((res) => { let ACCESS_TOKEN = res.data.access_token wepy .request({ method: 'post', url: `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${ACCESS_TOKEN}`, data: { code: data.code, }, }) .then((res) => { console.log(res.data) resolve(res.data.phone_info.phoneNumber) }) }) }) }

使用的是小程序的wepy框架,使用原生的小程序代码,将wepy.改为wx.即可

2.方法二

<button class="btn" open-type="getPhoneNumber" type="primary" bindgetphonenumber="onWeChatLogin">微信一键登录</button>

使用小程序Button里面的 open-type="getPhoneNumber" 来获取手机号的code,将其传给后端去解析,返回手机号


标签:code,手机号,res,wepy,获取,token,data
From: https://www.cnblogs.com/panghu77/p/17490538.html

相关文章

  • 获取cpu、memory、disk的基本情况
    #!/bin/bash#获取逻辑CPU个数processors=`cat/proc/cpuinfo|grep"processor"|wc-l`functioncpu(){NUM=1while[$NUM-le$processors];doutil=`vmstat|awk'{if(NR==3)print100-$15"%"}'`user=`vmst......
  • 如何通过手机号查对方微博
    第一步将以下网址放进浏览器(=后面是目标手机号)https://zy.xywlapi.cc/wbphone?phone=手机号如果能查到的话会得到:{"status":200,"message":"查询成功","id":"5992728669","phone":"*****","phonediqu":"湖南省衡阳市电信"}第二......
  • C# 获取数组排序后的下标
    usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceConsoleApp9{classProgram{staticvoidMain(string[]args){int[]src=newint[]{2,1......
  • 跟据WiFi名获取本地保存的密码
    @echooffecho+++++++++++++请选择用户配置文件里已保存的WiFi名称+++++++++++++++++netshwlanshowprofilesset/pWiFiName=请输入WiFi名称:echo++++++++++++++++++++++++WiFi密码如下++++++++++++++++++++++++++++++netshwlanshowprofilename=%WiFiName%key=cle......
  • 点击echarts图。获取点击事件
         自动跳转复用代码:letdataIndex=param.dataIndexthis.$nextTick(()=>{this.$refs.multipleTable0.bodyWrapper.scrollTop=(this.$refs.multipleTable0.bodyWrapper.scrollHeight*(this.tableList.len......
  • 获取正在执行的方法名
    importinspectimportsysdefdemo1():f_name=inspect.getframeinfo(inspect.currentframe().f_back)[3][0]print(f_name)defdemo2():f_name=sys._getframe().f_code.co_nameprint(f_name)defdemo3():print(demo3.__name__)if__......
  • 马拉松资讯获取及报名渠道分享
    1、马拉松赛事1.1马拉松赛事组别马拉松赛事分为全程马拉松(42.195公里)、半程马拉松(21.0975公里)、短程跑(健康跑、亲子跑、家庭跑之类的)这几个类别,大型田协认证赛事三种类型都有,大多中小型赛事长距离支持半马,更小型公司冠名的商业路跑仅有健康跑、徒步等。以2023兰州马拉松为例,是国际......
  • 获取度盘临时会员
    望周知:●获取的是临时会员,是普通会员,非svip●每月可以参加一次活动,能获得1-2天会员,新用户能获得7天●在某宝、某黄鱼、某夕夕,这种链接能卖个几毛到几块,销量还不错#导包importreimportrequests#定义变量url='https://pan.baidu.com/component/view?id='headers=......
  • 获取微信的token工具类
    importcn.hutool.extra.spring.SpringUtil;importcn.hutool.http.HttpUtil;importcn.RedisUtil;importcom.alibaba.fastjson.JSON;importlombok.extern.slf4j.Slf4j;/***<p>*获取微信的token工具类*</p>**@authorwss*@date2021-06-......
  • 如何通过店铺 ID 获取淘宝店铺商品数据上传至京东店铺,整店商品数据搬家,淘宝店铺所有商
    在电商行业还是销量为王,因此在很多相关行业,比如商品搬家行业都需要用到相关的商品详情信息,但是官方一般又没有开放这些接口,怎么办?  解决方案现在很多是通过爬虫获取数据,但是根本扛不住大量调用,不稳定,真能稳定获取了也不是一般人有能力去做的,加上淘宝变化频繁,防爬越来越严,技术难......