Files
youle_app_ios/msext/Class/Utils/QQAppIDValidator.m
joywayer 2296c65974 feat: 重构分享功能 - 将各平台分享逻辑整理到对应Manager中
- 新增 WechatShareManager:封装微信分享逻辑,支持ShareContent对象
- 增强 DouyinShareManager:新增ShareContent支持和分享引导功能
- 优化 QQShareManager:支持截图/纯文本分享类型自动识别
- 重构 SharePanel:简化为UI调度层,移除具体分享实现
- 实现职责分离:各Manager专注自己的平台分享逻辑
- 提升可维护性:修改某平台不影响其他平台
- 增强可扩展性:新增分享平台更容易实现
2025-06-17 19:55:44 +08:00

223 lines
8.6 KiB
Objective-C
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
//
// QQAppIDValidator.m
// msext
//
// Created on 2025/06/16.
// Copyright © 2025年. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "QQShareManager.h"
/**
* QQ AppID配置验证工具
* 用于验证无SDK方式的QQ分享配置是否正确
*/
@interface QQAppIDValidator : NSObject
/**
* 执行完整的QQ分享配置检查
* 包括AppID、URL Schemes、回调配置等
*/
+ (void)performCompleteValidation;
/**
* 显示配置检查结果
*/
+ (void)showValidationResults;
/**
* 生成QQ分享测试URL用于调试
*/
+ (NSString *)generateTestQQShareURL;
@end
@implementation QQAppIDValidator
+ (void)performCompleteValidation {
NSLog(@"\n🔍 开始QQ分享配置验证...\n");
// 1. 检查QQ安装状态
BOOL isQQInstalled = [QQShareManager isQQInstalled];
NSLog(@"1⃣ QQ安装检查: %@", isQQInstalled ? @"✅ 已安装" : @"❌ 未安装");
// 2. 检查AppID配置
BOOL isAppIDValid = [QQShareManager validateQQAppIDConfiguration];
NSString *appID = [QQShareManager getCurrentQQAppID];
NSLog(@"2⃣ AppID配置检查: %@", isAppIDValid ? [NSString stringWithFormat:@"✅ 有效 (%@)", appID] : @"❌ 无效");
// 3. 检查URL Schemes配置
[self validateURLSchemes];
// 4. 检查回调配置
[self validateCallbackConfiguration];
// 5. 生成测试URL
NSString *testURL = [self generateTestQQShareURL];
NSLog(@"5⃣ 测试分享URL: %@", testURL);
NSLog(@"\n✅ QQ分享配置验证完成\n");
}
+ (void)validateURLSchemes {
NSArray *requiredSchemes = @[@"mqqapi", @"mqq", @"mqqOpensdkSSoLogin", @"mqqopensdkapiV2", @"mqqopensdkapiV3", @"mqqopensdkapiV4", @"wtloginmqq2", @"mqzone"];
BOOL allSchemesConfigured = YES;
NSMutableArray *missingSchemes = [NSMutableArray array];
for (NSString *scheme in requiredSchemes) {
NSString *testURLString = [NSString stringWithFormat:@"%@://test", scheme];
NSURL *testURL = [NSURL URLWithString:testURLString];
if (![[UIApplication sharedApplication] canOpenURL:testURL]) {
allSchemesConfigured = NO;
[missingSchemes addObject:scheme];
}
}
if (allSchemesConfigured) {
NSLog(@"3⃣ URL Schemes配置: ✅ 完整");
} else {
NSLog(@"3⃣ URL Schemes配置: ❌ 缺少 %@", [missingSchemes componentsJoinedByString:@", "]);
NSLog(@" 请在Info.plist的LSApplicationQueriesSchemes中添加缺少的schemes");
}
}
+ (void)validateCallbackConfiguration {
// 检查msext回调scheme是否配置
NSURL *callbackURL = [NSURL URLWithString:@"msext://test"];
NSBundle *mainBundle = [NSBundle mainBundle];
NSDictionary *infoPlist = [mainBundle infoDictionary];
NSArray *urlTypes = infoPlist[@"CFBundleURLTypes"];
BOOL callbackConfigured = NO;
for (NSDictionary *urlType in urlTypes) {
NSArray *schemes = urlType[@"CFBundleURLSchemes"];
if ([schemes containsObject:@"msext"]) {
callbackConfigured = YES;
break;
}
}
NSLog(@"4⃣ 回调配置检查: %@", callbackConfigured ? @"✅ 正确" : @"❌ 缺失msext scheme");
if (!callbackConfigured) {
NSLog(@" 请在Info.plist的CFBundleURLTypes中添加msext scheme配置");
}
}
+ (NSString *)generateTestQQShareURL {
NSString *appID = [QQShareManager getCurrentQQAppID];
if (!appID) {
return @"❌ 无法生成测试URLAppID未配置";
}
// 构建基础的QQ分享测试URL
NSMutableString *testURL = [NSMutableString stringWithString:@"mqqapi://share/to_fri?"];
[testURL appendString:@"version=1"];
[testURL appendString:@"&cflag=0"];
[testURL appendString:@"&src_type=app"];
[testURL appendString:@"&sdkv=2.9.0"];
[testURL appendString:@"&sdkp=i"];
[testURL appendFormat:@"&appid=%@", appID];
[testURL appendString:@"&app_name=进贤聚友棋牌"];
[testURL appendString:@"&callback_type=scheme"];
[testURL appendString:@"&callback_name=msext"];
[testURL appendString:@"&req_type=0"];
[testURL appendString:@"&title=测试标题"];
[testURL appendString:@"&description=测试描述"];
return testURL;
}
+ (void)showValidationResults {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"QQ分享配置验证"
message:@"请查看控制台日志以获取详细的验证结果"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *validateAction = [UIAlertAction actionWithTitle:@"重新验证"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self performCompleteValidation];
}];
UIAlertAction *testAction = [UIAlertAction actionWithTitle:@"测试分享"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self performTestShare];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"关闭"
style:UIAlertActionStyleCancel
handler:nil];
[alert addAction:validateAction];
[alert addAction:testAction];
[alert addAction:cancelAction];
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = [self topViewController:rootVC];
[topVC presentViewController:alert animated:YES completion:nil];
});
}
+ (void)performTestShare {
NSLog(@"🧪 开始QQ分享测试...");
[QQShareManager shareToQQFriend:QQShareTypeText
title:@"QQ分享配置测试"
description:@"如果您看到这条消息说明QQ分享配置正确"
thumbImage:nil
url:nil
image:nil
completion:^(BOOL success) {
NSLog(@"🧪 QQ分享测试结果: %@", success ? @"✅ 成功" : @"❌ 失败");
dispatch_async(dispatch_get_main_queue(), ^{
NSString *message = success ? @"QQ分享测试成功配置正确。" : @"QQ分享测试失败请检查配置。";
UIAlertController *resultAlert = [UIAlertController alertControllerWithTitle:@"测试结果"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[resultAlert addAction:okAction];
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = [self topViewController:rootVC];
[topVC presentViewController:resultAlert animated:YES completion:nil];
});
}];
}
+ (UIViewController *)topViewController:(UIViewController *)rootViewController {
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
return [self topViewController:lastViewController];
}
if ([rootViewController.presentedViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabBarController = (UITabBarController *)rootViewController.presentedViewController;
UIViewController *selectedViewController = tabBarController.selectedViewController;
return [self topViewController:selectedViewController];
}
return [self topViewController:rootViewController.presentedViewController];
}
@end
// 便捷调用方法
void validateQQShareConfiguration(void) {
[QQAppIDValidator performCompleteValidation];
}
void showQQShareValidationDialog(void) {
[QQAppIDValidator showValidationResults];
}