MonkeyKing 2.2.1

MonkeyKing 2.2.1

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最新发布2021年6月
SPM支持 SPM

nixzhu 维护。



MonkeyKing

MonkeyKing 可帮助您向中国社交网络发布 SNS 消息,无需使用其有缺陷的 SDK。

MonkeyKing 使用与 openshare 相同的分析流程。我们还使用一些逆向工程工具,如 Hopper Disassembler,来揭示一些未经记录的认证机制。它支持将 文本URL图像音频视频文件 分享到 微信QQ支付宝微博。MonkeyKing 也可以通过网页发布微博消息。(注意:音频和视频仅限微信或 QQ,文件仅限 QQ 邮件线)

MonkeyKing 还支持通过微信和支付宝进行 OAuth移动支付

要求

Swift 5, iOS 9

(对于 Swift 4.2,使用版本 1.13.0)

(对于 Swift 4.1/4.0,使用版本 1.11.0)

(对于 Swift 3,使用版本 1.3.0)

示例

分享

例如:分享到微信(微信):

  1. 在项目目标的 Info.plist 中,将 URL 类型LSApplicationQueriesSchemes 设置如下

    一旦您启用了微信应用的全网链接,也应添加 weixinULAPI

  2. 注册账户:// 不必在这里做,但为了方便起见

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        MonkeyKing.regsiterAccount(
            .weChat(
                appID: "xxx",
                appKey: "yyy",
                miniAppID: nil,
                universalLink: nil // FIXME: You have to adopt Universal Link otherwise your app name becomes "Unauthorized App"(未验证应用)...
            )
        )
        return true
    }
  3. 附加以下代码处理回调

    // AppDelegate.swift
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    //func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { // only for iOS 8
        return MonkeyKing.handleOpenURL(url)
    }

    如果您在项目中使用 UIScene,请务必处理用户活动

    // SceneDelegate.swift
    
    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
        MonkeyKing.handleOpenUserActivity(userActivity)
    }
  4. 准备您的信息并让 MonkeyKing 送达

    @IBAction func shareURLToWeChatSession(sender: UIButton) {
    
        MonkeyKing.registerAccount(.weChat(appID: "xxx", appKey: "yyy", miniAppID: nil)) // you can do it here (just before deliver)
    
        let message = MonkeyKing.Message.weChat(.session(info: (
            title: "Session",
            description: "Hello Session",
            thumbnail: UIImage(named: "rabbit"),
            media: .url(URL(string: "http://www.apple.com/cn")!)
        )))
    
        MonkeyKing.deliver(message) { success in
            print("shareURLToWeChatSession success: \(success)")
        }
    }

完成!

OAuth

例如:微博 OAuth

MonkeyKing.oauth(for: .weibo) { (oauthInfo, response, error) -> Void in
    print("OAuthInfo \(oauthInfo) error \(error)")
    // Now, you can use the token to fetch info.
}

或者,仅使用代码的微信 OAuth

MonkeyKing.weChatOAuthForCode { [weak self] (code, error) in
    guard let code = code else {
        return
    }
    // TODO: fetch info with code
}

如果用户设备上没有安装微博应用,MonkeyKing 将使用网页 OAuth

支付

例如:支付宝

let order = MonkeyKing.Order.alipay(urlString: urlString, scheme: nil)
MonkeyKing.deliver(order) { result in
    print("result: \(result)")
}

您需要在远程服务器上配置 pay.php。在示例项目中可以找到 pay.php 的示例。


打开微信小程序

let path = "..."
MonkeyKing.launch(.weChat(.miniApp(username: "gh_XXX", path: path, type: .release))) { result in
    switch result {
    case .success:
        break
    case .failure(let error):
        print("error:", error)
    }
}

注意,username 前有一个 gh_ 前缀(原始ID)。

更多

如果您想使用 UIActivityViewController 来分享,MonkeyKing 提供了 AnyActivity 可帮助您。

查看示例获取更多信息。

安装

Carthage

github "nixzhu/MonkeyKing"

CocoaPods

pod 'MonkeyKing'

Swift 包管理器

https://github.com/nixzhu/MonkeyKing

贡献者

感谢所有 贡献者

致谢

来自 Ray 的 WeChat-Logo 的微信图标。

许可协议

MonkeyKing遵从MIT许可协议。更多信息请参阅LICENSE文件。