iT邦幫忙

2026 iThome 鐵人賽

DAY 25
0
Vibe Coding

上岸用AI,看小白如何從無到有的用Vibe Codeing開發遊戲系列 第 25 篇

Day 25:LINE Developer 平台正式發布與 LIFF 綁定維護 —— ShareTargetPicker 社交裂變行銷

  • 分享至 

  • xImage
  •  

歡迎來到第二十五天!為了讓門市顧客能將自己的「大廳裝飾」或「冰品挑戰高分」分享給 LINE 好友,今天我們要實作 LINE LIFF ShareTargetPicker 社交分享!


1. Cocos Creator TypeScript 呼叫 LIFF 分享功能

// LiffShareManager.ts
import liff from '@line/liff';

export class LiffShareManager {
    public static async shareGameResult(score: number, roomImageUrl: string) {
        if (!liff.isApiAvailable('shareTargetPicker')) {
            console.warn("當前環境不支援 ShareTargetPicker");
            return;
        }

        try {
            const result = await liff.shareTargetPicker([
                {
                    type: "flex",
                    altText: "快來看看我在甜點店打造的夢幻大廳!",
                    contents: {
                        type: "bubble",
                        hero: {
                            type: "image",
                            url: roomImageUrl,
                            size: "full",
                            aspectRatio: "20:13",
                            aspectMode: "cover"
                        },
                        body: {
                            type: "box",
                            layout: "vertical",
                            contents: [
                                { type: "text", text: "🍨 夢幻雪花冰門市", weight: "bold", size: "xl" },
                                { type: "text", text: `我在雪花冰極速挑戰拿下了 ${score} 分!快來挑戰我!`, size: "sm", color: "#666666" }
                            ]
                        },
                        footer: {
                            type: "box",
                            layout: "vertical",
                            contents: [
                                {
                                    type: "button",
                                    action: {
                                        type: "uri",
                                        label: "立即掃碼免費體驗",
                                        uri: "https://liff.line.me/1234567890-AbcdEfgh"
                                    },
                                    style: "primary",
                                    color: "#FF8C00"
                                }
                            ]
                        }
                    }
                }
            ]);

            if (result) {
                console.log("Flex Message 社交分享成功!");
            }
        } catch (error) {
            console.error("分享失敗:", error);
        }
    }
}

💡 鐵人賽小知識:什麼是 LINE LIFF ShareTargetPicker 病毒式裂變行銷?

Tech Tip:傳統網頁分享只能複製網址;而 shareTargetPicker 能讓顧客直接在遊戲內彈出 LINE 好友選單,將漂亮的 Flex Message 卡片 推送給好友或群組。好友點擊卡片就能直接啟動遊戲 LIFF,實現低成本的病毒式裂變行銷!



上一篇
Day 24:金流串接最終注意事項與全鏈路測試 —— 沙盒切換正式環境與 HMAC 防掉單實戰
下一篇
Day 26:Cocos Creator 網頁發布與輕量化打包 —— Asset Bundle 分包、WebP 轉換與 CDN 快取
系列文
上岸用AI,看小白如何從無到有的用Vibe Codeing開發遊戲 共 30 篇
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言