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

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