4.B FriendsShareHandler 加调试日志:原始 JSON + 解析字段 + 分发 mode

H5 调用分享接口时,按以下顺序输出到 Console(subsystem=ylgamehall,
category=FriendsShare):

  ← H5 friendsShare mode=lobby raw={"sharefriend":"1",...}
  friendsShare parsed:
    sharefriend = "1"  (1=好友/SharePanel, 2/其他=朋友圈)
    sharetype   = "1"  (1/2=微信, 3=闲聊;新外壳忽略)
    type        = "1"  (1=链接, 2=截图, 其他=远端图)
    webpageUrl  = "https://..."
    title       = "..."
    description = "..."
  → H5 sharesuccess fired: success="2", type="1"
  dispatch → lobby (直发微信 3 type 分支)

raw 字段直接 JSONSerialization 序列化整个 BridgeData,含 H5 传入的所有
键(不限于上面解析的 6 项),便于排查 H5 端偷偷加字段或类型漂移。
This commit is contained in:
joywayer
2026-06-24 09:07:36 +08:00
parent 5d4bdc2e29
commit a1332ed942
@@ -21,10 +21,13 @@
// //
import Foundation import Foundation
import os.log
@MainActor @MainActor
public enum FriendsShareHandler { public enum FriendsShareHandler {
private static let log = Logger(subsystem: "ylgamehall", category: "FriendsShare")
/// mode /// mode
public enum Mode: Sendable { public enum Mode: Sendable {
/// H5 WebContainer friendsShare /// H5 WebContainer friendsShare
@@ -42,7 +45,14 @@ public enum FriendsShareHandler {
// 1. responseCallback msext "sharefriend" // 1. responseCallback msext "sharefriend"
callback?(.string("sharefriend")) callback?(.string("sharefriend"))
guard let obj = data?.asObject else { return } await MainActor.run {
// 0. H5 JSON便 H5
Self.log.debug("← H5 friendsShare mode=\(String(describing: mode), privacy: .public) raw=\(Self.describe(data), privacy: .public)")
guard let obj = data?.asObject else {
Self.log.error("friendsShare: data 不是 object,跳过分发")
return
}
let content = ShareContent( let content = ShareContent(
// ShareCenter default msext [nil intValue]==0 // ShareCenter default msext [nil intValue]==0
sharefriend: obj["sharefriend"]?.asString ?? "", sharefriend: obj["sharefriend"]?.asString ?? "",
@@ -53,7 +63,17 @@ public enum FriendsShareHandler {
desc: obj["description"]?.asString ?? "" desc: obj["description"]?.asString ?? ""
) )
await MainActor.run { // ShareContent 便
Self.log.debug("""
friendsShare parsed:
sharefriend = "\(content.sharefriend, privacy: .public)" (1=好友/SharePanel, 2/其他=朋友圈)
sharetype = "\(content.sharetype, privacy: .public)" (1/2=微信, 3=闲聊;新外壳忽略)
type = "\(content.type, privacy: .public)" (1=链接, 2=截图, 其他=远端图)
webpageUrl = "\(content.webpageUrl, privacy: .public)"
title = "\(content.title, privacy: .public)"
description = "\(content.desc, privacy: .public)"
""")
// 2. sharesuccess // 2. sharesuccess
bridge?.call( bridge?.call(
"sharesuccess", "sharesuccess",
@@ -63,13 +83,32 @@ public enum FriendsShareHandler {
]), ]),
callback: nil callback: nil
) )
Self.log.debug("→ H5 sharesuccess fired: success=\"2\", type=\"\(content.sharefriend, privacy: .public)\"")
// 3. fire-and-forget UI mode // 3. fire-and-forget UI mode
switch mode { switch mode {
case .lobby: ShareCenter.dispatchLobby(content) case .lobby:
case .subGame: ShareCenter.dispatchSubGame(content) Self.log.debug("dispatch → lobby (直发微信 3 type 分支)")
ShareCenter.dispatchLobby(content)
case .subGame:
Self.log.debug("dispatch → subGame (SharePanel 或朋友圈兜底)")
ShareCenter.dispatchSubGame(content)
} }
} }
} }
} }
/// BridgeData JSON 便 H5
/// 6 H5
private static func describe(_ data: BridgeData?) -> String {
guard let data else { return "<nil>" }
let raw = data.jsonObject
if let bytes = try? JSONSerialization.data(
withJSONObject: raw,
options: [.fragmentsAllowed, .sortedKeys]
), let s = String(data: bytes, encoding: .utf8) {
return s
}
return String(describing: raw)
}
} }