东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

5 anos atrás
5 anos atrás
5 anos atrás
5 anos atrás
5 anos atrás
5 anos atrás
5 anos atrás
5 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. // 展示本地存储能力
  5. var openid = wx.getStorageSync('openid') || "";
  6. if (!openid) {
  7. // 登录
  8. this.wxLogin();
  9. } else {
  10. this.globalData.openid = openid;
  11. }
  12. },
  13. wxLogin() {
  14. wx.login({
  15. success: res => {
  16. if (res.code) {
  17. this.getOpenid(res.code);
  18. } else {
  19. console.log('登录失败!' + res.errMsg)
  20. }
  21. }
  22. })
  23. },
  24. globalData: {
  25. urlRoot: "https://dongfengqichen.jiyou-tech.com/",//测试接口根目录
  26. // urlRoot: "",//接口根目录
  27. urlStatic:"https://www.jiyou-tech.com/2020/496_qichen/static",//静态资源根目录
  28. openid: "",//OPENID
  29. friendOpenid:"",//推荐人的openid
  30. session_key: "",//session_key
  31. openidSuccessFuc: null,//方法回调
  32. nowPage:'0',//当前tabBar
  33. isRegister:false,//是否已注册
  34. userMobile:null,//用户手机号
  35. isFirstLogin:true,//是否为第一次登录
  36. indexData:{},//首页数据
  37. myCenterData:null//个人中心数据
  38. },
  39. // 获取openId
  40. getOpenid: function (code) {
  41. wx.showLoading({
  42. title: '加载中',
  43. mask: true,
  44. })
  45. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  46. wx.hideLoading();
  47. console.log(res);
  48. if (res.code == 200) {
  49. wx.setStorageSync("openid", res.data.openid);
  50. wx.setStorageSync("session_key", res.data.session_key);
  51. this.globalData.openid = res.data.openid;
  52. this.globalData.session_key = res.data.session_key;
  53. if (this.globalData.openidSuccessFuc) {
  54. this.globalData.openidSuccessFuc();
  55. }
  56. } else {
  57. wx.showToast({
  58. title: res.msg,
  59. icon: "none"
  60. })
  61. }
  62. }, this);
  63. },
  64. /**
  65. * wx.request
  66. */
  67. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  68. let that = this;
  69. var httpUrl = url;
  70. var str = "";
  71. var count = 0;
  72. for (let key in params) {
  73. if (count) {
  74. str += "&" + key + "=" + params[key];
  75. } else {
  76. str += key + "=" + params[key];
  77. }
  78. count++;
  79. }
  80. if (str) {
  81. httpUrl += "?" + str;
  82. }
  83. if (!methods) {
  84. methods = "GET";
  85. }
  86. if (methods == "POST") {
  87. wx.request({
  88. url: url,
  89. data: params,
  90. method: methods,
  91. header: {
  92. "content-type": "application/x-www-form-urlencoded",
  93. "OPENID": this.globalData.openid
  94. },
  95. success: function (re) {
  96. // if (re.data.code == -1002) {
  97. // wx.removeStorageSync('openid');
  98. // that.wxLogin();
  99. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  100. // }
  101. if (callback && thisArg) {
  102. callback.call(thisArg, re.data);
  103. }
  104. },
  105. fail: function (re) {
  106. wx.hideLoading();
  107. }
  108. })
  109. } else {
  110. wx.request({
  111. url: httpUrl,
  112. method: methods,
  113. header: {
  114. "OPENID": this.globalData.openid,
  115. },
  116. success: function (re) {
  117. if (re.data.code == -1002) {
  118. wx.removeStorageSync('openid');
  119. that.wxLogin();
  120. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  121. }
  122. if (callback && thisArg) {
  123. callback.call(thisArg, re.data);
  124. }
  125. },
  126. fail: function (res) {
  127. wx.hideLoading();
  128. }
  129. })
  130. }
  131. },
  132. submitUserMsg: function (data) {//提交用户信息
  133. this.wxRequest(this.globalData.urlRoot + "/login/submitWxInfo", { userInfo: data }, res => {
  134. }, this, "POST");
  135. },
  136. codeVerify: function (card) {//身份证号码验证
  137. let rule = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
  138. return rule.test(card);
  139. },
  140. mobileVerify: function (mobile) {//手机号验证
  141. let rule = /^1\d{10}$/;
  142. return rule.test(mobile);
  143. },
  144. callMobile: function (e) {//拨打电话
  145. wx.makePhoneCall({
  146. phoneNumber: e //仅为示例,并非真实的电话号码
  147. })
  148. },
  149. sharePack: function () {//分享
  150. return {
  151. title: '',
  152. imageUrl: "",
  153. path: "/pages/index/index"
  154. }
  155. },
  156. addformId: function (e) {//添加formid
  157. console.log("下面是formid");
  158. console.log(e);
  159. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  160. // if(res.code==200){
  161. // console.log(res.msg);
  162. // }else{
  163. // console.log(res.msg);
  164. // }
  165. console.log(res.msg);
  166. }, this, "POST");
  167. }
  168. })