| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- 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);
- }
- }
- });
|