<html>
<head>
<title>2021,送你一张船票</title>
<meta charset='utf-8' />
<meta name='renderer' content='webkit' />
<meta name='viewport' content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no' />
<meta name='apple-mobile-web-app-capable' content='yes' />
<meta name='full-screen' content='true' />
<meta name='x5-fullscreen' content='true' />
<meta name='360-fullscreen' content='true' />
<meta name='laya' screenorientation='landscape' />
<meta http-equiv='expires' content='0' />
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1' />
<meta http-equiv='expires' content='0' />
<meta http-equiv='Cache-Control' content='no-siteapp' />
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script src="./jquery.min.js"></script>
<script>
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?58795bfa09586309acb736645bd22ea9";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<style>
body {
/* background: url(./snow.jpg) repeat;
background-size: 40px 40px; */
background: black;
}
</style>
</head>
<body>
<div id="code"></div>
<audio src="./sound/bgm1.mp3" autoplay loop id="audio" style="display:none; height: 0" preload="auto"></audio>
<script type="text/javascript">
$(document).ready(function () {
var nn = JSON.parse(localStorage.getItem('wxuserinfo')) || {};
appendNode({
nickname: "新华社用户",
headImgUrl: "./icon_xhs.png"
});
if (location.href.indexOf('h5.zhongguowangshi.com') > -1) {
if (isWeiXin()) {
getShareData()
}
if (!!nn.nickname) {
appendNode(nn);
} else {
wxLogin(appendNode);
}
}
});
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
function appendNode(data) {
console.log(data)
window['wxUserInfo'] = data || {}
window['nickName'] = data.nickname
window['headImgUrl'] = data.headImgUrl
}
function setWXShareConfig(data) {
wx.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData']
});
wx.ready(function () {
wx.updateAppMessageShareData({
title: "送你一张船票",
desc: "一张船票,穿越百年",
link: 'https://h5.zhongguowangshi.com/h5/2020/chuanpiao/index.html',
imgUrl: "https://h5.zhongguowangshi.com/h5/2020/chuanpiao/share_icon.png",
error: function () {},
success() {}
});
wx.updateTimelineShareData({
title: "2021,送你一张船票",
desc: "2021,送你一张船票",
link: 'https://h5.zhongguowangshi.com/h5/2020/chuanpiao/index.html',
imgUrl: "https://h5.zhongguowangshi.com/h5/2020/chuanpiao/share_icon.png",
error: function () {},
success() {}
});
});
}
//判断是否是微信浏览器的函数
function isWeiXin() {
//window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息,这个属性可以用来判断浏览器类型
var ua = window.navigator.userAgent.toLowerCase();
//通过正则表达式匹配ua中是否含有MicroMessenger字符串
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
return true;
} else {
return false;
}
}
function getShareData() {
var get_weixinConfig = 'https://open.xhsxmt.com/wx/getWXConfig?url=' + encodeURIComponent(location.href.split('#')[0]);
$.ajax({
type: 'GET',
url: get_weixinConfig,
dataType: 'json',
success: function (res) {
var result = JSON.parse(res);
var data = result.data;
console.log('分享配置返回')
console.log(result)
if (result.rc === 0) {
console.log('接口成功,设置分享')
setWXShareConfig(data);
}
},
error: function (error) {
// throw new Error(error)
}
})
}
function wxLogin(callback) {
var appId = 'wx677fa1c6d5066c19';
var oauth_url = 'https://open.xhsxmt.com/wx/getUserInfo';
var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=" + location.href.split('#')[0] +
"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
if (!isWeiXin()) {
callback({
nickname: "新华社用户",
headImgUrl: "./icon_xhs.png"
});
return
}
var code = getUrlParam("code");
if (!code) {
window.location.replace(url)
} else {
$.ajax({
type: 'GET',
url: oauth_url,
dataType: 'json',
data: {
code: code
},
success: function (res) {
var result = JSON.parse(res);
var data = result.data;
if (result.rc === 0) {
localStorage.setItem('wxuserinfo', JSON.stringify(data));
callback(data);
}
},
error: function (error) {
// throw new Error(error)
}
});
}
}
</script>
<script type="text/javascript">
function audioAutoPlay(id) {
var audio = document.getElementById(id);
var play = function () {
document.removeEventListener("WeixinJSBridgeReady", play);
document.removeEventListener("YixinJSBridgeReady", play);
audio.pause();
audio.play();
document.removeEventListener("touchstart", play, false);
};
audio.pause();
audio.play();
//weixin
document.addEventListener("WeixinJSBridgeReady", play, false);
//yixin
document.addEventListener('YixinJSBridgeReady', play, false);
document.addEventListener("touchstart", play, false);
}
audioAutoPlay('audio')
function loadLib(url) {
var script = document.createElement("script");
评论1