Identity.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const app = require('../../utils/util.js');
  2. var util = require('../../utils/md5.js')
  3. Page({
  4. data: {
  5. defaultType1: true,
  6. passwordType1: true
  7. },
  8. eyeStatus1() {
  9. if (this.data.defaultType1) {
  10. this.setData({
  11. passwordType1: false,
  12. defaultType1: false,
  13. })
  14. } else {
  15. this.setData({
  16. passwordType1: true,
  17. defaultType1: true,
  18. })
  19. }
  20. },
  21. formSubmit(e) {
  22. console.log(e.detail, "daying");
  23. var password = e.detail.value.pwd;
  24. wx.request({
  25. url: app.globalData.publicUrl + '/applet/bing',
  26. method: "GET",
  27. data: {
  28. name: e.detail.value.name,
  29. pwd: util.hexMD5(password),
  30. appletsId: wx.getStorageSync('openId')
  31. },
  32. success: (res) => {
  33. if (res.data.code == 0) {
  34. wx.switchTab({
  35. url: '/pages/index/index',
  36. })
  37. wx.setStorageSync('user', 'user')
  38. }
  39. }
  40. })
  41. },
  42. onLoad: function () {
  43. var that = this;
  44. wx.login({
  45. success: res => {
  46. // 获取到用户的 code 之后:res.code
  47. console.log("用户的code:" + res.code);
  48. const appid = "wx1c015df104db7030"
  49. const secret = "d1956c1b5d3601657c98b0dc80a006f7"
  50. let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
  51. wx.request({
  52. // 自行补上自己的 APPID 和 SECRET
  53. url: url,
  54. success: res => {
  55. // 获取到用户的 openid
  56. console.log("用户的openid:" + res.data.openid);
  57. wx.setStorageSync('openId', res.data.openid)
  58. wx.request({
  59. url: app.globalData.publicUrl + '/applet/isExist',
  60. method: "GET",
  61. data: {
  62. appletsId: wx.getStorageSync('openId')
  63. },
  64. success: (res) => {
  65. }
  66. })
  67. }
  68. });
  69. }
  70. });
  71. },
  72. })