静默保存渠道id

This commit is contained in:
邱贞招 2024-01-27 21:16:35 +08:00
parent 0c4f396599
commit c5f055cc1c
11 changed files with 134 additions and 83 deletions

View File

@ -19,11 +19,12 @@ export function getWechatConfig() {
* 获取微信sdk配置
* @returns {*}
*/
export function wechatAuth(code, spread) {
export function wechatAuth(code, spread,channelId) {
var reg=/^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 ,判断正整数用/^[1-9]+[0-9]*]*$/
spread = reg.test(spread) ? spread : 0;
channelId = reg.test(channelId) ? channelId : 0;
return request.get(
"wechat/authorize/login?code=" + code + "&spread_spid=" + spread, {},
"wechat/authorize/login?code=" + code + "&spread_spid=" + spread+"&channelId="+channelId, {},
{ noAuth: true }
);
}

View File

@ -382,7 +382,7 @@ export function spread(puid)
return request.get("user/bindSpread?spreadPid="+ puid);
}
/**
// * 静默绑定推广人
// * 静默绑定渠道
// * @param {Object} channelId
// */
export function channel(channelId)

View File

@ -1,7 +1,7 @@
//移动端商城API
// let domain = 'http://117.50.163.143:20410'
// let domain = 'http://117.50.215.20:20410'
let domain = 'http://192.168.2.14:8081'
let domain = 'http://117.50.215.20:20410'
// let domain = 'http://192.168.2.14:8081'
// let domain = 'http://106.75.49.247:20410'
module.exports = {
@ -11,7 +11,7 @@ module.exports = {
HTTP_REQUEST_URL: domain,
// H5商城地址
// HTTP_H5_URL: 'http://106.75.49.247:20410',
HTTP_H5_URL: 'http://192.168.2.14:8081',
HTTP_H5_URL: 'http://117.50.215.20:20410',
// #endif
// #ifdef H5
HTTP_REQUEST_URL:domain,

View File

@ -27,6 +27,7 @@ module.exports = {
TIPS_KEY: 'TIPS_KEY',
SPREAD: 'SPREAD',
CHANNELID: 'CHANNELID',
//缓存经度
CACHE_LONGITUDE: 'LONGITUDE',
//缓存纬度

View File

@ -217,7 +217,7 @@ class AuthWechat {
*/
auth(code) {
return new Promise((resolve, reject) => {
wechatAuth(code, Cache.get('spread'))
wechatAuth(code, Cache.get('spread'),Cache.get('channelId'))
.then(({
data
}) => {

17
main.js
View File

@ -29,12 +29,13 @@ import {
} from "./utils";
import Auth from './libs/wechat';
import {
SPREAD
SPREAD,CHANNELID
} from './config/cache';
Vue.prototype.$wechat = Auth;
let cookieName = "VCONSOLE",
query = parseQuery(),
urlSpread = query["spread"],
urlChannelId = query["channelId"],
vconsole = query[cookieName.toLowerCase()],
md5Crmeb = "b14d1e9baeced9bb7525ab19ee35f2d2", //CRMEB MD5 加密开启vconsole模式
md5UnCrmeb = "3dca2162c4e101b7656793a1af20295c"; //UN_CREMB MD5 加密关闭vconsole模式
@ -44,13 +45,13 @@ let cookieName = "VCONSOLE",
name: 'spread',
value: urlSpread,
})
// var spread = Cache.get(SPREAD);
// urlSpread = parseInt(urlSpread);
// if (!Number.isNaN(urlSpread) && spread !== urlSpread) {
// Cache.set("spread", urlSpread || 0);
// } else if (spread === 0 || typeof spread !== "number") {
// Cache.set("spread", urlSpread || 0);
// }
}
if (urlChannelId) {
urlChannelId = parseInt(urlChannelId);
Cache.setItem({
name: 'channelId',
value: urlChannelId,
})
}
if (vconsole !== undefined) {
if (vconsole === md5UnCrmeb && Cache.has(cookieName))

View File

@ -1,6 +1,6 @@
{
"name" : "先享后付",
"appid" : "__UNI__C7D69AA", //wxb74514b47a2f29d4 wx46c3a73d8c4f7051 __UNI__EB8A7B
"appid" : "__UNI__E7B7107", //wxb74514b47a2f29d4 wx46c3a73d8c4f7051 __UNI__EB8A7B
"description" : "crmeb商城",
"versionName" : "2.1",
"versionCode" : 2,
@ -219,8 +219,7 @@
"async" : {
"timeout" : 200000
},
"title" : "先享后付",
"template" : "template.html"
"title" : "先享后付"
},
"plus" : {
"statusbar" : {

View File

@ -368,7 +368,7 @@
import shareRedPackets from '@/components/shareRedPackets';
import cusPreviewImg from '@/components/cus-previewImg/cus-previewImg.vue'
import {
silenceBindingSpread
silenceBindingSpread,silenceBindingChannelId
} from "@/utils";
import parser from "@/components/jyf-parser/jyf-parser";
import {
@ -550,6 +550,8 @@
this.getTokenIsExist();
},
onLoad(options) {
// console.log(JSON.stringify(options),"options.spread")
alert("options.spread"+JSON.stringify(options))
//
this.$set(this, 'theme', this.$Cache.get('theme'));
@ -607,6 +609,7 @@
// #endif
if (options.spread) app.globalData.spread = options.spread;
if (options.channelId) app.globalData.channelId = options.channelId;
this.getGoodsDetails(); //
this.getCouponType(); //
@ -683,6 +686,7 @@
this.getCartCount(true); //
//
if (parseInt(app.globalData.spread) > 0) silenceBindingSpread();
if (parseInt(app.globalData.channelId) > 0) silenceBindingChannelId();
}
});
},

View File

@ -210,7 +210,7 @@
getGroomList
} from '@/api/store.js';
import {
silenceBindingSpread,
silenceBindingSpread,silenceBindingChannelId,
getCityList
} from '@/utils';
import animationType from '@/utils/animationType.js'
@ -418,8 +418,10 @@
let qrCodeValue = this.$util.getUrlParams(decodeURIComponent(options.scene));
let mapeMpQrCodeValue = this.$util.formatMpQrCodeData(qrCodeValue);
app.globalData.spread = mapeMpQrCodeValue.spread;
app.globalData.channelId = mapeMpQrCodeValue.channelId;
}
if (options.spread) app.globalData.spread = options.spread; //urlidglobalDta
if (options.channelId) app.globalData.channelId = options.channelId; //urlidglobalDta
// #endif
// #ifndef MP || APP-PLUS
this.navH = 0;
@ -431,6 +433,12 @@
if (this.isLogin && parseInt(app.globalData.spread) > 0) {
silenceBindingSpread()
}
if (this.isLogin && parseInt(app.globalData.channelId) > 0) {
silenceBindingChannelId()
}
if (this.isLogin && parseInt(options.channelId) > 0) {
silenceBindingChannelId()
}
},
onShow() {
let self = this;

View File

@ -146,8 +146,9 @@
//if(!code) location.replace(decodeURIComponent(decodeURIComponent(option.query.back_url)));
if (code && this.options.scope !== 'snsapi_base') {
let spread = app.globalData.spread ? app.globalData.spread : 0;
let channelId = app.globalData.channelId ? app.globalData.channelId : 0;
// wechatAuth(code, Cache.get("spread"), loginType)
wechat.auth(code, spread).then(res => {
wechat.auth(code, spread,channelId).then(res => {
if (res.type === 'register') {
this.authKey = res.key;
this.isUp = true
@ -252,6 +253,7 @@
let userInfo = {};
userInfo.code = code;
userInfo.spread_spid = app.globalData.spread; //广ID
userInfo.channelId = app.globalData.channelId; //ID
userInfo.avatar = '';
userInfo.nickName = '微信用户';
userInfo.type = 'routine'
@ -267,6 +269,7 @@
let userInfo = res.userInfo;
userInfo.code = code;
userInfo.spread_spid = app.globalData.spread; //广ID
userInfo.channelId = app.globalData.channelId; //ID
userInfo.avatar = userInfo.userInfo.avatarUrl;
userInfo.city = userInfo.userInfo.city;
userInfo.country = userInfo.userInfo.country;
@ -306,6 +309,9 @@
if (app.globalData.spread) {
spread(app.globalData.spread).then(res => {}) //spread
}
if (app.globalData.channelId) {
channelId(app.globalData.channelId).then(res => {}) //
}
self.$util.Tips({
title: res,
icon: 'success'

View File

@ -1,6 +1,6 @@
import { spread } from "@/api/user";
import { spread,channel } from "@/api/user";
import Cache from "@/utils/cache";
import { getCity } from '@/api/api.js';
@ -35,6 +35,37 @@ export function silenceBindingSpread() {
}
}
/**
* 静默授权绑定渠道使用在已经登录后扫描了别人的推广二维码
* @param {Object} puid
*/
export function silenceBindingChannelId() {
//#ifdef H5
let puid = Cache.get('channelId');
//#endif
//#ifdef MP || APP-PLUS
let puid = getApp().globalData.channelId;
//#endif
puid = parseInt(puid);
if (Number.isNaN(puid)) {
puid = 0;
}
if (puid) {
channel(puid).then(res => {}).catch(res => {
//#ifdef H5
Cache.clear("channelId");
//#endif
//#ifdef MP || APP-PLUS
getApp().globalData.channelId = 0;
//#endif
});
} else {
Cache.set('channelId', 0);
}
}
export function isWeixin() {
return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
}