Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. var openid = wx.getStorageSync('openid') || "";
  9. console.log(this.globalData.present_id)
  10. // 登录
  11. if (!openid){
  12. wx.login({
  13. success: res => {
  14. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  15. // console.log(res)
  16. if (res.code){
  17. wx.request({
  18. url: this.globalData.httpUrl+'openid',
  19. header: {
  20. code: res.code
  21. },
  22. success: e => {
  23. // console.log(e)
  24. if (e.data.code == 200) {
  25. this.globalData.openId = e.data.data.openid;
  26. this.globalData.session_key = e.data.data.session_key;
  27. this.globalData.token = e.data.data.token;
  28. wx.setStorageSync('openid', e.data.data.openid)
  29. wx.setStorageSync('session_key', e.data.data.session_key)
  30. wx.setStorageSync('token', e.data.data.token)
  31. }
  32. }
  33. })
  34. } else {
  35. console.log("登陆失败" + res.errMsg)
  36. }
  37. }
  38. })
  39. }else{
  40. this.globalData.openid = openid;
  41. }
  42. this.getUserType();
  43. // 获取用户信息
  44. // wx.getSetting({
  45. // success: res => {
  46. // console.log(res)
  47. // if (res.authSetting['scope.userInfo']) {
  48. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  49. // wx.getUserInfo({
  50. // success: e => {
  51. // // 可以将 res 发送给后台解码出 unionId
  52. // this.globalData.userInfo = e.userInfo
  53. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  54. // // 所以此处加入 callback 以防止这种情况
  55. // if (this.userInfoReadyCallback) {
  56. // this.userInfoReadyCallback(res)
  57. // }
  58. // }
  59. // })
  60. // }else{
  61. // wx.authorize({
  62. // scope: 'scope.record',
  63. // success() {
  64. // wx.getUserInfo({
  65. // success: e => {
  66. // console.log(e)
  67. // }
  68. // })
  69. // }
  70. // })
  71. // }
  72. // }
  73. // })
  74. },
  75. getUserType:function(){//获取用户注册状态
  76. this.wxRequest(this.globalData.httpUrl + 'getinfo',{},e=>{
  77. // console.log(e)
  78. if(e.code==201){//未注册跳到注册页面
  79. wx.reLaunch({
  80. url: '/pages/register/register'
  81. })
  82. } else if (e.code == 202){//已注册跳到首页购券大厅
  83. wx.switchTab({
  84. url: '/pages/index/index'
  85. })
  86. }
  87. },this)
  88. },
  89. globalData: {
  90. userInfo: null,
  91. present_id:"",//判断用户是通过领取优惠券进来的还是直接进的
  92. number:"",//赠送优惠券的数量
  93. openId:"",
  94. session_key:"",
  95. token:"",
  96. userInfo:"",
  97. httpUrl:"https://laomenkuang.jiyou-tech.com/apiWx/"
  98. },
  99. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  100. let that = this;
  101. // console.log(this.globalData.openid)
  102. var httpUrl = url;
  103. var str = "";
  104. var count = 0;
  105. for (let key in params) {
  106. if (count) {
  107. str += "&" + key + "=" + params[key];
  108. } else {
  109. str += key + "=" + params[key];
  110. }
  111. count++;
  112. }
  113. if (str) {
  114. httpUrl += "?" + str;
  115. }
  116. if (!methods) {
  117. methods = "GET";
  118. }
  119. if (methods == "POST") {
  120. wx.request({
  121. url: url,
  122. data: params,
  123. method: methods,
  124. header: {
  125. "content-type": "application/x-www-form-urlencoded",
  126. "openid": this.globalData.openid
  127. },
  128. success: function (re) {
  129. // if (re.data.code == -1002) {
  130. // wx.removeStorageSync('openid');
  131. // that.wxLogin();
  132. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  133. // }
  134. if (callback && thisArg) {
  135. callback.call(thisArg, re.data);
  136. }
  137. },
  138. fail: function (re) {
  139. wx.hideLoading();
  140. }
  141. })
  142. } else {
  143. wx.request({
  144. url: httpUrl,
  145. method: methods,
  146. header: {
  147. "openid": this.globalData.openid,
  148. },
  149. success: function (re) {
  150. // if (re.data.code == -1002) {
  151. // wx.removeStorageSync('openid');
  152. // that.wxLogin();
  153. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  154. // }
  155. if (callback && thisArg) {
  156. callback.call(thisArg, re.data);
  157. }
  158. },
  159. fail: function (res) {
  160. wx.hideLoading();
  161. }
  162. })
  163. }
  164. },
  165. // requestGet:function(url,data,callback){//get接口调用
  166. // wx.request({
  167. // url: url,
  168. // header: {
  169. // "openid": this.globalData.openId
  170. // },
  171. // data: data,
  172. // success:res=>{
  173. // if (callback) {
  174. // }
  175. // }
  176. // })
  177. // },
  178. // requestPost: function (url, data) {//post接口调用
  179. // wx.request({
  180. // url: url,
  181. // header: {
  182. // "Content-Type":"application/x-www-form-urlencoded",
  183. // openid: this.globalData.openId
  184. // },
  185. // data: data,
  186. // success(res) {
  187. // console.log(res.data)
  188. // }
  189. // })
  190. // }
  191. })