Files
youle_app_ios_v2/ylgamehall/Source/Bridge/Handlers/AccreditLoginHandler.swift
T
joywayerandClaude Opus 4.7 05f1396645 微信 SDK 降级 2.0.5 → 1.8.2(与 daoqi msext 同款,避开 UL 强制)
H5 调 accreditlogin 后 sendAuthReq success=false,根因:微信 OpenSDK
2.0.x 强制 Universal Link,传空串被 SDK 拒绝;daoqi msext 用 1.8.x 不强制
UL,多年稳定上线。沿用 1.8.2 避免无谓的 UL 运维负担(HTTPS 域名 + AASA +
微信开放平台审核 30min-1d)。

文件改动:
- 新增 Vendor/WechatSDK/v1.8.2/{WXApi,WXApiObject,WechatAuthSDK}.h +
  libWeChatSDK.a(16MB,fat: i386+armv7+armv7s+x86_64+arm64,从 daoqi
  msext/Class/SDKExport/ 直接拷贝)
- 删除 Vendor/WechatSDK/WechatOpenSDK-NoPay.xcframework(2.0.5)
- 新增 ylgamehall/ylgamehall-Bridging-Header.h(1.x .a 无 Swift module,
  必须通过 Bridging Header 导入 WXApi.h / WXApiObject.h)

代码侧(5 个 Swift 文件):
- WeChatSDK.swift:register() 改为 1.x 单参数 WXApi.registerApp(appID),
  去掉 universalLink 参数;handleOpenURL 不变(1.x/2.x 同款)
- WeChatManager.swift:去掉 #if canImport(WechatOpenSDK) 守卫(Bridging
  Header 直接导入,符号编译期必在);authorize sendAuthReq 改 1.x BOOL
  返回(无 completion);shareLink/shareImage 改 WXApi.sendReq(req)
  (1.x BOOL 返回,无 completion);getVersion → getApiVersion
- AccreditLoginHandler / WechatShare:同样去掉 canImport 守卫和 stub 分支
- BackGameDataHandler:更新注释说明 1.x WXApi delegate 由 sendAuthReq
  逐次传入,WeChatManager singleton 持有不需要清理(1.x 早期 setDelegate:
  API 已废弃)

文档:
- Vendor/WechatSDK/README.md 重写,说明 1.8.2 决策原因 + 文件结构 +
  Xcode 接入 5 步 + M Mac simulator 已知限制
- docs/SDK-Integration-Guide.md §A.1 同步重写

⚠️ **本 commit 后 BuildProject 会失败**,需要用户在 Xcode UI 完成 5 步:
1. 删 Frameworks 里旧 WechatOpenSDK-NoPay.xcframework 引用
2. Add Vendor/WechatSDK/v1.8.2/libWeChatSDK.a(Do Not Embed)
3. Add 4 个系统库:libz.tbd / libsqlite3.tbd / Security.framework /
   CFNetwork.framework(Do Not Embed)
4. Build Settings → Header Search Paths += $(PROJECT_DIR)/Vendor/WechatSDK/v1.8.2
5. Build Settings → Objective-C Bridging Header = ylgamehall/ylgamehall-Bridging-Header.h

详细操作步骤见 Vendor/WechatSDK/README.md「Xcode 接入步骤」。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-23 08:27:40 +08:00

53 lines
2.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// AccreditLoginHandler.swift
// ylgamehall
//
// H5 → Native handleraccreditlogin — 微信授权登录
// 契约:docs/H5-Native-Contract.md §3.1 1 + §3.2 10sharelogin
//
// 完整链路(Phase 4.E):
// 1. WeChatAuth.authorize() → 拉起微信授权 + 客户端直拼 oauth2 + userinfo
// (msext NewRootVC.m:2415-2428 等价路径,沿用 AppID/AppSecret/scope)
// 2. bridge.call("sharelogin", data: 7 字段) 反向 callback
// 字段名严格 1:1 含历史包袱:`Province` 大写 P / `city` 经 danbian 去单引号
//
// ⚠️ canImport(WechatOpenSDK) 守卫:SDK 未链接前走 stub(与 Phase 4.A 一致),
// 仅响应 callback 不触发 sharelogin;项目方在 Xcode Embed & Sign 后真实路径激活。
//
import Foundation
public enum AccreditLoginHandler {
public static func register(on bridge: any BridgeProtocol) {
bridge.register("accreditlogin") { _, callback in
print("[Bridge] accreditlogin H5 调用命中 ✅")
callback?(.string("Response from accreditlogin"))
// 拉起微信授权 → 拿 7 字段 → 反向 callback sharelogin
Task { @MainActor in
do {
let user = try await WeChatAuth.authorize()
print("[Bridge] accreditlogin 拿到 user,发 sharelogin 反向 callback")
bridge.call("sharelogin", data: .object([
// 字段名严格 1:1 contract §3.2 表 [10] / msext NewRootVC.m:2428
"openid": .string(user.openid),
"headimgurl": .string(user.headimgurl),
"nickname": .string(user.nickname),
"sex": .number(Double(user.sex)),
"city": .string(user.city),
"Province": .string(user.Province), // ← 大写 P
"unionid": .string(user.unionid)
]), callback: nil)
} catch WeChatAuthError.userCancelled {
print("[Bridge] accreditlogin 用户取消授权(errCode -2")
// msext 行为:用户取消不弹 alert、不触发 sharelogin
} catch {
print("[Bridge] accreditlogin 失败:\(error)")
// 其它失败也吞下(msext 同款乐观策略:不反向通知 H5)
}
}
}
}
}