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 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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(wx.getStorageSync('state'));
  64. }
  65. },this)
  66. },
  67. globalData: {
  68. openidSuccessFuc: null,//方法回调
  69. userInfoSuccessFuc: null,//方法回调
  70. present_id:"",//判断用户是通过领取优惠券进来的还是直接进的
  71. number:"",//赠送优惠券的数量
  72. openId:"",
  73. session_key:"",
  74. token:"",
  75. userInfo:"",
  76. httpUrl:"https://laomenkuang.jiyou-tech.com/apiWx/",
  77. user_phone:"",//用户手机号
  78. },
  79. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  80. let that = this;
  81. var httpUrl = url;
  82. var str = "";
  83. var count = 0;
  84. for (let key in params) {
  85. if (count) {
  86. str += "&" + key + "=" + params[key];
  87. } else {
  88. str += key + "=" + params[key];
  89. }
  90. count++;
  91. }
  92. if (str) {
  93. httpUrl += "?" + str;
  94. }
  95. if (!methods) {
  96. methods = "GET";
  97. }
  98. if (methods == "POST") {
  99. wx.request({
  100. url: url,
  101. data: params,
  102. method: methods,
  103. header: {
  104. "content-type": "application/x-www-form-urlencoded",
  105. "openid": this.globalData.openId
  106. },
  107. success: function (re) {
  108. // if (re.data.code == -1002) {
  109. // wx.removeStorageSync('openid');
  110. // that.wxLogin();
  111. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  112. // }
  113. if (callback && thisArg) {
  114. callback.call(thisArg, re.data);
  115. }
  116. },
  117. fail: function (re) {
  118. wx.hideLoading();
  119. }
  120. })
  121. } else {
  122. wx.request({
  123. url: httpUrl,
  124. method: methods,
  125. header: {
  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 (res) {
  139. wx.hideLoading();
  140. }
  141. })
  142. }
  143. },
  144. // requestGet:function(url,data,callback){//get接口调用
  145. // wx.request({
  146. // url: url,
  147. // header: {
  148. // "openid": this.globalData.openId
  149. // },
  150. // data: data,
  151. // success:res=>{
  152. // if (callback) {
  153. // }
  154. // }
  155. // })
  156. // },
  157. // requestPost: function (url, data) {//post接口调用
  158. // wx.request({
  159. // url: url,
  160. // header: {
  161. // "Content-Type":"application/x-www-form-urlencoded",
  162. // openid: this.globalData.openId
  163. // },
  164. // data: data,
  165. // success(res) {
  166. // console.log(res.data)
  167. // }
  168. // })
  169. // }
  170. })