东风启辰小程序端
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 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
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. guessPrize:false,
  117. everyday:false
  118. }
  119. },
  120. // 获取openId
  121. getOpenid: function (code) {
  122. wx.showLoading({
  123. title: '加载中',
  124. mask: true,
  125. })
  126. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  127. wx.hideLoading();
  128. if (res.code == 200) {
  129. wx.setStorageSync("openid", res.data.openid);
  130. wx.setStorageSync("session_key", res.data.session_key);
  131. this.globalData.openid = res.data.openid;
  132. this.globalData.session_key = res.data.session_key;
  133. if (this.globalData.openidSuccessFuc) {
  134. this.globalData.openidSuccessFuc();
  135. }
  136. if(this.globalData.mobileData){
  137. this.getMobile2(this.globalData.mobileData.encryptedData, this.globalData.mobileData.iv, this.globalData.mobileData.callback, this.globalData.mobileData.thisArg);
  138. }
  139. var userInfoData = wx.getStorageSync("userInfoData");
  140. if (!userInfoData) {
  141. this.getUserInfo();
  142. }
  143. this.addAppEnter();
  144. this.getBuyState();
  145. } else {
  146. wx.showToast({
  147. title: res.msg,
  148. icon: "none"
  149. })
  150. }
  151. }, this);
  152. },
  153. /**
  154. * wx.request
  155. */
  156. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  157. let that = this;
  158. var httpUrl = url;
  159. var str = "";
  160. var count = 0;
  161. for (let key in params) {
  162. if (count) {
  163. str += "&" + key + "=" + params[key];
  164. } else {
  165. str += key + "=" + params[key];
  166. }
  167. count++;
  168. }
  169. if (str) {
  170. httpUrl += "?" + str;
  171. }
  172. if (!methods) {
  173. methods = "GET";
  174. }
  175. if (methods == "POST") {
  176. wx.request({
  177. url: url,
  178. data: params,
  179. method: methods,
  180. header: {
  181. "content-type": "application/x-www-form-urlencoded",
  182. "VERSION": '100',
  183. "OPENID": this.globalData.openid
  184. },
  185. success: function (re) {
  186. // if (re.data.code == -1002) {
  187. // wx.removeStorageSync('openid');
  188. // that.wxLogin();
  189. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  190. // }
  191. if (callback && thisArg) {
  192. callback.call(thisArg, re.data);
  193. }
  194. },
  195. fail: function (re) {
  196. wx.hideLoading();
  197. }
  198. })
  199. } else {
  200. wx.request({
  201. url: httpUrl,
  202. method: methods,
  203. header: {
  204. "OPENID": this.globalData.openid,
  205. "VERSION": '100'
  206. },
  207. success: function (re) {
  208. if (re.data.code == -1002) {
  209. wx.removeStorageSync('openid');
  210. // that.wxLogin();
  211. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  212. }
  213. if (callback && thisArg) {
  214. callback.call(thisArg, re.data);
  215. }
  216. },
  217. fail: function (res) {
  218. wx.hideLoading();
  219. }
  220. })
  221. }
  222. },
  223. submitUserMsg: function (avatarUrl, nickName) {//提交用户信息
  224. this.wxRequest(this.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: avatarUrl, nickName: nickName }, res => {
  225. if (res.code == 200) {
  226. this.globalData.userInfoData = {};
  227. this.globalData.userInfoData.avatarUrl = avatarUrl;
  228. this.globalData.userInfoData.nickName = nickName;
  229. wx.setStorageSync('userInfoData', {
  230. avatarUrl: avatarUrl,
  231. nickName: nickName,
  232. userLevel:1
  233. })
  234. }
  235. }, this, "POST")
  236. },
  237. codeVerify: function (card) {//身份证号码验证
  238. 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]$)/;
  239. return rule.test(card);
  240. },
  241. mobileVerify: function (mobile) {//手机号验证
  242. let rule = /^1\d{10}$/;
  243. return rule.test(mobile);
  244. },
  245. callMobile: function (e) {//拨打电话
  246. wx.makePhoneCall({
  247. phoneNumber: e //仅为示例,并非真实的电话号码
  248. })
  249. },
  250. sharePack: function () {//分享
  251. return {
  252. title: '',
  253. imageUrl: "",
  254. path: "/pages/index/index"
  255. }
  256. },
  257. addformId: function (e) {//添加formid
  258. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  259. console.log(res.msg);
  260. }, this, "POST");
  261. },
  262. getMobile: function (encryptedData, iv, callback, thisArg) {//检查登录态是否过期
  263. wx.checkSession({
  264. success: res => {
  265. this.getMobile2(encryptedData,iv,callback,thisArg);
  266. },
  267. fail: res => {
  268. this.globalData.mobileData = {};
  269. this.globalData.mobileData.encryptedData = encryptedData;
  270. this.globalData.mobileData.iv = iv;
  271. this.globalData.mobileData.callback = callback;
  272. this.globalData.mobileData.thisArg = thisArg;
  273. this.wxLogin();
  274. }
  275. })
  276. },
  277. getMobile2: function (encryptedData, iv, callback, thisArg) {//和后台置换手机号
  278. this.globalData.mobileData = null;
  279. this.wxRequest(this.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: encryptedData, iv: iv }, res => {
  280. if (res.code == 200) {
  281. if (res.data && res.data.decodeData) {
  282. wx.setStorageSync('userMobile', res.data.decodeData.phoneNumber);
  283. this.globalData.userMobile = res.data.decodeData.phoneNumber;
  284. }
  285. }
  286. if (callback && thisArg) {
  287. callback.call(thisArg, res);
  288. }
  289. }, this, "POST");
  290. },
  291. getUserInfo: function () {//获取个人信息
  292. this.wxRequest(this.globalData.urlRoot +"userInfo/getUserInfo",{},res=>{
  293. if(res.code==200){
  294. if (res.data && res.data.avatarUrl) {
  295. this.globalData.userInfoData = {};
  296. this.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  297. this.globalData.userInfoData.nickName = res.data.nickName;
  298. this.globalData.userInfoData.userLevel = res.data.userLevel;
  299. wx.setStorageSync('userInfoData', {
  300. avatarUrl: res.data.avatarUrl,
  301. nickName: res.data.nickName,
  302. userLevel: res.data.userLevel
  303. })
  304. }
  305. }
  306. },this)
  307. },
  308. getBuyState: function () {//查询是否已下订
  309. this.wxRequest(this.globalData.urlRoot + "wxPay/getBuyState", {}, res => {
  310. if (res.code == 200) {
  311. if (res.data) {
  312. res.data.cdate = res.data.cdate ? res.data.cdate : "";
  313. this.globalData.getBuyState = res.data;
  314. if (this.globalData.buyStateSuccessFuc){
  315. this.globalData.buyStateSuccessFuc();
  316. }
  317. }
  318. }
  319. }, this);
  320. },
  321. addAppEnter: function () {//小程序整体pv统计
  322. this.wxRequest(this.globalData.urlRoot + "statistics/addAppEnter", { scene:this.globalData.sceneSource}, res => {
  323. }, this,"POST");
  324. },
  325. addPageEnter: function (e) {//小程序页面pv统计
  326. this.wxRequest(this.globalData.urlRoot + "statistics/addPageEnter", { scene: this.globalData.sceneSource, statisticsType:e }, res => {
  327. }, this, "POST");
  328. }
  329. })