东风启辰小程序端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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