You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. // 展示本地存储能力
  5. // var logs = wx.getStorageSync('logs') || []
  6. // logs.unshift(Date.now())
  7. // wx.setStorageSync('logs', logs)
  8. // 登录
  9. wx.login({
  10. success: res => {
  11. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  12. console.log(res)
  13. if (res.code){
  14. wx.request({
  15. url: 'https://laomenkuang.jiyou-tech.com/apiWx/openid',
  16. header: {
  17. code: res.code
  18. },
  19. success: e => {
  20. console.log(e)
  21. if (e.data.code == 200) {
  22. this.globalData.openId = e.data.data.openid;
  23. this.globalData.session_key = e.data.data.session_key;
  24. this.globalData.token = e.data.data.token;
  25. wx.setStorageSync('openid', e.data.data.openid)
  26. wx.setStorageSync('session_key', e.data.data.session_key)
  27. wx.setStorageSync('token', e.data.data.token)
  28. }
  29. }
  30. })
  31. } else {
  32. console.log("登陆失败" + res.errMsg)
  33. }
  34. }
  35. })
  36. // 获取用户信息
  37. wx.getSetting({
  38. success: res => {
  39. console.log(res)
  40. if (res.authSetting['scope.userInfo']) {
  41. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  42. wx.getUserInfo({
  43. success: e => {
  44. // 可以将 res 发送给后台解码出 unionId
  45. this.globalData.userInfo = e.userInfo
  46. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  47. // 所以此处加入 callback 以防止这种情况
  48. if (this.userInfoReadyCallback) {
  49. this.userInfoReadyCallback(res)
  50. }
  51. }
  52. })
  53. }else{
  54. wx.authorize({
  55. scope: 'scope.record',
  56. success() {
  57. // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
  58. wx.startRecord()
  59. }
  60. })
  61. }
  62. }
  63. })
  64. },
  65. globalData: {
  66. userInfo: null,
  67. openId:"",
  68. session_key:"",
  69. token:"",
  70. userInfo:"",
  71. },
  72. wxRequest:function(url,data){//接口调用
  73. wx.request({
  74. url: url,
  75. data: data,
  76. header: {
  77. openid: this.globalData.openId
  78. },
  79. success(res) {
  80. console.log(res.data)
  81. }
  82. })
  83. }
  84. })