东风启辰小程序端
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.

344 satır
11KB

  1. //app.js
  2. App({
  3. onLaunch: function (options) {
  4. this.globalData.sceneSource = options.scene;
  5. if (options.referrerInfo && options.referrerInfo.extraData && options.referrerInfo.extraData.source) {
  6. this.globalData.sceneSource = options.referrerInfo.extraData.source;
  7. } else if (options.query && options.query.scene) {
  8. var scene = decodeURIComponent(options.query.scene);
  9. var source = scene.split("&");
  10. for (let i = 0; i < source.length; i++) {
  11. var split = source[i].split("=");
  12. source[i] = [split[0], split[1]];
  13. if (split[0] == "source") {
  14. this.globalData.sceneSource = split[1];
  15. }
  16. }
  17. }
  18. // 展示本地存储能力
  19. var openid = wx.getStorageSync('openid') || "";
  20. if (!openid) {
  21. // 登录
  22. this.wxLogin();
  23. } else {
  24. this.globalData.openid = openid;
  25. this.addAppEnter();
  26. this.getBuyState();
  27. }
  28. var isStar = wx.getStorageSync('isStar');
  29. if (isStar) {
  30. this.globalData.isStar = isStar;
  31. }
  32. var entered = wx.getStorageSync('entered');
  33. if (entered) {
  34. this.globalData.entered = entered;
  35. }
  36. var userMobile = wx.getStorageSync('userMobile');
  37. if (userMobile){
  38. this.globalData.userMobile = userMobile;
  39. }
  40. var parentOpenid = wx.getStorageSync('parentOpenid');
  41. if (parentOpenid) {
  42. this.globalData.parentOpenid = parentOpenid;
  43. }
  44. var certificationInfo = wx.getStorageSync('certificationInfo');
  45. if (certificationInfo) {
  46. this.globalData.certificationInfo = certificationInfo;
  47. }
  48. var userInfoData = wx.getStorageSync("userInfoData");
  49. if (userInfoData){
  50. this.globalData.userInfoData = {};
  51. this.globalData.userInfoData.avatarUrl = userInfoData.avatarUrl;
  52. this.globalData.userInfoData.nickName = userInfoData.nickName;
  53. this.globalData.userInfoData.userLevel = userInfoData.userLevel;
  54. }else{
  55. if (openid){
  56. this.getUserInfo();
  57. }
  58. }
  59. var userPhoneType = wx.getStorageSync('userPhoneType');
  60. if (userPhoneType) {
  61. this.globalData.userPhoneType = userPhoneType;
  62. } else {
  63. this.getPhoneType();
  64. }
  65. },
  66. getPhoneType() {//获取手机类型
  67. wx.getSystemInfo({
  68. success: res => {
  69. wx.setStorageSync("userPhoneType", res.platform);
  70. this.globalData.userPhoneType = res.platform;
  71. }
  72. })
  73. },
  74. wxLogin() {
  75. wx.login({
  76. success: res => {
  77. if (res.code) {
  78. this.getOpenid(res.code);
  79. } else {
  80. console.log('登录失败!' + res.errMsg)
  81. }
  82. }
  83. })
  84. },
  85. globalData: {
  86. // urlRoot: "https://dongfengqichen.jiyou-tech.com/",//测试接口根目录
  87. urlRoot: "https://xing.venucia.com/api/",//接口根目录
  88. // urlStatic: "https://www.jiyou-tech.com/2020/496_qichen/static",//测试静态资源根目录
  89. urlStatic: "https://xingb.venucia.com/resource",//静态资源根目录
  90. openid: "",//OPENID
  91. parentOpenid:"",//推荐人的openid
  92. session_key: "",//session_key
  93. openidSuccessFuc: null,//方法回调
  94. buyStateSuccessFuc:null,
  95. nowPage:'0',//当前tabBar
  96. isRegister:false,//是否已注册
  97. userMobile:null,//用户手机号
  98. isFirstLogin: true,//是否为第一次登录
  99. isFirstLucky: true,//是否为第一次进入幸运星抓手
  100. indexData:{},//首页数据
  101. myCenterData:null,//个人中心数据
  102. userInfoData:{
  103. "avatarUrl":"",
  104. "nickName":""
  105. },
  106. certificationState:0,//1车主,2合伙人,3同事
  107. mobileData:null,
  108. userPhoneType:null,
  109. kvurl:null,
  110. kvurlH:0,
  111. certificationInfo:false,
  112. getBuyState:null,
  113. entered:false,
  114. authenticationStatus:null,
  115. skipType:null,
  116. sceneSource:'',
  117. addPageEnterState:{
  118. index:false,
  119. luckyStar:false,
  120. star:false,
  121. myCenter:false,
  122. guessPrize:false,
  123. everyday:false
  124. },
  125. getSecondGuessInfo:{//第二轮价格竞猜信息
  126. secondData:null,
  127. firstData:null
  128. },
  129. getSecondGuessInfoV2:null,//第二轮价格竞猜结果
  130. phonebolb:false,
  131. isStar:null,//是否为星探
  132. },
  133. // 获取openId
  134. getOpenid: function (code) {
  135. wx.showLoading({
  136. title: '加载中',
  137. mask: true,
  138. })
  139. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  140. wx.hideLoading();
  141. if (res.code == 200) {
  142. wx.setStorageSync("openid", res.data.openid);
  143. wx.setStorageSync("session_key", res.data.session_key);
  144. this.globalData.openid = res.data.openid;
  145. this.globalData.session_key = res.data.session_key;
  146. if (this.globalData.openidSuccessFuc) {
  147. this.globalData.openidSuccessFuc();
  148. }
  149. if(this.globalData.mobileData){
  150. this.getMobile2(this.globalData.mobileData.encryptedData, this.globalData.mobileData.iv, this.globalData.mobileData.callback, this.globalData.mobileData.thisArg);
  151. }
  152. var userInfoData = wx.getStorageSync("userInfoData");
  153. if (!userInfoData) {
  154. this.getUserInfo();
  155. }
  156. this.addAppEnter();
  157. this.getBuyState();
  158. } else {
  159. wx.showToast({
  160. title: res.msg,
  161. icon: "none"
  162. })
  163. }
  164. }, this);
  165. },
  166. /**
  167. * wx.request
  168. */
  169. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  170. let that = this;
  171. var httpUrl = url;
  172. var str = "";
  173. var count = 0;
  174. for (let key in params) {
  175. if (count) {
  176. str += "&" + key + "=" + params[key];
  177. } else {
  178. str += key + "=" + params[key];
  179. }
  180. count++;
  181. }
  182. if (str) {
  183. httpUrl += "?" + str;
  184. }
  185. if (!methods) {
  186. methods = "GET";
  187. }
  188. if (methods == "POST") {
  189. wx.request({
  190. url: url,
  191. data: params,
  192. method: methods,
  193. header: {
  194. "content-type": "application/x-www-form-urlencoded",
  195. "VERSION": '100',
  196. "OPENID": this.globalData.openid
  197. // "OPENID": "o4h7Y5ReAtr8SiEYzRWgJGu82UiI"
  198. },
  199. success: function (re) {
  200. // if (re.data.code == -1002) {
  201. // wx.removeStorageSync('openid');
  202. // that.wxLogin();
  203. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  204. // }
  205. if (callback && thisArg) {
  206. callback.call(thisArg, re.data);
  207. }
  208. },
  209. fail: function (re) {
  210. wx.hideLoading();
  211. }
  212. })
  213. } else {
  214. wx.request({
  215. url: httpUrl,
  216. method: methods,
  217. header: {
  218. "OPENID": this.globalData.openid,
  219. // "OPENID": "o4h7Y5ReAtr8SiEYzRWgJGu82UiI",
  220. "VERSION": '100'
  221. },
  222. success: function (re) {
  223. if (re.data.code == -1002) {
  224. wx.removeStorageSync('openid');
  225. // that.wxLogin();
  226. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  227. }
  228. if (callback && thisArg) {
  229. callback.call(thisArg, re.data);
  230. }
  231. },
  232. fail: function (res) {
  233. wx.hideLoading();
  234. }
  235. })
  236. }
  237. },
  238. submitUserMsg: function (avatarUrl, nickName) {//提交用户信息
  239. this.wxRequest(this.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: avatarUrl, nickName: nickName }, res => {
  240. if (res.code == 200) {
  241. this.globalData.userInfoData = {};
  242. this.globalData.userInfoData.avatarUrl = avatarUrl;
  243. this.globalData.userInfoData.nickName = nickName;
  244. wx.setStorageSync('userInfoData', {
  245. avatarUrl: avatarUrl,
  246. nickName: nickName,
  247. userLevel:1
  248. })
  249. }
  250. }, this, "POST")
  251. },
  252. codeVerify: function (card) {//身份证号码验证
  253. 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]$)/;
  254. return rule.test(card);
  255. },
  256. mobileVerify: function (mobile) {//手机号验证
  257. let rule = /^1\d{10}$/;
  258. return rule.test(mobile);
  259. },
  260. callMobile: function (e) {//拨打电话
  261. wx.makePhoneCall({
  262. phoneNumber: e //仅为示例,并非真实的电话号码
  263. })
  264. },
  265. sharePack: function () {//分享
  266. return {
  267. title: '发现宝藏小程序!玩游戏赢好礼,来一起探寻更多惊喜吧!',
  268. imageUrl: this.globalData.urlStatic+"/newImages6/25.png?v=002",
  269. path: "/pages/index/index"
  270. }
  271. },
  272. addformId: function (e) {//添加formid
  273. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  274. console.log(res.msg);
  275. }, this, "POST");
  276. },
  277. getMobile: function (encryptedData, iv, callback, thisArg) {//检查登录态是否过期
  278. wx.checkSession({
  279. success: res => {
  280. this.getMobile2(encryptedData,iv,callback,thisArg);
  281. },
  282. fail: res => {
  283. this.globalData.mobileData = {};
  284. this.globalData.mobileData.encryptedData = encryptedData;
  285. this.globalData.mobileData.iv = iv;
  286. this.globalData.mobileData.callback = callback;
  287. this.globalData.mobileData.thisArg = thisArg;
  288. this.wxLogin();
  289. }
  290. })
  291. },
  292. getMobile2: function (encryptedData, iv, callback, thisArg) {//和后台置换手机号
  293. this.globalData.mobileData = null;
  294. this.wxRequest(this.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: encryptedData, iv: iv }, res => {
  295. if (res.code == 200) {
  296. if (res.data && res.data.decodeData) {
  297. wx.setStorageSync('userMobile', res.data.decodeData.phoneNumber);
  298. this.globalData.userMobile = res.data.decodeData.phoneNumber;
  299. }
  300. }
  301. if (callback && thisArg) {
  302. callback.call(thisArg, res);
  303. }
  304. }, this, "POST");
  305. },
  306. getUserInfo: function () {//获取个人信息
  307. this.wxRequest(this.globalData.urlRoot +"userInfo/getUserInfo",{},res=>{
  308. if(res.code==200){
  309. if (res.data && res.data.avatarUrl) {
  310. this.globalData.userInfoData = {};
  311. this.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  312. this.globalData.userInfoData.nickName = res.data.nickName;
  313. this.globalData.userInfoData.userLevel = res.data.userLevel;
  314. wx.setStorageSync('userInfoData', {
  315. avatarUrl: res.data.avatarUrl,
  316. nickName: res.data.nickName,
  317. userLevel: res.data.userLevel
  318. })
  319. }
  320. }
  321. },this)
  322. },
  323. getBuyState: function () {//查询是否已下订
  324. this.wxRequest(this.globalData.urlRoot + "wxPay/getBuyState", {source:2}, res => {
  325. if (res.code == 200) {
  326. if (res.data) {
  327. res.data.cdate = res.data.cdate ? res.data.cdate : "";
  328. this.globalData.getBuyState = res.data;
  329. if (this.globalData.buyStateSuccessFuc){
  330. this.globalData.buyStateSuccessFuc();
  331. }
  332. }
  333. }
  334. }, this);
  335. },
  336. addAppEnter: function () {//小程序整体pv统计
  337. this.wxRequest(this.globalData.urlRoot + "statistics/addAppEnter", { scene:this.globalData.sceneSource}, res => {
  338. }, this,"POST");
  339. },
  340. addPageEnter: function (e) {//小程序页面pv统计
  341. this.wxRequest(this.globalData.urlRoot + "statistics/addPageEnter", { scene: this.globalData.sceneSource, statisticsType:e }, res => {
  342. }, this, "POST");
  343. }
  344. })