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