import { init, loginUserInfo, login, dataReport, makePayment, shareAppMessage, addShortcut, checkShortcut, onShareAppMessage, navigateToScene, openCustomerServiceConversation, requestFeedSubscribe, checkFeedSubscribeStatus, reportScene, getFeedLaunchParams } from "index"; // from './dist/dyMiniGameSdk.1.0.0.js' // 初始化skd (async () => { try { let data = { app_version: "1.0.0", config_id: "tta0dbd6663eb8fad902", game_name: "暮影战神", }; // 静默授权 const res = await init(data); console.log("初始化") console.log(res); tt.showToast({ title: "进入游戏成功", }); } catch (error) { console.log(error); } })(); // 下单 const handleMakePayment = async () => { try { let info = { amt: 1, server_id: 1, server_name: "测试1服", role_id: "10000111", role_name: "小林", role_level: 1, ext: "aaaaaaa", product_id: "001", product_name: "测试商品", }; makePayment(info) .then((res) => { console.log("支付调用结果:", res); }) .catch((error) => { console.log(error); }); } catch (error) { console.log("支付调用结果error:", error); } }; //角色上报按钮 const handleDataReport = async () => { try { let info = { data_type: 2, server_id: 1, server_name: "测试1服", role_id: "10000111", role_name: "小林", role_level: 1, role_currency: 1000, }; const res = await dataReport(info); tt.showToast({ title: "角色上报成功", }); console.log("角色上报") console.log(res); } catch (error) { console.log(error); } }; /** * 2025年05月06日 * 新增登陆方法 */ const handleLogin = async ()=>{ try { const res = await login(); console.log("登录") console.log(res); tt.showToast({ title: "获取成功", }); } catch (error) { console.log(error); } } //获取平台登录用户信息 const handleLoginUserInfo = async () => { try { const res = await loginUserInfo(); console.log(res); tt.showToast({ title: "获取成功", }); } catch (error) { console.log(error); } }; //主动分享 const handleShareAppMessage = async () => { try { let info = { title: "分享测试", imageUrl: "https://app.hainanruiyu.com/hd/img/632-2.jpg", ext: "&ceshi=linquan321", channel: "", templateId: "", }; await shareAppMessage(info); tt.showToast({ title: "分享成功", }); } catch (error) { console.log(error); } }; //主动监听 const handleOnShareAppMessage = () => { onShareAppMessage({ title: "测试", imageUrl: "https://app.hainanruiyu.com/hd/img/632-2.jpg", ext: "&ceshi=test", }); }; // 将小游戏快捷方式添加到手机桌面上 const handleAddShortcut = async () => { checkShortcut() .then((res) => { console.log("+++++++++++++++++++++++checkShortcut_res", res); }) .catch((error) => { console.log(error); }); }; // 侧边栏能力 const handleNavigateToScene = async () => { navigateToScene() .then((res) => { console.log("navigateToScene then res:", res); }) .catch((error) => { console.log(error); }); }; // IM客服能力 const handleService = async () => { openCustomerServiceConversation() .then((res) => { console.log("openCustomerServiceConversation then res:", res); }) .catch((error) => { console.log(error); }); }; // 请求推荐流直出订阅 const handleRequestFeedSubscribe = async () => { requestFeedSubscribe({ scene: 3}) .then((res) => { console.log("cp调用【请求推荐流直出订阅】res: ", res); }) .catch((error) => { console.log(error); }); } // 检查推荐流直出订阅状态 const handleCheckFeedSubscribeStatus = async () => { checkFeedSubscribeStatus({ scene: 3 }) .then((res) => { console.log("checkFeedSubscribeStatus then res:", res); }) .catch((error) => { console.log(error); }); } reportScene() getFeedLaunchParams().then(res=>{ console.log("CP调用启动参数res:", res) }) // =================== 按钮功能 UI function newButtonMap(name, callback, x, y, w = 200, h = 30) { return { name: name, callback: callback, x: x, y: y, w: w, h: h, }; } let buttonList = [ newButtonMap("登陆", handleLogin, 10, 150), newButtonMap("获取平台登陆用户信息", handleLoginUserInfo, 10, 200), newButtonMap("上报用户角色", handleDataReport, 10, 250), newButtonMap("生成1元订单", handleMakePayment, 10, 300), newButtonMap("主动分享", handleShareAppMessage, 10, 350), newButtonMap("监听分享传参", handleOnShareAppMessage, 10, 400), newButtonMap("添加到桌面", handleAddShortcut, 10, 450), newButtonMap("侧边栏能力", handleNavigateToScene, 10, 500), newButtonMap("IM客服能力", handleService, 10, 550), newButtonMap("请求推荐流直出订阅", handleRequestFeedSubscribe, 10, 600), newButtonMap("检查推荐流直出订阅状态", handleCheckFeedSubscribeStatus, 10, 650), // newButtonMap("监听推荐流直出订阅状态变化", handleOnFeedStatusChange, 10, 700), // newButtonMap("取消监听推荐流直出订阅状态变化", handleOffFeedStatusChange, 10, 750), // newButtonMap("存储推荐流直出订阅数据", handleStoreFeedData, 10, 800), // newButtonMap("获取游戏是否直玩就绪状态数据", handleGetFeedData, 10, 850), ]; const canvas = tt.createCanvas(); const ctx = canvas.getContext("2d"); ctx.fillStyle = "#ff0000"; ctx.font = "14px Arial"; ctx.strokeStyle = "#ff0000"; for (let k in buttonList) { ctx.fillText(buttonList[k].name, 20, buttonList[k].y + 20); } tt.onTouchEnd(function (a) { let cur = a.changedTouches[0]; for (let k in buttonList) { if ( cur.clientX >= buttonList[k].x && cur.clientX <= buttonList[k].x + buttonList[k].w && cur.clientY >= buttonList[k].y && cur.clientY <= buttonList[k].y + buttonList[k].h ) { buttonList[k].callback.call(this); } } });