login.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  38. }
  39. })
  40. },
  41. onLoad: function () {
  42. var that = this;
  43. wx.login({
  44. success: res => {
  45. // 获取到用户的 code 之后:res.code
  46. console.log("用户的code:" + res.code);
  47. const appid = "wx1c015df104db7030"
  48. const secret = "d1956c1b5d3601657c98b0dc80a006f7"
  49. let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
  50. wx.request({
  51. // 自行补上自己的 APPID 和 SECRET
  52. url: url,
  53. success: res => {
  54. // 获取到用户的 openid
  55. console.log("用户的openid:" + res.data.openid);
  56. wx.setStorageSync('openId', res.data.openid)
  57. }
  58. });
  59. }
  60. });
  61. },
  62. })