Skip to content

Commit

Permalink
适配2.3.18 && 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
TKkk-iOSer committed Oct 15, 2018
1 parent 3bf0a35 commit d179408
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 99 deletions.
17 changes: 9 additions & 8 deletions Other/Install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#!/bin/bash

app_name="WeChat"
shell_path="$(dirname "$0")"
wechat_path="/Applications/WeChat.app"
framework_name="WeChatPlugin"
app_bundle_path="/Applications/${app_name}.app/Contents/MacOS"
app_executable_path="${app_bundle_path}/${app_name}"
app_executable_backup_path="${app_executable_path}_backup"
framework_path="${app_bundle_path}/${framework_name}.framework"


if [ ! -d "$wechat_path" ]
then
Expand All @@ -20,6 +12,15 @@ exit
fi
fi

app_name="WeChat"
shell_path="$(dirname "$0")"
framework_name="WeChatPlugin"
app_bundle_path="${wechat_path}/Contents/MacOS"
app_executable_path="${app_bundle_path}/${app_name}"
app_executable_backup_path="${app_executable_path}_backup"
framework_path="${app_bundle_path}/${framework_name}.framework"


# 对 WeChat 赋予权限
if [ ! -w "$wechat_path" ]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@end

@interface MMContactSearchLogic : NSObject
{
unsigned long long _logicSearchResultFlag;
}
@property(retain, nonatomic) NSMutableArray *contactResults;
- (void)doSearchWithKeyword:(id)arg1 searchScene:(unsigned long long)arg2 resultIsShownBlock:(id)arg3 completion:(id)arg4;
@property(retain, nonatomic) NSMutableArray *groupResults;
Expand Down
12 changes: 6 additions & 6 deletions Other/Products/Debug/WeChatPlugin.framework/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>17E199</string>
<string>17G65</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>9E145</string>
<string>10A255</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>17E189</string>
<string>18A384</string>
<key>DTSDKName</key>
<string>macosx10.13</string>
<string>macosx10.14</string>
<key>DTXcode</key>
<string>0930</string>
<string>1000</string>
<key>DTXcodeBuild</key>
<string>9E145</string>
<string>10A255</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017年 tk. All rights reserved.</string>
<key>versionInfo</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@end

@interface MMContactSearchLogic : NSObject
{
unsigned long long _logicSearchResultFlag;
}
@property(retain, nonatomic) NSMutableArray *contactResults;
- (void)doSearchWithKeyword:(id)arg1 searchScene:(unsigned long long)arg2 resultIsShownBlock:(id)arg3 completion:(id)arg4;
@property(retain, nonatomic) NSMutableArray *groupResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>17E199</string>
<string>17G65</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>9E145</string>
<string>10A255</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>17E189</string>
<string>18A384</string>
<key>DTSDKName</key>
<string>macosx10.13</string>
<string>macosx10.14</string>
<key>DTXcode</key>
<string>0930</string>
<string>1000</string>
<key>DTXcodeBuild</key>
<string>9E145</string>
<string>10A255</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017年 tk. All rights reserved.</string>
<key>versionInfo</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@end

@interface MMContactSearchLogic : NSObject
{
unsigned long long _logicSearchResultFlag;
}
@property(retain, nonatomic) NSMutableArray *contactResults;
- (void)doSearchWithKeyword:(id)arg1 searchScene:(unsigned long long)arg2 resultIsShownBlock:(id)arg3 completion:(id)arg4;
@property(retain, nonatomic) NSMutableArray *groupResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>17E199</string>
<string>17G65</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>9E145</string>
<string>10A255</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>17E189</string>
<string>18A384</string>
<key>DTSDKName</key>
<string>macosx10.13</string>
<string>macosx10.14</string>
<key>DTXcode</key>
<string>0930</string>
<string>1000</string>
<key>DTXcodeBuild</key>
<string>9E145</string>
<string>10A255</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017年 tk. All rights reserved.</string>
<key>versionInfo</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Other/Products/Debug/WeChatPlugin.framework/WeChatPlugin
Binary file not shown.
16 changes: 9 additions & 7 deletions Other/Uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# !/bin/bash

app_name="WeChat"
wechat_path="/Applications/WeChat.app"
framework_name="WeChatPlugin"
app_bundle_path="/Applications/${app_name}.app/Contents/MacOS"
app_executable_path="${app_bundle_path}/${app_name}"
app_executable_backup_path="${app_executable_path}_backup"
framework_path="${app_bundle_path}/${framework_name}.framework"

if [ ! -d "$wechat_path" ]
then
Expand All @@ -18,6 +12,13 @@ exit
fi
fi

