From 663199fe2ff663528b7dee9af5f2af610e10a1cb Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 00:03:10 +0800 Subject: [PATCH 01/15] feat: Wechat.code --- NBus/Classes/Core/Bus.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NBus/Classes/Core/Bus.swift b/NBus/Classes/Core/Bus.swift index 5d192f4..7ef4403 100644 --- a/NBus/Classes/Core/Bus.swift +++ b/NBus/Classes/Core/Bus.swift @@ -155,5 +155,10 @@ extension Bus { public static let accessToken = Bus.OauthInfoKey(rawValue: "com.nuomi1.bus.weibo.accessToken") } + + enum Wechat { + + public static let code = Bus.OauthInfoKey(rawValue: "com.nuomi1.bus.wechat.code") + } } } From 1f74b3afbe974803c1fe0c7d2272e3d6938126e5 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 00:03:33 +0800 Subject: [PATCH 02/15] refactor: Wechat.code --- NBus/Classes/Handler/WechatSDKHandler.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NBus/Classes/Handler/WechatSDKHandler.swift b/NBus/Classes/Handler/WechatSDKHandler.swift index 2959d5a..9b5f73b 100644 --- a/NBus/Classes/Handler/WechatSDKHandler.swift +++ b/NBus/Classes/Handler/WechatSDKHandler.swift @@ -241,7 +241,7 @@ extension WechatSDKHandler { public enum OauthInfoKeys { - public static let code = Bus.OauthInfoKey(rawValue: "com.nuomi1.bus.wechatSDKHandler.code") + public static let code = Bus.OauthInfoKeys.Wechat.code } } From a87e1e1bc4c1e9a71b2fcc41c24ff9b563c7bcbc Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 00:03:51 +0800 Subject: [PATCH 03/15] feat: sha1 --- NBus/Classes/Core/Bus+Helper.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/NBus/Classes/Core/Bus+Helper.swift b/NBus/Classes/Core/Bus+Helper.swift index 422a56a..26a806b 100644 --- a/NBus/Classes/Core/Bus+Helper.swift +++ b/NBus/Classes/Core/Bus+Helper.swift @@ -6,6 +6,7 @@ // Copyright © 2020 nuomi1. All rights reserved. // +import CommonCrypto import Foundation extension Dictionary: BusCompatible {} @@ -30,6 +31,17 @@ extension BusWrapper where Base == String { var base64EncodedString: String? { base.data(using: .utf8)?.base64EncodedString() } + + var sha1: String? { + let data = Data(base.utf8) + + var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH)) + data.withUnsafeBytes { pointer in + _ = CC_SHA1(pointer.baseAddress, CC_LONG(data.count), &digest) + } + + return String(bytes: digest, encoding: .ascii) + } } extension NSObject: BusCompatible {} From 9510adf226bb9ed2763284388400c139ab563c4e Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 00:04:15 +0800 Subject: [PATCH 04/15] feat: WechatHandler --- NBus/Classes/Handler/WechatHandler.swift | 507 +++++++++++++++++++++++ 1 file changed, 507 insertions(+) create mode 100644 NBus/Classes/Handler/WechatHandler.swift diff --git a/NBus/Classes/Handler/WechatHandler.swift b/NBus/Classes/Handler/WechatHandler.swift new file mode 100644 index 0000000..ff35183 --- /dev/null +++ b/NBus/Classes/Handler/WechatHandler.swift @@ -0,0 +1,507 @@ +// +// WechatHandler.swift +// NBus +// +// Created by nuomi1 on 2021/1/27. +// Copyright © 2021 nuomi1. All rights reserved. +// + +import Foundation + +// swiftlint:disable file_length + +public class WechatHandler { + + public let endpoints: [Endpoint] = [ + Endpoints.Wechat.friend, + Endpoints.Wechat.timeline, + Endpoints.Wechat.favorite, + ] + + public let platform: Platform = Platforms.wechat + + public var isInstalled: Bool { + guard let url = URL(string: "weixin://") else { + assertionFailure() + return false + } + + return UIApplication.shared.canOpenURL(url) + } + + private var shareCompletionHandler: Bus.ShareCompletionHandler? + private var oauthCompletionHandler: Bus.OauthCompletionHandler? + + public let appID: String + public let universalLink: URL + + @BusUserDefaults(key: ShareOptionKeys.signToken) + private var signToken: String? + + private var lastMessageData: Data? + + public init(appID: String, universalLink: URL) { + self.appID = appID + self.universalLink = universalLink + } +} + +extension WechatHandler: ShareHandlerType { + + // swiftlint:disable cyclomatic_complexity function_body_length + + public func share( + message: MessageType, + to endpoint: Endpoint, + options: [Bus.ShareOptionKey: Any], + completionHandler: @escaping Bus.ShareCompletionHandler + ) { + guard isInstalled else { + completionHandler(.failure(.missingApplication)) + return + } + + guard canShare(message: message.identifier, to: endpoint) else { + completionHandler(.failure(.unsupportedMessage)) + return + } + + guard + let scene = scene(endpoint) + else { + assertionFailure() + completionHandler(.failure(.invalidParameter)) + return + } + + shareCompletionHandler = completionHandler + + var pasteBoardItems: [String: Any] = [:] + + pasteBoardItems["command"] = "1010" + pasteBoardItems["isAutoResend"] = "0" + pasteBoardItems["result"] = "1" + pasteBoardItems["returnFromApp"] = "0" + pasteBoardItems["scene"] = scene + pasteBoardItems["sdkver"] = sdkVersion + pasteBoardItems["universalLink"] = universalLink.absoluteString + + if let message = message as? MediaMessageType { + pasteBoardItems["title"] = message.title + pasteBoardItems["description"] = message.description + pasteBoardItems["thumbData"] = message.thumbnail + } + + switch message { + case let message as TextMessage: + pasteBoardItems["command"] = "1020" + + pasteBoardItems["title"] = message.text + + case let message as ImageMessage: + pasteBoardItems["objectType"] = "2" + + pasteBoardItems["fileData"] = message.data + + case let message as AudioMessage: + pasteBoardItems["objectType"] = "3" + + pasteBoardItems["mediaDataUrl"] = message.dataLink?.absoluteString + pasteBoardItems["mediaUrl"] = message.link.absoluteString + + case let message as VideoMessage: + pasteBoardItems["objectType"] = "4" + + pasteBoardItems["mediaUrl"] = message.link.absoluteString + + case let message as WebPageMessage: + pasteBoardItems["objectType"] = "5" + + pasteBoardItems["mediaUrl"] = message.link.absoluteString + + case let message as FileMessage: + pasteBoardItems["objectType"] = "6" + + pasteBoardItems["fileData"] = message.data + pasteBoardItems["fileExt"] = message.fileExtension + + case let message as MiniProgramMessage: + pasteBoardItems["objectType"] = "36" + + pasteBoardItems["appBrandPath"] = message.path + pasteBoardItems["appBrandUserName"] = message.miniProgramID + pasteBoardItems["mediaUrl"] = message.link.absoluteString + pasteBoardItems["miniprogramType"] = miniProgramType(message.miniProgramType) + + default: + assertionFailure() + completionHandler(.failure(.unsupportedMessage)) + return + } + + setPasteboard(with: pasteBoardItems, in: .general, saveData: true) + + guard let url = getShareUniversalLink() else { + assertionFailure() + completionHandler(.failure(.invalidParameter)) + return + } + + UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { result in + if !result { + completionHandler(.failure(.unknown)) + } + } + } + + // swiftlint:enable cyclomatic_complexity function_body_length + + private func canShare(message: Message, to endpoint: Endpoint) -> Bool { + switch endpoint { + case Endpoints.Wechat.friend: + return true + case Endpoints.Wechat.timeline: + return ![ + Messages.file, + Messages.miniProgram, + ].contains(message) + case Endpoints.Wechat.favorite: + return ![ + Messages.miniProgram, + ].contains(message) + default: + assertionFailure() + return false + } + } + + private func scene(_ endpoint: Endpoint) -> String? { + let result: Int + + switch endpoint { + case Endpoints.Wechat.friend: + result = 0 // WXSceneSession + case Endpoints.Wechat.timeline: + result = 1 // WXSceneTimeline + case Endpoints.Wechat.favorite: + result = 2 // WXSceneFavorite + default: + return nil + } + + return "\(result)" + } + + private func miniProgramType(_ miniProgramType: MiniProgramMessage.MiniProgramType) -> String { + let result: Int + + switch miniProgramType { + case .release: + result = 0 // WXMiniProgramTypeRelease + case .test: + result = 1 // WXMiniProgramTypeTest + case .preview: + result = 2 // WXMiniProgramTypePreview + } + + return "\(result)" + } +} + +extension WechatHandler: OauthHandlerType { + + public func oauth( + options: [Bus.OauthOptionKey: Any], + completionHandler: @escaping Bus.OauthCompletionHandler + ) { + guard isInstalled else { + completionHandler(.failure(.missingApplication)) + return + } + + oauthCompletionHandler = completionHandler + + var pasteBoardItems: [String: Any] = [:] + + pasteBoardItems["command"] = "0" + pasteBoardItems["isAutoResend"] = "0" + pasteBoardItems["result"] = "1" + pasteBoardItems["returnFromApp"] = "0" + pasteBoardItems["sdkver"] = sdkVersion + pasteBoardItems["universalLink"] = universalLink.absoluteString + + setPasteboard(with: pasteBoardItems, in: .general) + + guard let url = getOauthUniversalLink() else { + assertionFailure() + completionHandler(.failure(.invalidParameter)) + return + } + + UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { result in + if !result { + completionHandler(.failure(.unknown)) + } + } + } +} + +extension WechatHandler { + + private var identifier: String? { + Bundle.main.bus.identifier + } + + private var contextID: String? { + let timestamp = Date().timeIntervalSince1970 + return "\(timestamp)".bus.sha1 + } + + private var sdkVersion: String { + "1.8.7.1" + } +} + +extension WechatHandler { + + private func setPasteboard( + with pasteBoardItems: [String: Any], + in pasteboard: UIPasteboard, + saveData: Bool = false + ) { + var pbItems: [String: Any] = [:] + + pbItems[appID] = pasteBoardItems + + guard + let pbData = try? PropertyListSerialization.data( + fromPropertyList: pbItems, + format: .binary, + options: .zero + ) + else { + assertionFailure() + return + } + + setPasteboard(with: pbData, in: .general) + + if saveData { + lastMessageData = pbData + } + } + + private func setPasteboard(with data: Data, in pasteboard: UIPasteboard) { + pasteboard.setData(data, forPasteboardType: "content") + } + + private func getShareUniversalLink() -> URL? { + guard + let identifier = identifier, + let contextID = contextID + else { + return nil + } + + var components = URLComponents() + + components.scheme = "https" + components.host = "help.wechat.com" + components.path = "/app/\(appID)/sendreq/" + + var urlItems: [String: String] = [:] + + urlItems["wechat_app_bundleId"] = identifier + urlItems["wechat_auth_context_id"] = contextID + + if let signToken = signToken { + urlItems["wechat_auth_token"] = signToken + } + + components.queryItems = urlItems.map { key, value in + URLQueryItem(name: key, value: value) + } + + return components.url + } + + private func getOauthUniversalLink() -> URL? { + guard + let identifier = identifier, + let contextID = contextID + else { + return nil + } + + var components = URLComponents() + + components.scheme = "https" + components.host = "help.wechat.com" + components.path = "/app/\(appID)/auth/" + + var urlItems: [String: String] = [:] + + urlItems["scope"] = "snsapi_userinfo" + urlItems["wechat_app_bundleId"] = identifier + urlItems["wechat_auth_context_id"] = contextID + + components.queryItems = urlItems.map { key, value in + URLQueryItem(name: key, value: value) + } + + return components.url + } +} + +extension WechatHandler: OpenUserActivityHandlerType { + + public func openUserActivity(_ userActivity: NSUserActivity) { + guard + let url = userActivity.webpageURL, + let components = URLComponents(url: url, resolvingAgainstBaseURL: false) + else { + assertionFailure() + return + } + + switch components.path { + case universalLink.appendingPathComponent("\(appID)/refreshToken").path: + handleSignToken(with: components) + case universalLink.appendingPathComponent("\(appID)/").path + "/": + handleGeneral() + case universalLink.appendingPathComponent("\(appID)/oauth").path: + handleOauth(with: components) + default: + assertionFailure() + } + } +} + +extension WechatHandler { + + private func handleSignToken(with components: URLComponents) { + guard + let infos = components.queryItems, + let signTokenItem = infos.first(where: { $0.name == "wechat_auth_token" }), + let signToken = signTokenItem.value, + let pbData = lastMessageData + else { + assertionFailure() + shareCompletionHandler?(.failure(.invalidParameter)) + return + } + + self.signToken = signToken + + setPasteboard(with: pbData, in: .general) + lastMessageData = nil + + guard let url = getShareUniversalLink() else { + assertionFailure() + shareCompletionHandler?(.failure(.invalidParameter)) + return + } + + UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { [weak self] result in + if !result { + self?.shareCompletionHandler?(.failure(.unknown)) + } + } + } + + private func getPlist(from pasteboard: UIPasteboard) -> [String: Any]? { + guard + let itemData = pasteboard.data(forPasteboardType: "content"), + let infos = try? PropertyListSerialization.propertyList(from: itemData, format: nil) as? [String: Any] + else { + return nil + } + + return infos[appID] as? [String: Any] + } + + private func handleGeneral() { + guard let infos = getPlist(from: .general) else { + assertionFailure() + return + } + + let command = infos["command"] as? String + + switch command { + case "2020": + handleShare(with: infos) + case "2030": + handleOauth(with: infos) + default: + assertionFailure() + } + } +} + +extension WechatHandler { + + private func handleShare(with infos: [String: Any]) { + let result = infos["result"] as? String + + switch result { + case "0": + shareCompletionHandler?(.success(())) + default: + assertionFailure() + shareCompletionHandler?(.failure(.unknown)) + } + } + + private func handleOauth(with infos: [String: Any]) { + let result = infos["result"] as? String + + switch result { + case "-4", "-2": + oauthCompletionHandler?(.failure(.userCancelled)) + default: + assertionFailure() + oauthCompletionHandler?(.failure(.unknown)) + } + } + + private func handleOauth(with components: URLComponents) { + guard + let items = components.queryItems, + let codeItem = items.first(where: { $0.name == "code" }), + let code = codeItem.value + else { + assertionFailure() + oauthCompletionHandler?(.failure(.invalidParameter)) + return + } + + let parameters = [ + OauthInfoKeys.code: code, + ] + .bus + .compactMapContent() + + if !parameters.isEmpty { + oauthCompletionHandler?(.success(parameters)) + } else { + oauthCompletionHandler?(.failure(.unknown)) + } + } +} + +extension WechatHandler { + + public enum ShareOptionKeys { + + public static let signToken = Bus.ShareOptionKey(rawValue: "com.nuomi1.bus.wechatHandler.signToken") + } +} + +extension WechatHandler { + + public enum OauthInfoKeys { + + public static let code = Bus.OauthInfoKeys.Wechat.code + } +} From d2fc51da8a95d6923c1de61cef9521524a7ca5b7 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 00:05:14 +0800 Subject: [PATCH 05/15] feat: add WechatHandler --- NBus.podspec | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NBus.podspec b/NBus.podspec index 5357284..efcefe6 100644 --- a/NBus.podspec +++ b/NBus.podspec @@ -16,6 +16,7 @@ Pod::Spec.new do |s| s.subspec "BusHandlers" do |ss| ss.dependency "NBus/QQHandler" + ss.dependency "NBus/WechatHandler" ss.dependency "NBus/WeiboHandler" ss.dependency "NBus/SystemHandler" end @@ -51,6 +52,12 @@ Pod::Spec.new do |s| ss.source_files = ["NBus/Classes/Handler/WechatSDKHandler.swift"] end + s.subspec "WechatHandler" do |ss| + ss.dependency "NBus/Core" + + ss.source_files = ["NBus/Classes/Handler/WechatHandler.swift"] + end + s.subspec "WeiboSDKHandler" do |ss| ss.dependency "NBus/Core" ss.dependency "NBus/WeiboSDK" From b97cac263f4f09f6aee8b7b046372374624996a7 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 00:05:25 +0800 Subject: [PATCH 06/15] chore: update --- Example/Podfile.lock | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 17d60a5..bde3ab1 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,30 +1,33 @@ PODS: - - NBus/BusHandlers (0.8.1): + - NBus/BusHandlers (0.9.1): - NBus/QQHandler - NBus/SystemHandler + - NBus/WechatHandler - NBus/WeiboHandler - - NBus/Core (0.8.1) - - NBus/QQHandler (0.8.1): + - NBus/Core (0.9.1) + - NBus/QQHandler (0.9.1): - NBus/Core - - NBus/QQSDK (0.8.1) - - NBus/QQSDKHandler (0.8.1): + - NBus/QQSDK (0.9.1) + - NBus/QQSDKHandler (0.9.1): - NBus/Core - NBus/QQSDK - - NBus/SDKHandlers (0.8.1): + - NBus/SDKHandlers (0.9.1): - NBus/QQSDKHandler - NBus/SystemHandler - NBus/WechatSDKHandler - NBus/WeiboSDKHandler - - NBus/SystemHandler (0.8.1): + - NBus/SystemHandler (0.9.1): - NBus/Core - - NBus/WechatSDK (0.8.1) - - NBus/WechatSDKHandler (0.8.1): + - NBus/WechatHandler (0.9.1): + - NBus/Core + - NBus/WechatSDK (0.9.1) + - NBus/WechatSDKHandler (0.9.1): - NBus/Core - NBus/WechatSDK - - NBus/WeiboHandler (0.8.1): + - NBus/WeiboHandler (0.9.1): - NBus/Core - - NBus/WeiboSDK (0.8.1) - - NBus/WeiboSDKHandler (0.8.1): + - NBus/WeiboSDK (0.9.1) + - NBus/WeiboSDKHandler (0.9.1): - NBus/Core - NBus/WeiboSDK - PinLayout (1.9.3) @@ -59,7 +62,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - NBus: 97c14cb69f0ec19bd0752f5e25a3518849b81f8c + NBus: 8ecb3a7eb79360d65d22b5ca785164ca371f106d PinLayout: 4d8733121f8687edcc8f00c19bf1379d12808767 RxCocoa: 3f79328fafa3645b34600f37c31e64c73ae3a80e RxRelay: 8d593be109c06ea850df027351beba614b012ffb From c958f643343ba7009a4e577cce7776623b0b1ba7 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 00:05:45 +0800 Subject: [PATCH 07/15] feat: WechatHandler --- Example/NBus/Model/AppState.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Example/NBus/Model/AppState.swift b/Example/NBus/Model/AppState.swift index 8512c76..1371185 100644 --- a/Example/NBus/Model/AppState.swift +++ b/Example/NBus/Model/AppState.swift @@ -88,10 +88,16 @@ extension AppState { logger.debug("\(message)", file: file, function: function, line: line) } + let wechatHandler = WechatHandler( + appID: AppState.getAppID(for: Platforms.wechat)!, + universalLink: AppState.getUniversalLink(for: Platforms.wechat)! + ) + let wechatItem = AppState.PlatformItem( platform: Platforms.wechat, category: .sdk, handlers: [ + .bus: wechatHandler, .sdk: wechatSDKHandler, ], viewController: { PlatformViewController() } From 1ce9a46d70d77185115e7ed347008dbe16ed47f9 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 14:59:09 +0800 Subject: [PATCH 08/15] feat: wechatMiniProgram add thumbnail --- Example/NBus/Model/MediaSource.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Example/NBus/Model/MediaSource.swift b/Example/NBus/Model/MediaSource.swift index ba47866..5b1e3dd 100644 --- a/Example/NBus/Model/MediaSource.swift +++ b/Example/NBus/Model/MediaSource.swift @@ -124,11 +124,16 @@ enum MediaSource { let miniProgramID = AppState.getMiniProgramID(for: Platforms.wechat)! + let dataAsset = NSDataAsset(name: "giphy-J1ZajKJKzD0PK")! + let data = dataAsset.data + let thumbnail = UIImage(data: data)?.jpegData(compressionQuality: 0.2) + return Messages.miniProgram( miniProgramID: miniProgramID, path: path, link: url, - miniProgramType: .release + miniProgramType: .release, + thumbnail: thumbnail ) }() } From 84a8535113e7b8fef46ca9ab3c2bc1127d3093ca Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 15:00:54 +0800 Subject: [PATCH 09/15] fix: sha1 --- NBus/Classes/Core/Bus+Helper.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NBus/Classes/Core/Bus+Helper.swift b/NBus/Classes/Core/Bus+Helper.swift index 26a806b..2992667 100644 --- a/NBus/Classes/Core/Bus+Helper.swift +++ b/NBus/Classes/Core/Bus+Helper.swift @@ -40,7 +40,8 @@ extension BusWrapper where Base == String { _ = CC_SHA1(pointer.baseAddress, CC_LONG(data.count), &digest) } - return String(bytes: digest, encoding: .ascii) + let bytes = digest.map { String(format: "%02hhx", $0) } + return bytes.joined() } } From 6c1a44829981e96d571f89e334d5119549da9e7c Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 15:01:19 +0800 Subject: [PATCH 10/15] fix: type --- NBus/Classes/Handler/WechatHandler.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NBus/Classes/Handler/WechatHandler.swift b/NBus/Classes/Handler/WechatHandler.swift index ff35183..77b39a2 100644 --- a/NBus/Classes/Handler/WechatHandler.swift +++ b/NBus/Classes/Handler/WechatHandler.swift @@ -79,7 +79,7 @@ extension WechatHandler: ShareHandlerType { var pasteBoardItems: [String: Any] = [:] pasteBoardItems["command"] = "1010" - pasteBoardItems["isAutoResend"] = "0" + pasteBoardItems["isAutoResend"] = false pasteBoardItems["result"] = "1" pasteBoardItems["returnFromApp"] = "0" pasteBoardItems["scene"] = scene @@ -192,7 +192,7 @@ extension WechatHandler: ShareHandlerType { return "\(result)" } - private func miniProgramType(_ miniProgramType: MiniProgramMessage.MiniProgramType) -> String { + private func miniProgramType(_ miniProgramType: MiniProgramMessage.MiniProgramType) -> Int { let result: Int switch miniProgramType { @@ -204,7 +204,7 @@ extension WechatHandler: ShareHandlerType { result = 2 // WXMiniProgramTypePreview } - return "\(result)" + return result } } From e151f545e3824e050d5df3dd31d4ec5cf8b156a9 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 15:01:32 +0800 Subject: [PATCH 11/15] feat: hdThumbData --- NBus/Classes/Handler/WechatHandler.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/NBus/Classes/Handler/WechatHandler.swift b/NBus/Classes/Handler/WechatHandler.swift index 77b39a2..a633f83 100644 --- a/NBus/Classes/Handler/WechatHandler.swift +++ b/NBus/Classes/Handler/WechatHandler.swift @@ -130,6 +130,7 @@ extension WechatHandler: ShareHandlerType { pasteBoardItems["appBrandPath"] = message.path pasteBoardItems["appBrandUserName"] = message.miniProgramID + pasteBoardItems["hdThumbData"] = message.thumbnail pasteBoardItems["mediaUrl"] = message.link.absoluteString pasteBoardItems["miniprogramType"] = miniProgramType(message.miniProgramType) From c07d95e16ff8e00d5620a3fa85c1dfc1fe8aa08b Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sun, 31 Jan 2021 15:01:42 +0800 Subject: [PATCH 12/15] feat: oldText --- NBus/Classes/Handler/WechatHandler.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NBus/Classes/Handler/WechatHandler.swift b/NBus/Classes/Handler/WechatHandler.swift index a633f83..f9c0b54 100644 --- a/NBus/Classes/Handler/WechatHandler.swift +++ b/NBus/Classes/Handler/WechatHandler.swift @@ -261,6 +261,10 @@ extension WechatHandler { private var sdkVersion: String { "1.8.7.1" } + + private var oldText: String? { + UIPasteboard.general.bus.oldText + } } extension WechatHandler { @@ -274,6 +278,10 @@ extension WechatHandler { pbItems[appID] = pasteBoardItems + if let oldText = oldText { + pbItems["old_text"] = oldText + } + guard let pbData = try? PropertyListSerialization.data( fromPropertyList: pbItems, From 57f3f336ed54dcbe7a4095372f2f2d247706abf3 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Mon, 1 Feb 2021 21:57:41 +0800 Subject: [PATCH 13/15] feat: set pasteboard --- Example/NBus/AppDelegate.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Example/NBus/AppDelegate.swift b/Example/NBus/AppDelegate.swift index ba9d323..de96032 100644 --- a/Example/NBus/AppDelegate.swift +++ b/Example/NBus/AppDelegate.swift @@ -199,6 +199,8 @@ extension AppDelegate { let pasteboard = UIPasteboard.general pasteboard.items = [] + + pasteboard.string = "NBus" } private func clearUserDefaults() { From 04b85d94f3e10c9bbc184b1d8125191493271602 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Mon, 1 Feb 2021 23:18:23 +0800 Subject: [PATCH 14/15] feat: add WechatHandler article --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e9fcefa..0f96feb 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ nuomi1, nuomi1@qq.com - [NBus 之 QQHandler](https://blog.nuomi1.com/archives/2021/01/nbus-qqhandler.html) - [NBus 之 QQSDKHandler](https://blog.nuomi1.com/archives/2020/12/nbus-qqsdkhandler.html) - [NBus 之 SystemHandler](https://blog.nuomi1.com/archives/2020/12/nbus-systemhandler.html) +- [NBus 之 WechatHandler](https://blog.nuomi1.com/archives/2021/01/nbus-wechathandler.html) - [NBus 之 WechatSDKHandler](https://blog.nuomi1.com/archives/2020/12/nbus-wechatsdkhandler.html) - [NBus 之 WeiboHandler](https://blog.nuomi1.com/archives/2021/01/nbus-weibohandler.html) - [NBus 之 WeiboSDKHandler](https://blog.nuomi1.com/archives/2020/12/nbus-weibosdkhandler.html) From 5aa2e226a955fa0fbc3dba27e0b1d3a11bbb80ef Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Mon, 1 Feb 2021 23:18:41 +0800 Subject: [PATCH 15/15] bump to 0.10.0 --- NBus.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NBus.podspec b/NBus.podspec index efcefe6..9532280 100644 --- a/NBus.podspec +++ b/NBus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "NBus" - s.version = "0.9.1" + s.version = "0.10.0" s.summary = "A short description of NBus." s.homepage = "https://github.com/nuomi1/NBus"