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