index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Page({
  2. dever: getApp().dever,
  3. data: {
  4. //判断小程序的API,回调,参数,组件等是否在当前版本可用。
  5. canIUse: wx.canIUse('button.open-type.getUserInfo')
  6. },
  7. onLoad: function (options) {
  8. // 查看是否授权
  9. wx.getSetting({
  10. success(res) {
  11. if (res.authSetting['scope.userInfo']) {
  12. // 已经授权,可以直接调用 getUserInfo 获取头像昵称
  13. wx.getUserInfo({
  14. success: function (res) {
  15. console.log(res.userInfo)
  16. }
  17. })
  18. }
  19. }
  20. })
  21. },
  22. //微信授权回调
  23. bindGetUserInfo: function (e) {
  24. var that = this;
  25. if (e.detail.userInfo) {
  26. console.log(e.detail.userInfo);
  27. wx.login({
  28. success: function (res) {
  29. if (res.code) {
  30. that.doLogin(res.code);
  31. } else {
  32. console.log(res.errMsg);
  33. }
  34. }
  35. })
  36. } else {
  37. console.log("拒绝了授权");
  38. }
  39. },
  40. doLogin: function(wxCode){
  41. var that = this;
  42. this.dever.request("/wxLogin", {code: wxCode}, {
  43. success: function (data, res) {
  44. that.dever.goBack();
  45. }
  46. }, "POST");
  47. }
  48. })