gswz/SFHY/static/js/tool_apply.js

279 lines
9.9 KiB
JavaScript
Raw Normal View History

2024-02-28 14:35:44 +08:00
var link = document.location.href
var refer = document.referrer
var tool = {
setCookie: function (cname, cvalue, cday) {
var d = new Date()
d.setTime(d.getTime() + cday * 24 * 60 * 60 * 1000)
var expires = "expires=" + d.toGMTString()
document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/"
},
getCookie: function (cname) {
var name = cname + "="
var ca = document.cookie.split(";")
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim()
if (c.indexOf(name) == 0) return c.substring(name.length, c.length)
}
return ""
},
checkCookie: function () {
var qd = this.getCookie("qd")
if (qd != "") {
console.log(qd)
} else {
console.log(link)
}
}
}
var G = {
sent: "https://www.hollycrm.com/messageInterface/sendVerifyMessage.php",
verify: "https://www.hollycrm.com/messageInterface/verifyMessage.php",
info: "holly.400",
state: "",
actionId: ""
}
/* ............ 取出存储的来源链接ssessioon ............ */
var sourceUrl = sessionStorage.getItem("qd") || tool.getCookie("qd") || refer || link
/* ................. 分渠道修改网站电话 ................ */
function changeNumber() {
if (sourceUrl && sourceUrl.indexOf("baidu.com") > 0 && sourceUrl.indexOf("medium=cpc") < 0) {
$(".telNum").each(function () {
$(this).text("4000-628-505") //百度SEO
})
}
if (sourceUrl && sourceUrl.indexOf("medium=cpc") > 0 && sourceUrl.indexOf("baidu") > 0) {
$(".telNum").each(function () {
$(this).text("4006-456-595") //百度SEM
})
}
if (sourceUrl && (sourceUrl.indexOf("aladdin") > 0 || location.href.indexOf("aladdin") > 0)) {
$(".telNum").each(function () {
$(this).text("4008-198-638") //阿拉丁
})
}
if (sourceUrl.indexOf("medium=cpc") < 0 && (sourceUrl.indexOf("media=360") > 0 || sourceUrl.indexOf("so.com") > 0 || sourceUrl.indexOf("source=360") > 0)) {
$(".telNum").each(function () {
$(this).text("4000-628-505") //360SEO
})
}
if (sourceUrl.indexOf("medium=cpc") > 0 && (sourceUrl.indexOf("media=360") > 0 || sourceUrl.indexOf("so.com") > 0 || sourceUrl.indexOf("source=360") > 0)) {
$(".telNum").each(function () {
$(this).text("4006-345-595") //360SEM
})
}
if (sourceUrl.indexOf("medium=cpc") > 0 && (sourceUrl.indexOf("media=sogou") > 0 || sourceUrl.indexOf("sogou.com") > 0)) {
$(".telNum").each(function () {
$(this).text("4006-345-595") //搜狗SEM
})
}
if (sourceUrl && (sourceUrl.indexOf("zhihu") > 0 || sourceUrl.indexOf("知乎") > 0 || sourceUrl.indexOf("%E7%9F%A5%E4%B9%8E") > 0)) {
$(".telNum").each(function () {
$(this).text("4006-240-256") //知乎
})
}
if (sourceUrl.indexOf("medium=cpc") > 0 && sourceUrl.indexOf("project") > 0) {
$(".telNum").each(function () {
$(this).text("4006-345-690") //项目管理页面SEM相关
})
}
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i)) {
$(".telNum").each(function () {
$(this).text("180-4353-0712") //移动端的
})
}
axios({
method: "post",
url: "https://ipapi.co/json/"
}).then(res => {
var ipApiCity = res.data.city || ""
if (ipApiCity.indexOf("Shanghai") > -1) {
$(".telNum").each(function () {
$(this).text("021-61897000") //上海区域的
})
}
}).catch(err => {
console.log("??ip定位 err:", err)
})
}
changeNumber()
/* ............ 如果在手机屏幕下则加载适配移动端的js ........... */
function IsMobile() {
let info = navigator.userAgent
let agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPod", "iPad"]
for (let i = 0; i < agents.length; i++) {
if (info.indexOf(agents[i]) >= 0) return true
}
return false
}
/* ---------- 下面是企微活码相关的内容 ---------- */
function getUrlData(link = location.href) {//获取url中的参数
let urlData = {}
if (link.indexOf("?") != -1) {
let index = link.lastIndexOf("?")
let url = link.substring(index, link.length)
let str = url.substr(1)
let strs = str.split("&")
for (let i = 0; i < strs.length; i++) {
try {
urlData[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1])
} catch (error) {
urlData[strs[i].split("=")[0]] = strs[i].split("=")[1]
}
}
}
return urlData
}
const urlParam = getUrlData(sourceUrl)
let website_device = "pc"
if (window.navigator && /Mobile|Android|webOS|iPhone|iPad|Phone/i.test(navigator.userAgent)) {
website_device = "mobile"
}
let website_url = sourceUrl //来源链接
let website_landing_page_type = "hollycrm," + website_device //落地页类型
let website_contact_channel = "wxwork" //联络渠道
/* -------------- 推广媒体 -------------- */
function websiteMedia() {
let media = "no"
if (sourceUrl.indexOf("baidu") > -1 || sourceUrl.indexOf("百度") > -1 || sourceUrl.indexOf("aladdin") > -1) {
media = "baidu,seo"
if (sourceUrl.indexOf("medium=cpc") > -1 || sourceUrl.indexOf("zhidao.baidu") > -1 || sourceUrl.indexOf("百度,SEM") > -1) {
media = "baidu,sem"
}
if (sourceUrl.indexOf("aladdin") > -1) {
media = "baidu,aladdin"
}
if (sourceUrl.indexOf("baidufeed") > -1) {
media = "baidu,baidufeed"
}
}
if (sourceUrl.indexOf("so.com") > -1 || sourceUrl.indexOf("media=360") > -1 || sourceUrl.indexOf("source=360") > -1) {
media = "360,seo"
if (sourceUrl.indexOf("medium=cpc") > -1 || sourceUrl.indexOf("360SEM") > -1) {
media = "360,sem"
}
}
if (sourceUrl.indexOf("sogou.com") > -1 || sourceUrl.indexOf("media=sogou") > -1) {
media = "sogou,seo"
if (sourceUrl.indexOf("cpc") > -1) {
media = "sogou,sem"
}
}
if (sourceUrl.indexOf("zhihu") > -1 || sourceUrl.indexOf("知乎") > -1) {
media = "zhihu"
}
if (sourceUrl.indexOf("google.com") > -1) {
media = "google"
}
if (sourceUrl.indexOf("sm.cn") > -1) {
media = "sm"
}
if (sourceUrl.indexOf("bing.com") > -1 || sourceUrl.indexOf("bing.cn") > -1) {
media = "bing"
}
if (sourceUrl.indexOf("douban.com") > -1) {
media = "douban"
}
if (sourceUrl.indexOf("taobao.com") > -1) {
media = "taobao"
}
if (sourceUrl.indexOf("toutiao") > -1) {
media = "toutiao"
}
if (sourceUrl.indexOf("a6.7x24cc.com") > -1) {
media = "a6"
}
return media
}
let website_promotion_media = websiteMedia()
/* --------------- 关键词 -------------- */
let website_keywords = urlParam.utm_term || urlParam.word || urlParam.wd || urlParam.hmkw || urlParam.q || urlParam.query || urlParam.keyword || ""
/* -------------- 计划单元 -------------- */
let website_plan_unit = ""
let website_keywords_string = ""
if (urlParam.plan || urlParam.unit) {
website_plan_unit = urlParam.plan + "-" + urlParam.unit
}
if (website_keywords && website_plan_unit) {
website_keywords_string = website_plan_unit + "-" + website_keywords // 媒体摘要
}
if (!website_plan_unit && website_keywords) {// 只有关键词
website_keywords_string = website_keywords
}
if (website_plan_unit && !website_keywords) {// 只有计划单元
website_keywords_string = website_plan_unit
}
let bd_vid = urlParam.bd_vid || "" // 百度vid
var qrCode = "" // 二维码图片地址
async function getAccessToken() {
//获取access_token
let res = await axios.get("https://a2.xiaomilaile.com/local-commonInte/accessToken?account=N000000001907&appid=xmpavkl4bgs4lihg&secret=120d0781-827c-4320-9104-47cb33a303ae")
return res.data.accessToken
}
async function getCode() {
//获取二维码
let accessToken = await getAccessToken()
const data = {
account: "N000000001907",
access_token: accessToken,
id: "5e89b46d-6a41-4dd0-8056-953f33708921",
website_keywords: website_keywords_string, //媒体摘要 包含计划 单元 关键词
website_url: website_url, //原始链接
website_promotion_media: website_promotion_media, //推广媒体 如 百度SEM baidu,sem
website_contact_channel: website_contact_channel, //联络渠道 如企业微信 wxwork
website_landing_page_type: website_landing_page_type, //落地页 hollycrm,pc
processLevel: "undefined,undefined",// 客户分级
welcome_msg: `您好,欢迎关注合力亿捷。
我们专注营销服一体化客户联络方案拥有20年技术积累产品覆盖零售金融汽车餐饮和制造等行业
您想了解哪个产品呢
1云呼叫中心
2在线客服
3工单系统
4AI语音机器人
5企微SCRM
6其他`// 欢迎语
}
await axios({
method: "post",
url: "https://a2.xiaomilaile.com/local-commonInte/qywxExternal/get_multi_qrcode",
data: data
})
.then(res => {
qrCode = res.data.result.qr_code
})
.catch(err => {
console.log(err)
})
}
/* ............ 点击跳转小程序活码 .............. */
async function toweixin() {
location.href = "https://work.weixin.qq.com/ca/cawcdec1a0cc0f1141";
// let accessToken = await getAccessToken()
// const data = {
// account: "N000000001907",
// access_token: accessToken,
// id: "32462733-4f95-492b-8f58-5fc498ecca35",
// website_keywords: website_keywords_string, //媒体摘要 包含计划 单元 关键词
// website_url: website_url, //原始链接
// website_promotion_media: website_promotion_media, //推广媒体 如 百度SEM baidu,sem
// website_contact_channel: website_contact_channel, //联络渠道 如企业微信 wxwork
// website_landing_page_type: website_landing_page_type, //落地页 website,hollycrm
// processLevel: "undefined,undefined"// 客户分级
// }
// let param = new URLSearchParams()
// param.append("source", JSON.stringify(data))
// axios
// .post("/api/weixin/to_weixin.php", param)
// .then(res => {
// if (IsMobile()) {
// window.location.href = res.data
// } else {
// alert("请在手机端打开")
// }
// })
// .catch(error => {
// console.log(error)
// })
}