云开发小程序如何获取用户的手机号

小程序 文章 2021-03-17 17:01 424 0 全屏看文

AI助手支持GPT4.0

云开发小程序如何获取用户的手机号How to obtain the user's mobile phone number for the cloud development applet

云开发小程序如何获取用户的手机号


云开发小程序如何获取用户的手机号

~


官方文档

1、https://developers.weixin.qq.com/miniprogram/dev/component/button.html

2、https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

首先我说下做这个的场景,近期在迭代培训刷题小程序,该小程序支持线上和线下报名,对于线上报名的用户平台会电话引导购买其他付费服务,这个时候对于手机号的正确收集是非常有必要的

那么能不能通过文本框让用户自己输入呢,这样做其实也不是不可以的,但是目前常规的做法就是利用微信的


微信开放能力直接获取微信实名认证绑定的手机号,由于目前基本绝大部分手机都实名认证了,所以这个方式就非常自然

~

其实在之前的开发中,也做过手机号码的获取工作,但是当时是在社区随便找了一个可行方案,没有严格按照官方指定的方案来,这次就顺着官方提供的思路实现了下

真好看

具体代码就是增加以下二块

1、


2、

对的,你看到了,创建的云函数就是默认的初始化代码,但是这样就work的,不妨可以试试


How to get the user's mobile phone number ~ official document 1 https://developers.weixin.qq.com/miniprogram/dev/component/button.html 2、 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html First of all, I'll talk about the scenario of doing this. Recently, I've been iteratively training the topic brushing applet, which supports online and offline registration. The online registration user platform will call to guide the purchase of other paid services. At this time, it's very necessary to collect the correct mobile phone number So can we let users input by themselves through the text box? In fact, it's not impossible to do so. But at present, the conventional way is to use wechat's wechat open ability to directly obtain the mobile phone number bound with wechat's real name authentication. Because most mobile phones have real name authentication, this way is very natural~ In fact, in the previous development, I also did the work of obtaining mobile phone numbers, but at that time, I found a feasible solution in the community. I didn't strictly follow the plan specified by the official. This time, I followed the idea provided by the official. You laugh very well. The specific code is to add the following two pieces of 1, 2 Yes, as you can see, the created cloud function is the default initialization code, but it's work like this. You can try it

回答:

红小豆:

利用微信的开放能力获取手机号,是需要企业资质的,所以对于个人小程序是不支持的,这一点需要格外注意。

红小豆:

res.result.event.wuRunData.data.phoneNumber

红小豆:

官方提供了以下二种方案,本文采用了第二种方式来实现

服务端获取开放数据

小程序可以通过各种前端接口获取微信提供的开放数据。考虑到开发者服务端也需要获取这些开放数据,微信提供了两种获取方式:


方式一:开发者后台校验与解密开放数据

方式二:云调用直接获取开放数据(云开发)


-EOF-

AI助手支持GPT4.0