Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

app.js 4.8KB

il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. wx.setStorageSync('state',-1);
  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. console.log(res.code)
  18. wx.request({
  19. url: this.globalData.httpUrl+'openid',
  20. header: {
  21. code: res.code
  22. },
  23. success: e => {
  24. console.log(e)
  25. if (e.data.code == 200) {
  26. this.globalData.openId = e.data.data.openid;
  27. this.globalData.session_key = e.data.data.session_key;
  28. this.globalData.token = e.data.data.token;
  29. wx.setStorageSync('openid', e.data.data.openid)
  30. wx.setStorageSync('session_key', e.data.data.session_key)
  31. wx.setStorageSync('token', e.data.data.token)
  32. this.getUserType();
  33. if (this.globalData.openidSuccessFuc) {
  34. this.globalData.openidSuccessFuc();
  35. }
  36. }
  37. }
  38. })
  39. } else {
  40. console.log("登陆失败" + res.errMsg)
  41. }
  42. }
  43. })
  44. }else{
  45. this.globalData.openId = openid;
  46. this.getUserType();
  47. }
  48. },
  49. // onShow:function(){
  50. // this.getUserType();
  51. // },
  52. getUserType: function () {//获取用户注册状态
  53. console.log(this.globalData.openId)
  54. this.wxRequest(this.globalData.httpUrl + 'getinfo', {},e=>{
  55. console.log(e)
  56. if(e.code==201){//未注册跳到注册页面
  57. wx.setStorageSync('state', 0);
  58. } else if (e.code == 202) {//已注册
  59. wx.setStorageSync('state', 1);
  60. this.globalData.userInfo = e.data;
  61. }
  62. if(this.globalData.userInfoBackFn){
  63. this.globalData.userInfoBackFn(this.globalData.state);
  64. }
  65. },this)
  66. },
  67. globalData: {
  68. openidSuccessFuc: null,//方法回调
  69. userInfoSuccessFuc: null,//方法回调
  70. userInfo: null,
  71. present_id:"",//判断用户是通过领取优惠券进来的还是直接进的
  72. number:"",//赠送优惠券的数量
  73. openId:"",
  74. session_key:"",
  75. token:"",
  76. userInfo:"",
  77. httpUrl:"https://laomenkuang.jiyou-tech.com/apiWx/",
  78. user_phone:"",//用户手机号
  79. },
  80. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  81. let that = this;
  82. var httpUrl = url;
  83. var str = "";
  84. var count = 0;
  85. for (let key in params) {
  86. if (count) {
  87. str += "&" + key + "=" + params[key];
  88. } else {
  89. str += key + "=" + params[key];
  90. }
  91. count++;
  92. }
  93. if (str) {
  94. httpUrl += "?" + str;
  95. }
  96. if (!methods) {
  97. methods = "GET";
  98. }
  99. if (methods == "POST") {
  100. wx.request({
  101. url: url,
  102. data: params,
  103. method: methods,
  104. header: {
  105. "content-type": "application/x-www-form-urlencoded",
  106. "openid": this.globalData.openId
  107. },
  108. success: function (re) {
  109. // if (re.data.code == -1002) {
  110. // wx.removeStorageSync('openid');
  111. // that.wxLogin();
  112. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  113. // }
  114. if (callback && thisArg) {
  115. callback.call(thisArg, re.data);
  116. }
  117. },
  118. fail: function (re) {
  119. wx.hideLoading();
  120. }
  121. })
  122. } else {
  123. wx.request({
  124. url: httpUrl,
  125. method: methods,
  126. header: {
  127. "openid": this.globalData.openId,
  128. },
  129. success: function (re) {
  130. // if (re.data.code == -1002) {
  131. // wx.removeStorageSync('openid');
  132. // that.wxLogin();
  133. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  134. // }
  135. if (callback && thisArg) {
  136. callback.call(thisArg, re.data);
  137. }
  138. },
  139. fail: function (res) {
  140. wx.hideLoading();
  141. }
  142. })
  143. }
  144. },
  145. // requestGet:function(url,data,callback){//get接口调用
  146. // wx.request({
  147. // url: url,
  148. // header: {
  149. // "openid": this.globalData.openId
  150. // },
  151. // data: data,
  152. // success:res=>{
  153. // if (callback) {
  154. // }
  155. // }
  156. // })
  157. // },
  158. // requestPost: function (url, data) {//post接口调用
  159. // wx.request({
  160. // url: url,
  161. // header: {
  162. // "Content-Type":"application/x-www-form-urlencoded",
  163. // openid: this.globalData.openId
  164. // },
  165. // data: data,
  166. // success(res) {
  167. // console.log(res.data)
  168. // }
  169. // })
  170. // }
  171. })