东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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