<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>sdk test</title>
<style>
div {
width: 100px;
margin-bottom: 10px;
padding: 10px 15px;
border: 1px solid;
border-radius: 10px;
}
.userInfo {
display: flex;
flex-wrap: wrap;
align-items: center;
margin-bottom: 10px;
}
.avatar {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 10px;
}
span {
margin-right: 10px;
}
</style>
</head>
<body>
<section class="userInfo"> </section>
<div class="login">login</div>
<div class="getUserInfo">获取APP用户信息</div>
<div class="openh5">open h5</div>
<div class="openwebh5">外部浏览器打开 h5 页面</div>
<div class="openShop">打开商城页面(只对Android有效)</div>
<div class="share">share</div>
<div class="close">close</div>
<script src="https://s0.ssl.qhres2.com/!0da0d140/theme/js/jquery-2.1.4.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/eruda"></script>
<!-- 引入 SDK -->
<script src="https://s0.ssl.qhres2.com/!3cdf87fe/wgappsdk.min.js"></script>
<script>
eruda.init();
// 给 webview 添加标题
wgappsdk.callNative('showTitle', { title: 'wgappsdk' })
document.querySelector('.login').addEventListener('click', async () => {
// 唤起 APP 原生登录框
wgappsdk.callNative('jumpToLogin');
})
document.querySelector('.getUserInfo').addEventListener('click', async () => {
getUserInfo()
})
document.querySelector('.close').addEventListener('click', async () => {
// 关闭 webview 页面
wgappsdk.callNative('finishWeb');
})
document.querySelector('.openh5').addEventListener('click', async () => {
// 通过 APP 打开页面
wgappsdk.callNative('jumpToUi', { jump_type: 'openclient', jump_data: 'wotbox://client/webview?isFullScreen=1&url=https%3A%2F%2Fzs.wows.360.cn%2Fmatrix_ship_test.html%23%2FpostDetail%2F1340' });
})
document.querySelector('.openwebh5').addEventListener('click', async () => {
// 通过 APP 打开外部浏览器
wgappsdk.callNative('jumpToUi', { jump_type: 'openbrowser', jump_data: 'https://beta.wot.360.cn/m/wci/2023/tickets/' });
})
document.querySelector('.openShop').addEventListener('click', async () => {
// 打开安卓 APP 商城
wgappsdk.callNative('jumpToUi', { jump_type: 'openclient', jump_data: 'wows://client/mainactivity?tab=0&child_tab=2' });
})
document.querySelector('.share').addEventListener('click', async () => {
// 唤起 APP 原生分享功能
wgappsdk.callNative('jumpToShare', { type: 'url', title: '战舰助手APP SDK 测试', desc: '测试测试testesttesttest', url: location.href, iconUrl: "https://s3.ssl.qhres2.com/static/a85197ff4c92dd7e.ico", });
})
// 设置 APP 头部图表颜色和按钮是否显示
wgappsdk.callNative('titleBarStyleMotify', {
icon_is_white: '0',
right_icon: {
show_share_icon: '1',
show_search_icon: '1'
}
});
getUserInfo()
// 获取当前APP用户信息
async function getUserInfo() {
const res = await wgappsdk.callNative('getAppUserInfo');
const userRes = JSON.parse(res)
if (userRes.errno === 0 && userRes.data) {
const userInfo = userRes.data;
$('.userInfo').html(`
<img src="${userInfo.user_info.face_url}" class="avatar">
<span class="username">${userInfo.currentUserInfo.nickname || userInfo.user_info.user_name || userInfo.user_info.nick_name}</span>
<p>军团:<span style="color: ${userInfo.currentUserInfo.clan_color}">[${userInfo.currentUserInfo.clan_tag}]</span>-${userInfo.currentUserInfo.clan_name}</p>
<span>军团ID:${userInfo.currentUserInfo.clan_id}</span>
<span>wg_id:${userInfo.currentUserInfo.wg_id}</span>
<span>qid:${userInfo.currentUserInfo.qid}</span>
`)
} else {
wgappsdk.callNative('jumpToLogin');
}
}
</script>
</body>
</html>