微信小程序如何通过微信绑定的手机号进行快速登录
来源:互联网 发布:开发板与单片机 编辑:程序博客网 时间:2024/04/30 12:07
1.首先wxml布局文件这么写。 open-type是固定的。 bindgetPhonenumber后面跟的是自定的方法名
open-type="getPhoneNumber"bindgetphonenumber="getPhoneNumber"
<view class="btn-submit"> <button class="btn-block btn-green" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">微信用户快速登录</button></view>
2. js文件。写法 需要把获取的js_code, iv, encryptedData传给服务器,开发者需要在开发者服务器后台调用 api,使用 code 换取 openid 和 session_key 等信息
getPhoneNumber: function (e) { var that = this // console.log("errMsg:" + e.detail.errMsg) console.log("iv:" + e.detail.iv) console.log("未转 encryptedData:" + e.detail.encryptedData) // console.log("encryptedData:" + encodeURIComponent(e.detail.encryptedData)) console.log("js_code:" + encodeURIComponent(app.data.js_code)) wx.request({ url: url1, data: { act: "binding_little_program", code: encodeURIComponent(app.data.js_code), encryptedData: encodeURIComponent(e.detail.encryptedData), iv: encodeURIComponent(e.detail.iv), }, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT header: { 'content-type': 'application/json' }, success: function (res) { // success console.log(res) console.log("result_msg:"+res.data.result_msg) if (res.data.result_code == 0) { util.showAlert(res.data.result_msg) } else { console.log(res.data.uid) util.showAlert1(res.data.result_msg, 'success') app.globalData.uid = res.data.uid app.globalData.card_id = res.data.card_id app.globalData.fullname = res.data.fullname app.globalData.photo_img = res.data.photo_img app.globalData.usertel = res.data.telephone app.globalData.sex = res.data.sex console.log('aaphoto = ' + app.globalData.usertel) wx.setStorage({ key: "uid", data: res.data.uid, success: function (res) { console.log(res) }, fail: function (res) { console.log(res) }, complete: function (res) { console.log(res) }, }) wx.setStorage({ key: "usertel", data: res.data.telephone, success: function (res) { console.log(res) }, fail: function (res) { console.log(res) }, complete: function (res) { console.log(res) }, }) wx.setStorage({ key: "card_id", data: res.data.card_id, success: function (res) { console.log(res) }, fail: function (res) { console.log(res) }, complete: function (res) { console.log(res) }, }) wx.setStorage({ key: "fullname", data: res.data.fullname, success: function (res) { console.log(res) }, fail: function (res) { console.log(res) }, complete: function (res) { console.log(res) }, }) wx.setStorage({ key: "photo_img", data: res.data.photo_img, success: function (res) { console.log(res) }, fail: function (res) { console.log(res) }, complete: function (res) { console.log(res) }, }) wx.setStorage({ key: "sex", data: res.data.sex, success: function (res) { console.log(res) }, fail: function (res) { console.log(res) }, complete: function (res) { console.log(res) }, }) var pages = getCurrentPages(); console.log("length" + pages.length); //更新ui that.setData({ uid: res.data.uid }) if (that.data.uid > 0) { that.getUserInfo(); } } }, fail: function () { // fail util.showAlert('操作失败') }, complete: function () { // complete } }) },
阅读全文
0 0
- 微信小程序如何通过微信绑定的手机号进行快速登录
- 如何通过微信电脑客户端,快速加微信群内的好友
- App通过QQ/微信登录绑定用户信息的一般流程
- java的网站通过微信登录
- iOS微信登录/绑定
- 微信小程序获取手机号授权登录
- 如何通过手机号获得对应的省份
- 微信小程序之手机号快速注册
- 使用微信授权登录的APP,如何通过App Store审核?
- 使用微信授权登录的APP,如何通过App Store审核?
- 使用微信授权登录的APP,如何通过App Store审核?
- Ecstore的微信账号绑定会员免登录
- 如何快速通过对方微信好友验证!
- 【微信小程序 一】微信登录
- 微信小程序开发--微信登录流程
- 如何快速开发一套微信商城小程序?
- php的laravel框架快速集成微信登录
- php的laravel框架快速集成微信登录
- slatstack中的远程执行命令的方法
- Cisco Catalyst Vs. Small Business Switches
- sparkSQL1.1入门
- 习题1.5
- Tomcat服务器使用详解
- 微信小程序如何通过微信绑定的手机号进行快速登录
- 通过关联条件将A表的某个字段值和B表的某个对应字段值设成一样
- hdu-1242-Rescue
- 你真的会使用XMLHttpRequest吗?
- Git的学习
- 技术博客,技术社区,学术机构(汇总)
- Linux-4.9.2内核在mini2440上的移植(三)——编译环境测试
- python 高级特性笔记
- js事件(Event)之阻止默认操作