app_name="WeChat"
framework_name="WeChatPlugin"
app_bundle_path="${wechat_path}/Contents/MacOS"
app_executable_path="${app_bundle_path}/${app_name}"
app_executable_backup_path="${app_executable_path}_backup"
framework_path="${app_bundle_path}/${framework_name}.framework"

# 备份WeChat原始可执行文件
if [ -f "$app_executable_backup_path" ]
then
Expand All @@ -26,8 +27,9 @@ rm -rf "$framework_path"
mv "$app_executable_backup_path" "$app_executable_path"

if [ -f "$app_executable_backup_path" ]
echo "卸载失败,请到 /Applications/WeChat.app/Contents/MacOS 路径,删除 WeChatPlugin.framework、WeChat 两个文件文件,并将 WeChat_backup 重命名为 WeChat"
then
echo "卸载失败,请到 /Applications/WeChat.app/Contents/MacOS 路径,删除 WeChatPlugin.framework、WeChat 两个文件文件,并将 WeChat_backup 重命名为 WeChat"
else
echo "\n\t卸载成功"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,4 @@
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WeChatPlugin/Sources/Hook/WeChat+hook.m"
timestampString = "556881584.921349"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "191"
endingLineNumber = "191"
landmarkName = "-hook_OnSyncBatchAddMsgs:isFirstSync:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WeChatPlugin/Sources/Hook/WeChat+hook.m"
timestampString = "556881584.922109"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "194"
endingLineNumber = "194"
landmarkName = "-hook_OnSyncBatchAddMsgs:isFirstSync:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
74 changes: 42 additions & 32 deletions WeChatPlugin/Sources/Managers/TKWebServerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ - (void)addHandleForSearchUser {
__weak typeof(self) weakSelf = self;

[self.webServer addHandlerForMethod:@"GET" path:@"/wechat-plugin/user" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {

NSString *hostname = request.headers[@"Host"];
NSString *url1 = [NSString stringWithFormat:@"127.0.0.1:%d", port];
NSString *url2 = [NSString stringWithFormat:@"localhost:%d", port];
if(!([hostname isEqualToString:url1] | [hostname isEqualToString:url2])){
return [GCDWebServerResponse responseWithStatusCode:404];

if (![weakSelf isLocalhost:request.headers[@"Host"]]) {
return [GCDWebServerResponse responseWithStatusCode:404];
}

NSString *keyword = request.query ? request.query[@"keyword"] ? request.query[@"keyword"] : @"" : @"";
Expand Down Expand Up @@ -112,7 +109,11 @@ - (void)addHandleForSearchUser {
}
}];

while (!(hasResult && logic.isContactSearched && logic.isGroupContactSearched && logic.isBrandContactSearched)) {};
if ([logic respondsToSelector:@selector(isContactSearched)]) {
while (!(hasResult && logic.isContactSearched && logic.isGroupContactSearched && logic.isBrandContactSearched)) {};
} else {
while (!(hasResult && [[logic valueForKey:@"_logicSearchResultFlag"] longLongValue])) {};
}

MMChatMangerSearchReportMgr *reportMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMChatMangerSearchReportMgr")];

Expand Down Expand Up @@ -141,16 +142,14 @@ - (void)addHandleForSearchUser {
- (void)addHandleForSearchUserChatLog {
__weak typeof(self) weakSelf = self;
[self.webServer addHandlerForMethod:@"GET" path:@"/wechat-plugin/chatlog" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {
NSString *userId = request.query ? request.query[@"userId"] ? request.query[@"userId"] : nil : nil;
NSInteger count = request.query ? request.query[@"count"] ? [request.query[@"count"] integerValue] : 30 : 30;

NSString *hostname = request.headers[@"Host"];
NSString *url1 = [NSString stringWithFormat:@"127.0.0.1:%d", port];
NSString *url2 = [NSString stringWithFormat:@"localhost:%d", port];
if(!([hostname isEqualToString:url1] | [hostname isEqualToString:url2])){

if (![weakSelf isLocalhost:request.headers[@"Host"]]) {
return [GCDWebServerResponse responseWithStatusCode:404];
}

NSString *userId = request.query ? request.query[@"userId"] ? request.query[@"userId"] : nil : nil;
NSInteger count = request.query ? request.query[@"count"] ? [request.query[@"count"] integerValue] : 30 : 30;

if (userId) {
NSMutableArray *chatLogList = [NSMutableArray array];

Expand Down Expand Up @@ -182,16 +181,16 @@ - (void)addHandleForSearchUserChatLog {
}

- (void)addHandleForOpenSession {
__weak typeof(self) weakSelf = self;

[self.webServer addHandlerForMethod:@"POST" path:@"/wechat-plugin/open-session" requestClass:[GCDWebServerURLEncodedFormRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerURLEncodedFormRequest * _Nonnull request) {
NSDictionary *requestBody = [request arguments];

NSString *hostname = request.headers[@"Host"];
NSString *url1 = [NSString stringWithFormat:@"127.0.0.1:%d", port];
NSString *url2 = [NSString stringWithFormat:@"localhost:%d", port];
if(!([hostname isEqualToString:url1] | [hostname isEqualToString:url2])){

if (![weakSelf isLocalhost:request.headers[@"Host"]]) {
return [GCDWebServerResponse responseWithStatusCode:404];
}

NSDictionary *requestBody = [request arguments];

if (requestBody && requestBody[@"userId"]) {
dispatch_async(dispatch_get_main_queue(), ^{
MMSessionMgr *sessionMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMSessionMgr")];
Expand Down Expand Up @@ -220,16 +219,16 @@ - (void)addHandleForOpenSession {
}

- (void)addHandleForSendMsg {
__weak typeof(self) weakSelf = self;

[self.webServer addHandlerForMethod:@"POST" path:@"/wechat-plugin/send-message" requestClass:[GCDWebServerURLEncodedFormRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerURLEncodedFormRequest * _Nonnull request) {
NSDictionary *requestBody = [request arguments];
NSString *userId = requestBody[@"userId"];

NSString *hostname = request.headers[@"Host"];
NSString *url1 = [NSString stringWithFormat:@"127.0.0.1:%d", port];
NSString *url2 = [NSString stringWithFormat:@"localhost:%d", port];
if(!([hostname isEqualToString:url1] | [hostname isEqualToString:url2])){

if (![weakSelf isLocalhost:request.headers[@"Host"]]) {
return [GCDWebServerResponse responseWithStatusCode:404];
}

NSDictionary *requestBody = [request arguments];
NSString *userId = requestBody[@"userId"];

if (requestBody && userId.length > 0) {
NSString *content = requestBody[@"content"];
Expand All @@ -245,11 +244,14 @@ - (void)addHandleForSendMsg {
[[TKMessageManager shareManager] clearUnRead:requestBody[@"userId"]];

} else if (content.length == 0 && requestBody[@"srvId"]) {
NSInteger srvId = [requestBody[@"srvId"] integerValue];
if (srvId != 0) {
MessageData *msgData = [messageService GetMsgData:userId svrId:srvId];
[[TKMessageManager shareManager] playVoiceWithMessageData:msgData];
if (requestBody[@"srvId"]) {
NSInteger srvId = [requestBody[@"srvId"] integerValue];
if (srvId != 0) {
MessageData *msgData = [messageService GetMsgData:userId svrId:srvId];
[[TKMessageManager shareManager] playVoiceWithMessageData:msgData];
}
}
[[TKMessageManager shareManager] clearUnRead:userId];
}
});
return [GCDWebServerResponse responseWithStatusCode:200];
Expand Down Expand Up @@ -445,7 +447,7 @@ - (NSDictionary *)dictFromMessageData:(MessageData *)msgData {
title = [title stringByAppendingString:msgData.msgVoiceText];
}
if (msgData.IsUnPlayed) {
title = [NSString stringWithFormat:@"%@%@",TKLocalizedString(@"assistant.search.message.unread"),title];
title = [NSString stringWithFormat:@"%@(%@)",title,TKLocalizedString(@"assistant.search.message.unread")];
}
} else if (msgData.messageType == 49) {
NSString *msgContact = [msgData summaryString:NO];
Expand Down Expand Up @@ -491,6 +493,7 @@ - (NSDictionary *)dictWithMessageContent:(NSString *)msg {

return error? nil : msgDict;
}

- (NSString *)getDateStringWithTimeStr:(NSTimeInterval)time{
NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
Expand Down Expand Up @@ -530,4 +533,11 @@ - (NSString *)getUserNameWithContactData:(WCContactData *)contact showOriginName
return userName ?: @"";
}

- (BOOL)isLocalhost:(NSString *)host {
NSArray *localhostUrls = @[[NSString stringWithFormat:@"127.0.0.1:%d", port],
[NSString stringWithFormat:@"localhost:%d", port]
];
return [localhostUrls containsObject:host];
}

@end
3 changes: 3 additions & 0 deletions WeChatPlugin/WeChatPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@end

@interface MMContactSearchLogic : NSObject
{
unsigned long long _logicSearchResultFlag;
}
@property(retain, nonatomic) NSMutableArray *contactResults;
- (void)doSearchWithKeyword:(id)arg1 searchScene:(unsigned long long)arg2 resultIsShownBlock:(id)arg3 completion:(id)arg4;
@property(retain, nonatomic) NSMutableArray *groupResults;
Expand Down

0 comments on commit d179408

Please sign in to comment.