import { init, authLogin, share, onShareAppMessage, reportRole, payment, getCurrentUserInfo, safeTextCheck } from "./dist/wxxyx-sdk.1.0.0.js" // 初始化skd (async () => { try { let data = { version: "1.0.1", // 游戏版本 mini_program_id: "wx0cc61b77db2c5e2d", //小游戏APPID game_id: "101", // 游戏id game_name: "测试游戏", // 游戏名称 }; // 静默授权 const res = await init(data); console.log("init", res); wx.showToast({ title: "进入游戏成功", }); } catch (error) { } })(); const handleLogin = async () => { const res = await authLogin() console.log("登录返回", res) } // 角色上报 const handleRoleDataReport = async () => { const res = await reportRole({ data_type: 4, server_id: 1, server_name: "仙侠幻世1服", role_id: "90980001", role_name: "仙剑奇侠", role_level: 2, }) console.log("reportRole", res); } //主动分享 const handleShareAppMessage = async () => { try { let info = { title: "分享测试", imageUrl: "https://apxxx.com/1.jpg", ext: "&a=1", }; await share(info); wx.showToast({ title: "分享成功", }); } catch (error) { console.log(error); } }; //主动监听 const handleOnShareAppMessage = () => { onShareAppMessage({ title: "测试分享监听", imageUrl: "https://apxxx.com/2.jpg", ext: "&a=2", }); }; // 支付 const handleMakePayment = async () => { let params = { money: 1, cp_order_id: new Date().getTime() / 1000, server_id: 1, server_name: "仙侠幻世1服", role_id: "90980001", role_name: "仙剑奇侠", role_level: 1, ext: "ceshi", product_id: "-1", product_name: "1元的大礼包", }; try { await payment(params) } catch (error) { console.log('payment cancel or fail', error) } } // 获取当前用户信息 const handleLoginUserInfo = async () => { const res = await getCurrentUserInfo() console.log("getCurrentUserInfo", res) } // 文本内容安全检测 const handleSecCheckText = async () => { const res = await safeTextCheck({ content: "文本内容", scene: 1 }) console.log(res) } 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, 60), newButtonMap("上报用户角色", handleRoleDataReport, 10, 110), newButtonMap("生成1元订单", handleMakePayment, 10, 160), newButtonMap("主动分享", handleShareAppMessage, 10, 260), newButtonMap("获取平台登陆用户信息", handleLoginUserInfo, 10, 210), newButtonMap("监听分享传参", handleOnShareAppMessage, 10, 310), newButtonMap("文本内容安全检测", handleSecCheckText, 10, 360), ]; const canvas = wx.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); } wx.onTouchStart(function (a) { let cur = a.touches[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(); } } });