怎么知道微信好友的手机号,微信好友手机号查询方法? | 大商梦-尊龙凯时官网

在小程序开发中,特别是一些电商平台,为了提供更好的用户服务和订单管理,通常需要获取用户的手机号码。用户的手机号码可以用于验证身份、发送订单信息和优惠活动等。为了保护用户隐私,开发者需要遵守相关法律法规,确保用户的手机号码安全使用,并明确告知用户手机号码的使用目的和范围。同时,开发者也应该提供用户选择的权利,让用户自主决定是否提供手机号码,并提供相应的隐私保护措施,如加密存储和合理的数据访问权限控制。

前端是无法直接获取用户手机号码,前端需要用户点击同意授权后,把获取到用户的code传给后端.后端收到code后,要先获取一下token(获取token的代码,下次发).具体代码如下(我是用golang原生写的).

//获取微信手机号码
func getphonenumber(wxcode string) interface{} {
   //获取用户的token 明天发获取token的代码
   accesstoken :=getaccesstoken()
   httpdata :=make(map[string]interface{})
   httpdata["code"]=wxcode
   httpdatacode, _ :=json.marshal(httpdata)
   httpurl :="https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="   accesstoken
   client :=&http.client{}
   req, _ :=http.newrequest("post", httpurl, bytes.newreader(httpdatacode))
   req.header.add("content-type", "application/json")
   res, _ :=client.do(req)
   defer func() {
      _=res.body.close()
   }()
   body, _ :=ioutil.readall(res.body)
   fmt.print(string(body))
   var bodydata map[string]interface{}
   _=json.unmarshal(body, &bodydata)
   return bodydata["phone_info"].(interface{}).(map[string]interface{})["purephonenumber"]
}
注意!!!
  "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="   accesstoken 
token一定要拼接到url后面,至于为啥,微信规定的哈.
本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 sumchina520@foxmail.com 举报,一经查实,本站将立刻删除。
如若转载,请注明出处:https://www.dasum.com/254372.html
网站地图