|
|
@@ -1,5 +1,6 @@
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="zh-CN">
|
|
|
+
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
|
@@ -15,24 +16,33 @@
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
+
|
|
|
<body class="p-4 flex flex-col min-h-screen">
|
|
|
-
|
|
|
+
|
|
|
<div class="text-center mb-8 mt-4">
|
|
|
<div class="inline-block p-3 rounded-full bg-indigo-100 text-indigo-600 mb-3">
|
|
|
- <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="6" width="20" height="12" rx="2"/><path d="M6 12h4"/><path d="M8 10v4"/><path d="M15 13h.01"/><path d="M18 11h.01"/></svg>
|
|
|
+ <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none"
|
|
|
+ stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
+ <rect x="2" y="6" width="20" height="12" rx="2" />
|
|
|
+ <path d="M6 12h4" />
|
|
|
+ <path d="M8 10v4" />
|
|
|
+ <path d="M15 13h.01" />
|
|
|
+ <path d="M18 11h.01" />
|
|
|
+ </svg>
|
|
|
</div>
|
|
|
<h1 class="text-2xl font-bold text-slate-800">异界修仙传 H5</h1>
|
|
|
<p class="text-slate-500 text-sm mt-1">游戏客户端 (Iframe内)</p>
|
|
|
</div>
|
|
|
|
|
|
<div class="space-y-4 flex-1">
|
|
|
-
|
|
|
+
|
|
|
<!-- 初始化模块 -->
|
|
|
<div class="bg-white p-5 rounded-2xl shadow-sm border border-slate-100">
|
|
|
<div class="flex justify-between items-center mb-3">
|
|
|
<h2 class="font-semibold text-slate-700">1. 初始化模块</h2>
|
|
|
</div>
|
|
|
- <button id="btn-init" class="w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-sm shadow-blue-200 active:scale-95 duration-150">
|
|
|
+ <button id="btn-init"
|
|
|
+ class="w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-sm shadow-blue-200 active:scale-95 duration-150">
|
|
|
调用 SDK 初始化
|
|
|
</button>
|
|
|
<div id="init-res" class="mt-3 text-xs text-slate-600 bg-slate-50 p-2 rounded hidden break-all"></div>
|
|
|
@@ -44,7 +54,8 @@
|
|
|
<h2 class="font-semibold text-slate-700">2. 登录模块</h2>
|
|
|
<span id="login-status" class="text-xs px-2 py-1 rounded-full bg-slate-100 text-slate-500">未登录</span>
|
|
|
</div>
|
|
|
- <button id="btn-login" class="w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-sm shadow-blue-200 active:scale-95 duration-150">
|
|
|
+ <button id="btn-login"
|
|
|
+ class="w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-sm shadow-blue-200 active:scale-95 duration-150">
|
|
|
调用 SDK 登录
|
|
|
</button>
|
|
|
<div id="login-res" class="mt-3 text-xs text-slate-600 bg-slate-50 p-2 rounded hidden break-all"></div>
|
|
|
@@ -55,7 +66,8 @@
|
|
|
<div class="flex justify-between items-center mb-3">
|
|
|
<h2 class="font-semibold text-slate-700">3. 支付模块</h2>
|
|
|
</div>
|
|
|
- <button id="btn-pay" class="w-full py-3 bg-emerald-500 hover:bg-emerald-600 text-white rounded-xl font-medium transition-colors shadow-sm shadow-emerald-200 active:scale-95 duration-150">
|
|
|
+ <button id="btn-pay"
|
|
|
+ class="w-full py-3 bg-emerald-500 hover:bg-emerald-600 text-white rounded-xl font-medium transition-colors shadow-sm shadow-emerald-200 active:scale-95 duration-150">
|
|
|
购买「绝世神兵」(¥99)
|
|
|
</button>
|
|
|
<div id="pay-res" class="mt-3 text-xs text-slate-600 bg-slate-50 p-2 rounded hidden break-all"></div>
|
|
|
@@ -66,18 +78,31 @@
|
|
|
<div class="flex justify-between items-center mb-3">
|
|
|
<h2 class="font-semibold text-slate-700">4. 数据上报</h2>
|
|
|
</div>
|
|
|
- <button id="btn-report" class="w-full py-3 bg-purple-500 hover:bg-purple-600 text-white rounded-xl font-medium transition-colors shadow-sm shadow-purple-200 active:scale-95 duration-150">
|
|
|
+ <button id="btn-report"
|
|
|
+ class="w-full py-3 bg-purple-500 hover:bg-purple-600 text-white rounded-xl font-medium transition-colors shadow-sm shadow-purple-200 active:scale-95 duration-150">
|
|
|
上报「角色升级」事件
|
|
|
</button>
|
|
|
<div id="report-res" class="mt-3 text-xs text-slate-600 bg-slate-50 p-2 rounded hidden break-all"></div>
|
|
|
</div>
|
|
|
|
|
|
+ <!-- 退出登录模块 -->
|
|
|
+ <div class="bg-white p-5 rounded-2xl shadow-sm border border-slate-100">
|
|
|
+ <div class="flex justify-between items-center mb-3">
|
|
|
+ <h2 class="font-semibold text-slate-700">5. 退出登录</h2>
|
|
|
+ </div>
|
|
|
+ <button id="btn-logout"
|
|
|
+ class="w-full py-3 bg-red-500 hover:bg-red-600 text-white rounded-xl font-medium transition-colors shadow-sm shadow-red-200 active:scale-95 duration-150">
|
|
|
+ 退出登录
|
|
|
+ </button>
|
|
|
+ <div id="logout-res" class="mt-3 text-xs text-slate-600 bg-slate-50 p-2 rounded hidden break-all"></div>
|
|
|
+ </div>
|
|
|
+
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
// 绑定事件到 GameSDK
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
-
|
|
|
+
|
|
|
const setLog = (id, result, isError = false) => {
|
|
|
const el = document.getElementById(id);
|
|
|
el.classList.remove('hidden');
|
|
|
@@ -90,11 +115,11 @@
|
|
|
const btn = document.getElementById('btn-init');
|
|
|
btn.disabled = true;
|
|
|
btn.innerHTML = '初始化中...';
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 调用全局注入的 GameSDK,返回 Promise 并等待
|
|
|
- const result = await GameSDK.init({version:'1.0.0'});
|
|
|
-
|
|
|
+ const result = await GameSDK.init({ version: '1.0.0' });
|
|
|
+
|
|
|
setLog('init-res', result);
|
|
|
btn.innerHTML = '初始化成功';
|
|
|
btn.className = 'w-full py-3 bg-emerald-600 hover:bg-emerald-700 text-white rounded-xl font-medium transition-colors shadow-sm shadow-emerald-200 active:scale-95 duration-150';
|
|
|
@@ -111,11 +136,11 @@
|
|
|
const status = document.getElementById('login-status');
|
|
|
btn.disabled = true;
|
|
|
btn.innerHTML = '登录中...';
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 调用全局注入的 GameSDK,返回 Promise 并等待
|
|
|
const result = await GameSDK.login();
|
|
|
-
|
|
|
+
|
|
|
setLog('login-res', result);
|
|
|
status.textContent = '已登录';
|
|
|
status.className = 'text-xs px-2 py-1 rounded-full bg-emerald-100 text-emerald-600 font-medium';
|
|
|
@@ -134,21 +159,21 @@
|
|
|
const originalText = btn.innerHTML;
|
|
|
btn.disabled = true;
|
|
|
btn.innerHTML = '支付中...';
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
const result = await GameSDK.pay({
|
|
|
- cp_order_id:String(new Date().getTime()/1000),
|
|
|
- server_id:'1',
|
|
|
+ cp_order_id: String(new Date().getTime() / 1000),
|
|
|
+ server_id: '1',
|
|
|
server_name: '服务器1',
|
|
|
- role_id:'1000001',
|
|
|
- role_name:'角色1',
|
|
|
- money:'1', // 元
|
|
|
- product_id:'1',
|
|
|
- product_name:'商品1',
|
|
|
- ext:'11111111'
|
|
|
+ role_id: '1000001',
|
|
|
+ role_name: '角色1',
|
|
|
+ money: '1', // 元
|
|
|
+ product_id: '1',
|
|
|
+ product_name: '商品1',
|
|
|
+ ext: '11111111'
|
|
|
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
setLog('pay-res', result);
|
|
|
} catch (error) {
|
|
|
setLog('pay-res', error.message, true);
|
|
|
@@ -164,17 +189,17 @@
|
|
|
const originalText = btn.innerHTML;
|
|
|
btn.disabled = true;
|
|
|
btn.innerHTML = '上报中...';
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
const result = await GameSDK.report({
|
|
|
- data_type: '1',
|
|
|
- server_id: '1',
|
|
|
+ data_type: 1,
|
|
|
+ server_id: 2002,
|
|
|
server_name: '服务器1',
|
|
|
role_id: '1000001',
|
|
|
role_name: '角色1',
|
|
|
role_level: '1'
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
setLog('report-res', result);
|
|
|
} catch (error) {
|
|
|
setLog('report-res', error.message, true);
|
|
|
@@ -183,29 +208,56 @@
|
|
|
btn.innerHTML = originalText;
|
|
|
}
|
|
|
});
|
|
|
+ // 4. 退出登录
|
|
|
+ document.getElementById('btn-logout').addEventListener('click', async () => {
|
|
|
+ const btn = document.getElementById('btn-logout');
|
|
|
+ const originalText = btn.innerHTML;
|
|
|
+ btn.disabled = true;
|
|
|
+ btn.innerHTML = '退出登录中...';
|
|
|
+
|
|
|
+ try {
|
|
|
+ const result = await GameSDK.logout();
|
|
|
+ if (result.success) {
|
|
|
+ GameSDK.init({ version: '1.0.0' })
|
|
|
+ GameSDK.login()
|
|
|
+ }
|
|
|
+ setLog('logout-res', result);
|
|
|
+ } catch (error) {
|
|
|
+ setLog('logout-res', error.message, true);
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
|
|
|
// 监听来自 SDK 的消息(使用封装好的 onLogout 方法)
|
|
|
- GameSDK.onLogout(() => {
|
|
|
- const btn = document.getElementById('btn-login');
|
|
|
- const status = document.getElementById('login-status');
|
|
|
- const resLog = document.getElementById('login-res');
|
|
|
-
|
|
|
- // 重置登录按钮和状态
|
|
|
- btn.disabled = false;
|
|
|
- btn.innerHTML = '调用 SDK 登录';
|
|
|
- btn.className = 'w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-sm shadow-blue-200 active:scale-95 duration-150';
|
|
|
-
|
|
|
- status.textContent = '未登录';
|
|
|
- status.className = 'text-xs px-2 py-1 rounded-full bg-slate-100 text-slate-500';
|
|
|
-
|
|
|
- // 隐藏/清除日志
|
|
|
- resLog.classList.add('hidden');
|
|
|
- resLog.textContent = '';
|
|
|
-
|
|
|
- console.log('游戏收到通知 (通过 GameSDK.onLogout):退出登录成功,已重置 UI');
|
|
|
- });
|
|
|
+ GameSDK.onLogout().then(res => {
|
|
|
+ if (res.success) {
|
|
|
+
|
|
|
+ const btn = document.getElementById('btn-login');
|
|
|
+ const status = document.getElementById('login-status');
|
|
|
+ const resLog = document.getElementById('login-res');
|
|
|
+
|
|
|
+ // 重置登录按钮和状态
|
|
|
+ btn.disabled = false;
|
|
|
+ btn.innerHTML = '调用 SDK 登录';
|
|
|
+ btn.className = 'w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-sm shadow-blue-200 active:scale-95 duration-150';
|
|
|
+
|
|
|
+ status.textContent = '未登录';
|
|
|
+ status.className = 'text-xs px-2 py-1 rounded-full bg-slate-100 text-slate-500';
|
|
|
+
|
|
|
+ // 隐藏/清除日志
|
|
|
+ resLog.classList.add('hidden');
|
|
|
+ resLog.textContent = '';
|
|
|
+
|
|
|
+ console.log('游戏收到通知 (通过 GameSDK.onLogout):退出登录成功,已重置 UI');
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
</script>
|
|
|
</body>
|
|
|
-</html>
|
|
|
+
|
|
|
+</html>
|