|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- //app.js
- App({
- onLaunch: function (options) {
- this.globalData.sceneSource = options.scene;
- if (options.referrerInfo && options.referrerInfo.extraData && options.referrerInfo.extraData.source) {
- this.globalData.sceneSource = options.referrerInfo.extraData.source;
- } else if (options.query && options.query.scene) {
- var scene = decodeURIComponent(options.query.scene);
- var source = scene.split("&");
- for (let i = 0; i < source.length; i++) {
- var split = source[i].split("=");
- source[i] = [split[0], split[1]];
- if (split[0] == "source") {
- this.globalData.sceneSource = split[1];
- }
- }
- }
- // 展示本地存储能力
- var openid = wx.getStorageSync('openid') || "";
- if (!openid) {
- // 登录
- this.wxLogin();
- } else {
- this.globalData.openid = openid;
- this.addAppEnter();
- this.getBuyState();
- }
- var entered = wx.getStorageSync('entered');
- if (entered) {
- this.globalData.entered = entered;
- }
- var userMobile = wx.getStorageSync('userMobile');
- if (userMobile){
- this.globalData.userMobile = userMobile;
- }
- var parentOpenid = wx.getStorageSync('parentOpenid');
- if (parentOpenid) {
- this.globalData.parentOpenid = parentOpenid;
- }
- var certificationInfo = wx.getStorageSync('certificationInfo');
- if (certificationInfo) {
- this.globalData.certificationInfo = certificationInfo;
- }
- var userInfoData = wx.getStorageSync("userInfoData");
- if (userInfoData){
- this.globalData.userInfoData = {};
- this.globalData.userInfoData.avatarUrl = userInfoData.avatarUrl;
- this.globalData.userInfoData.nickName = userInfoData.nickName;
- this.globalData.userInfoData.userLevel = userInfoData.userLevel;
- }else{
- if (openid){
- this.getUserInfo();
- }
- }
- var userPhoneType = wx.getStorageSync('userPhoneType');
- if (userPhoneType) {
- this.globalData.userPhoneType = userPhoneType;
- } else {
- this.getPhoneType();
- }
- },
- getPhoneType() {//获取手机类型
- wx.getSystemInfo({
- success: res => {
- wx.setStorageSync("userPhoneType", res.platform);
- this.globalData.userPhoneType = res.platform;
- }
- })
- },
- wxLogin() {
- wx.login({
- success: res => {
- if (res.code) {
- this.getOpenid(res.code);
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- }
- })
- },
- globalData: {
- urlRoot: "https://dongfengqichen.jiyou-tech.com/",//测试接口根目录
- // urlRoot: "https://xing.venucia.com/api/",//接口根目录
- urlStatic: "https://www.jiyou-tech.com/2020/496_qichen/static",//测试静态资源根目录
- // urlStatic: "https://xingb.venucia.com/resource",//静态资源根目录
- openid: "",//OPENID
- parentOpenid:"",//推荐人的openid
- session_key: "",//session_key
- openidSuccessFuc: null,//方法回调
- buyStateSuccessFuc:null,
- nowPage:'0',//当前tabBar
- isRegister:false,//是否已注册
- userMobile:null,//用户手机号
- isFirstLogin: true,//是否为第一次登录
- isFirstLucky: true,//是否为第一次进入幸运星抓手
- indexData:{},//首页数据
- myCenterData:null,//个人中心数据
- userInfoData:{
- "avatarUrl":"",
- "nickName":""
- },
- certificationState:0,//1车主,2合伙人,3同事
- mobileData:null,
- userPhoneType:null,
- kvurl:null,
- kvurlH:0,
- certificationInfo:false,
- getBuyState:null,
- entered:false,
- authenticationStatus:null,
- skipType:null,
- sceneSource:'',
- addPageEnterState:{
- index:false,
- luckyStar:false,
- star:false,
- myCenter:false,
- guessPrize:false,
- everyday:false
- },
- getSecondGuessInfo:{//第二轮价格竞猜信息
- secondData:null,
- firstData:null
- },
- getSecondGuessInfoV2:null,//第二轮价格竞猜结果
- phonebolb:false,
- firstEnterOrder:true,//第一次进入下订
- },
- // 获取openId
- getOpenid: function (code) {
- wx.showLoading({
- title: '加载中',
- mask: true,
- })
- this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
- wx.hideLoading();
- if (res.code == 200) {
- wx.setStorageSync("openid", res.data.openid);
- wx.setStorageSync("session_key", res.data.session_key);
- this.globalData.openid = res.data.openid;
- this.globalData.session_key = res.data.session_key;
- if (this.globalData.openidSuccessFuc) {
- this.globalData.openidSuccessFuc();
- }
- if(this.globalData.mobileData){
- this.getMobile2(this.globalData.mobileData.encryptedData, this.globalData.mobileData.iv, this.globalData.mobileData.callback, this.globalData.mobileData.thisArg);
- }
- var userInfoData = wx.getStorageSync("userInfoData");
- if (!userInfoData) {
- this.getUserInfo();
- }
- this.addAppEnter();
- this.getBuyState();
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- /**
- * wx.request
- */
- wxRequest: function (url, params, callback, thisArg, methods, openid) {
- let that = this;
- var httpUrl = url;
- var str = "";
- var count = 0;
- for (let key in params) {
- if (count) {
- str += "&" + key + "=" + params[key];
- } else {
- str += key + "=" + params[key];
- }
- count++;
- }
- if (str) {
- httpUrl += "?" + str;
- }
- if (!methods) {
- methods = "GET";
- }
- if (methods == "POST") {
- wx.request({
- url: url,
- data: params,
- method: methods,
- header: {
- "content-type": "application/x-www-form-urlencoded",
- "VERSION": '100',
- "OPENID": this.globalData.openid
- },
- success: function (re) {
- // if (re.data.code == -1002) {
- // wx.removeStorageSync('openid');
- // that.wxLogin();
- // // that.wxRequest(url, params, callback, thisArg, methods, openid);
- // }
- if (callback && thisArg) {
- callback.call(thisArg, re.data);
- }
- },
- fail: function (re) {
- wx.hideLoading();
- }
- })
- } else {
- wx.request({
- url: httpUrl,
- method: methods,
- header: {
- "OPENID": this.globalData.openid,
- "VERSION": '100'
- },
- success: function (re) {
- if (re.data.code == -1002) {
- wx.removeStorageSync('openid');
- // that.wxLogin();
- // that.wxRequest(url, params, callback, thisArg, methods, openid);
- }
- if (callback && thisArg) {
- callback.call(thisArg, re.data);
- }
- },
- fail: function (res) {
- wx.hideLoading();
- }
- })
- }
- },
- submitUserMsg: function (avatarUrl, nickName) {//提交用户信息
- this.wxRequest(this.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: avatarUrl, nickName: nickName }, res => {
- if (res.code == 200) {
- this.globalData.userInfoData = {};
- this.globalData.userInfoData.avatarUrl = avatarUrl;
- this.globalData.userInfoData.nickName = nickName;
- wx.setStorageSync('userInfoData', {
- avatarUrl: avatarUrl,
- nickName: nickName,
- userLevel:1
- })
- }
- }, this, "POST")
- },
- codeVerify: function (card) {//身份证号码验证
- 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]$)/;
- return rule.test(card);
- },
- mobileVerify: function (mobile) {//手机号验证
- let rule = /^1\d{10}$/;
- return rule.test(mobile);
- },
- callMobile: function (e) {//拨打电话
- wx.makePhoneCall({
- phoneNumber: e //仅为示例,并非真实的电话号码
- })
- },
- sharePack: function () {//分享
- return {
- title: '发现宝藏小程序!玩游戏赢好礼,来一起探寻更多惊喜吧!',
- imageUrl: this.globalData.urlStatic+"/newImages6/25.png",
- path: "/pages/index/index"
- }
- },
- addformId: function (e) {//添加formid
- this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
- console.log(res.msg);
- }, this, "POST");
- },
- getMobile: function (encryptedData, iv, callback, thisArg) {//检查登录态是否过期
- wx.checkSession({
- success: res => {
- this.getMobile2(encryptedData,iv,callback,thisArg);
- },
- fail: res => {
- this.globalData.mobileData = {};
- this.globalData.mobileData.encryptedData = encryptedData;
- this.globalData.mobileData.iv = iv;
- this.globalData.mobileData.callback = callback;
- this.globalData.mobileData.thisArg = thisArg;
- this.wxLogin();
- }
- })
- },
- getMobile2: function (encryptedData, iv, callback, thisArg) {//和后台置换手机号
- this.globalData.mobileData = null;
- this.wxRequest(this.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: encryptedData, iv: iv }, res => {
- if (res.code == 200) {
- if (res.data && res.data.decodeData) {
- wx.setStorageSync('userMobile', res.data.decodeData.phoneNumber);
- this.globalData.userMobile = res.data.decodeData.phoneNumber;
- }
- }
- if (callback && thisArg) {
- callback.call(thisArg, res);
- }
- }, this, "POST");
- },
- getUserInfo: function () {//获取个人信息
- this.wxRequest(this.globalData.urlRoot +"userInfo/getUserInfo",{},res=>{
- if(res.code==200){
- if (res.data && res.data.avatarUrl) {
- this.globalData.userInfoData = {};
- this.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
- this.globalData.userInfoData.nickName = res.data.nickName;
- this.globalData.userInfoData.userLevel = res.data.userLevel;
- wx.setStorageSync('userInfoData', {
- avatarUrl: res.data.avatarUrl,
- nickName: res.data.nickName,
- userLevel: res.data.userLevel
- })
- }
- }
- },this)
- },
- getBuyState: function () {//查询是否已下订
- this.wxRequest(this.globalData.urlRoot + "wxPay/getBuyState", {source:2}, res => {
- if (res.code == 200) {
- if (res.data) {
- res.data.cdate = res.data.cdate ? res.data.cdate : "";
- this.globalData.getBuyState = res.data;
- if (this.globalData.buyStateSuccessFuc){
- this.globalData.buyStateSuccessFuc();
- }
- }
- }
- }, this);
- },
- addAppEnter: function () {//小程序整体pv统计
- this.wxRequest(this.globalData.urlRoot + "statistics/addAppEnter", { scene:this.globalData.sceneSource}, res => {
- }, this,"POST");
- },
- addPageEnter: function (e) {//小程序页面pv统计
- this.wxRequest(this.globalData.urlRoot + "statistics/addPageEnter", { scene: this.globalData.sceneSource, statisticsType:e }, res => {
- }, this, "POST");
- }
- })
|