click_Jurisdiction.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const app = getApp();
  2. Page({
  3. data: {
  4. canIUse: wx.canIUse('button.open-type.getUserInfo')
  5. },
  6. onLoad() {
  7. setTimeout(function () {
  8. wx.hideLoading()
  9. })
  10. // 查看是否授权
  11. wx.getSetting({
  12. success(res) {
  13. if (res.authSetting['scope.userInfo']) {
  14. console.log('已经授权');
  15. }else{
  16. console.log('没有授权');
  17. }
  18. }
  19. })
  20. },
  21. bindGetUserInfo(e) {
  22. var that = this;
  23. wx.login({
  24. success: function (res) {
  25. console.log(res.code)
  26. if (res.code) {
  27. wx.getUserInfo({
  28. withCredentials: true,
  29. success: function (res_user) {
  30. console.log(res_user);
  31. console.log(res_user.userInfo.avatarUrl);
  32. console.log(res_user.userInfo.city);
  33. console.log(res_user.userInfo.country);
  34. console.log(res_user.userInfo.gender);
  35. console.log(res_user.userInfo.language);
  36. console.log(res_user.userInfo.nickName);
  37. console.log(res_user.userInfo.province);
  38. let p_url = 'public/wxlogin';
  39. let p_data = {
  40. encryptedData: res_user.encryptedData,
  41. iv: res_user.iv,
  42. code: res.code,
  43. headimgurl: res_user.userInfo.avatarUrl,
  44. city: res_user.userInfo.city,
  45. country: res_user.userInfo.country,
  46. sex: res_user.userInfo.gender,
  47. language: res_user.userInfo.language,
  48. nickname: res_user.userInfo.nickName,
  49. province: res_user.userInfo.province,
  50. };
  51. app.postRequest(p_url, p_data, function (res) {
  52. console.log(res);
  53. if (res.code==201){
  54. if (res.data.openid && res.data.wx_id){
  55. wx.navigateTo({
  56. url: '/pages/Landpage/Land/Land'
  57. })
  58. }
  59. }
  60. // console.log(res.data.openid);
  61. // that.setData({
  62. // selectArray: 123
  63. // })
  64. // 同步传参
  65. try {
  66. wx.setStorageSync('openid', res.data.openid)
  67. } catch (e) {
  68. }
  69. // 同步传参
  70. try {
  71. wx.setStorageSync('wx_id', res.data.wx_id)
  72. } catch (e) {
  73. }
  74. })
  75. }, fail: function () {
  76. wx.showToast({
  77. title: '您拒绝了,无法登陆,请重新授权',
  78. icon: 'none', // 不显示图标
  79. mask: true, // 是否显示透明蒙层,防止触摸穿透
  80. duration: 3000
  81. })
  82. // console.log('您拒绝了,无法登陆,请重新授权');
  83. }, complete: function (res) {
  84. }
  85. })
  86. }
  87. }
  88. })
  89. },
  90. }) // Page