提交 dd1bc54a authored 作者: JarvanMo's avatar JarvanMo

refactor iOS

上级 44209945
#!/bin/sh #!/bin/sh
# This is a generated file; do not edit or check into version control. # This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/mo/Development/flutter" export "FLUTTER_ROOT=/Users/mo/Development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/mo/Code/Other/newF/fluwx/example" export "FLUTTER_APPLICATION_PATH=/Users/mo/Code/Other/fluwx/example"
export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_TARGET=/Users/mo/Code/Other/fluwx/example/lib/main.dart"
export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/mo/Development/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_FRAMEWORK_DIR=/Users/mo/Development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1" export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
PODS:
- Flutter (1.0.0)
- fluwx (0.0.1):
- Flutter
- WechatOpenSDK (= 1.8.6.2)
- WechatOpenSDK (1.8.6.2)
DEPENDENCIES:
- Flutter (from `Flutter`)
- fluwx (from `.symlinks/plugins/fluwx/ios`)
SPEC REPOS:
trunk:
- WechatOpenSDK
EXTERNAL SOURCES:
Flutter:
:path: Flutter
fluwx:
:path: ".symlinks/plugins/fluwx/ios"
SPEC CHECKSUMS:
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
fluwx: 1b1b2979492955ba6c5228483b8517bb7d1d0740
WechatOpenSDK: 8b3ba4239193d1112205c139c94e21934e8f369a
PODFILE CHECKSUM: 3dbe063e9c90a5d7c9e4e76e70a821b9e2c1d271
COCOAPODS: 1.8.4
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
62B88C18565D88C02906C10C /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C08EA6C421C7E89069DE6B /* libPods-Runner.a */; };
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
...@@ -38,6 +39,8 @@ ...@@ -38,6 +39,8 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
27C08EA6C421C7E89069DE6B /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
32AE9497AA826921991B27BF /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
...@@ -52,6 +55,8 @@ ...@@ -52,6 +55,8 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9E479F6222F46DD1BF9F2E3E /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
D9FC4FD7820D62136E2C7EAB /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -61,12 +66,31 @@ ...@@ -61,12 +66,31 @@
files = ( files = (
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
62B88C18565D88C02906C10C /* libPods-Runner.a in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
3510C167085BA3D3F8540F37 /* Pods */ = {
isa = PBXGroup;
children = (
9E479F6222F46DD1BF9F2E3E /* Pods-Runner.debug.xcconfig */,
32AE9497AA826921991B27BF /* Pods-Runner.release.xcconfig */,
D9FC4FD7820D62136E2C7EAB /* Pods-Runner.profile.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
};
8513A54653CE3C4FB2C564F0 /* Frameworks */ = {
isa = PBXGroup;
children = (
27C08EA6C421C7E89069DE6B /* libPods-Runner.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = { 9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -86,7 +110,8 @@ ...@@ -86,7 +110,8 @@
9740EEB11CF90186004384FC /* Flutter */, 9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */, 97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */, 97C146EF1CF9000F007C117D /* Products */,
CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, 3510C167085BA3D3F8540F37 /* Pods */,
8513A54653CE3C4FB2C564F0 /* Frameworks */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };
...@@ -129,12 +154,14 @@ ...@@ -129,12 +154,14 @@
isa = PBXNativeTarget; isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = ( buildPhases = (
E2E8F9B5C8F1E9545B8C092B /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */, 9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */, 97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */, 97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */, 97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */, 9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */,
193B0A2F7BBE7B22CD4D85EA /* [CP] Embed Pods Frameworks */,
); );
buildRules = ( buildRules = (
); );
...@@ -192,6 +219,21 @@ ...@@ -192,6 +219,21 @@
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */
193B0A2F7BBE7B22CD4D85EA /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
...@@ -220,6 +262,28 @@ ...@@ -220,6 +262,28 @@
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
}; };
E2E8F9B5C8F1E9545B8C092B /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */ /* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
......
...@@ -4,4 +4,7 @@ ...@@ -4,4 +4,7 @@
<FileRef <FileRef
location = "group:Runner.xcodeproj"> location = "group:Runner.xcodeproj">
</FileRef> </FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace> </Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
...@@ -18,8 +18,22 @@ ...@@ -18,8 +18,22 @@
<string>$(FLUTTER_BUILD_NAME)</string> <string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>wxd930ea5d5a258f4f</string>
</dict>
</array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string> <string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
<string>weixinULAPI</string>
</array>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
......
//
// Created by mo on 2020/3/7.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "FluwxPlugin.h"
#import "WXApiRequestHandler.h"
#import "WechatAuthSDK.h"
@class FluwxStringUtil;
@interface FluwxAuthHandler : NSObject <WechatAuthAPIDelegate>
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar methodChannel:(FlutterMethodChannel *)flutterMethodChannel;
- (void)handleAuth:(FlutterMethodCall *)call result:(FlutterResult)result;
- (void)authByQRCode:(FlutterMethodCall *)call result:(FlutterResult)result;
- (void)stopAuthByQRCode:(FlutterMethodCall *)call result:(FlutterResult)result;
@end
//
// Created by mo on 2020/3/7.
//
#import "FluwxAuthHandler.h"
#import "WXApi.h"
#import "WechatAuthSDK.h"
@implementation FluwxAuthHandler
WechatAuthSDK *_qrauth;
FlutterMethodChannel *_fluwxMethodChannel = nil;
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar methodChannel:(FlutterMethodChannel *)flutterMethodChannel {
self = [super init];
if (self) {
_qrauth = [[WechatAuthSDK alloc] init];
_qrauth.delegate = self;
_fluwxMethodChannel = flutterMethodChannel;
}
return self;
}
- (void)handleAuth:(FlutterMethodCall *)call result:(FlutterResult)result {
NSString *openId = call.arguments[@"openId"];
[WXApiRequestHandler sendAuthRequestScope:call.arguments[@"scope"]
State:(call.arguments[@"state"] == (id) [NSNull null]) ? nil : call.arguments[@"state"]
OpenID:(openId == (id) [NSNull null]) ? nil : openId completion:^(BOOL done) {result(@(done));}];
}
- (void)authByQRCode:(FlutterMethodCall *)call result:(FlutterResult)result {
NSString *appId = call.arguments[@"appId"];
NSString *scope = call.arguments[@"scope"];
NSString *nonceStr = call.arguments[@"nonceStr"];
NSString *timeStamp = call.arguments[@"timeStamp"];
NSString *signature = call.arguments[@"signature"];
NSString *schemeData = (call.arguments[@"schemeData"] == (id) [NSNull null]) ? nil : call.arguments[@"schemeData"];
BOOL done = [_qrauth Auth:appId nonceStr:nonceStr timeStamp:timeStamp scope:scope signature:signature schemeData:schemeData];
result(@(done));
}
- (void)stopAuthByQRCode:(FlutterMethodCall *)call result:(FlutterResult)result {
BOOL done = [_qrauth StopAuth];
result(@(done));
}
- (void)onQrcodeScanned {
[_fluwxMethodChannel invokeMethod:@"onQRCodeScanned" arguments:nil];
}
- (void)onAuthGotQrcode:(UIImage *)image {
NSData *imageData = UIImagePNGRepresentation(image);
// if (imageData == nil) {
// imageData = UIImageJPEGRepresentation(image, 1);
// }
[_fluwxMethodChannel invokeMethod:@"onAuthGotQRCode" arguments:imageData];
}
- (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode {
NSDictionary *errorCode = @{@"errCode": @(errCode)};
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:errorCode];
if (authCode != nil) {
result[@"authCode"] = authCode;
}
[_fluwxMethodChannel invokeMethod:@"onAuthByQRCodeFinished" arguments:result];
}
@end
#import "FluwxPlugin.h" #import "FluwxPlugin.h"
#import "FluwxResponseHandler.h"
#import "FluwxStringUtil.h"
#import "FluwxAuthHandler.h"
#import "FluwxShareHandler.h"
@implementation FluwxPlugin @implementation FluwxPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { FluwxAuthHandler *_fluwxAuthHandler;
FlutterMethodChannel* channel = [FlutterMethodChannel FluwxShareHandler *_fluwxShareHandler;
methodChannelWithName:@"fluwx"
binaryMessenger:[registrar messenger]]; BOOL handleOpenURLByFluwx = YES;
FluwxPlugin* instance = [[FluwxPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel]; + (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
} FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:@"com.jarvanmo/fluwx"
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { binaryMessenger:[registrar messenger]];
if ([@"getPlatformVersion" isEqualToString:call.method]) { FluwxPlugin *instance = [[FluwxPlugin alloc] initWithRegistrar:registrar methodChannel:channel];
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); [registrar addMethodCallDelegate:instance channel:channel];
} else { [[FluwxResponseHandler defaultManager] setMethodChannel:channel];
result(FlutterMethodNotImplemented); [registrar addApplicationDelegate:instance];
}
}
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar methodChannel:(FlutterMethodChannel *)flutterMethodChannel {
self = [super init];
if (self) {
_fluwxAuthHandler = [[FluwxAuthHandler alloc] initWithRegistrar:registrar methodChannel:flutterMethodChannel];
_fluwxShareHandler = [[FluwxShareHandler alloc] initWithRegistrar:registrar];
}
return self;
}
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"registerApp" isEqualToString:call.method]) {
[self registerApp:call result:result];
} else if ([@"isWeChatInstalled" isEqualToString:call.method]) {
[self checkWeChatInstallation:call result:result];
} else if ([@"sendAuth" isEqualToString:call.method]) {
[_fluwxAuthHandler handleAuth:call result:result];
} else if ([@"authByQRCode" isEqualToString:call.method]) {
[_fluwxAuthHandler authByQRCode:call result:result];
} else if ([@"stopAuthByQRCode" isEqualToString:call.method]) {
[_fluwxAuthHandler stopAuthByQRCode:call result:result];
} else if ([@"openWXApp" isEqualToString:call.method]) {
result(@([WXApi openWXApp]));
} else if ([@"payWithFluwx" isEqualToString:call.method]) {
[self handlePayment:call result:result];
} else if ([@"launchMiniProgram" isEqualToString:call.method]) {
[self handleLaunchMiniProgram:call result:result];
} else if ([@"subscribeMsg" isEqualToString:call.method]) {
[self handleSubscribeWithCall:call result:result];
} else if ([@"autoDeduct" isEqualToString:call.method]) {
[self handleAutoDeductWithCall:call result:result];
} else if ([call.method hasPrefix:@"share"]) {
[_fluwxShareHandler handleShare:call result:result];
} else {
result(FlutterMethodNotImplemented);
}
}
- (void)registerApp:(FlutterMethodCall *)call result:(FlutterResult)result {
if (!call.arguments[@"iOS"]) {
result(@NO);
return;
}
NSString *appId = call.arguments[@"appId"];
if ([FluwxStringUtil isBlank:appId]) {
result([FlutterError errorWithCode:@"invalid app id" message:@"are you sure your app id is correct ? " details:appId]);
return;
}
NSString *universalLink = call.arguments[@"universalLink"];
if ([FluwxStringUtil isBlank:universalLink]) {
result([FlutterError errorWithCode:@"invalid universal link" message:@"are you sure your universal link is correct ? " details:universalLink]);
return;
}
BOOL isWeChatRegistered = [WXApi registerApp:appId universalLink:universalLink];
result(@(isWeChatRegistered));
}
- (void)checkWeChatInstallation:(FlutterMethodCall *)call result:(FlutterResult)result {
result(@([WXApi isWXAppInstalled]));
}
- (void)handlePayment:(FlutterMethodCall *)call result:(FlutterResult)result {
NSNumber *timestamp = call.arguments[@"timeStamp"];
NSString *partnerId = call.arguments[@"partnerId"];
NSString *prepayId = call.arguments[@"prepayId"];
NSString *packageValue = call.arguments[@"packageValue"];
NSString *nonceStr = call.arguments[@"nonceStr"];
UInt32 timeStamp = [timestamp unsignedIntValue];
NSString *sign = call.arguments[@"sign"];
[WXApiRequestHandler sendPayment:call.arguments[@"appId"]
PartnerId:partnerId
PrepayId:prepayId
NonceStr:nonceStr
Timestamp:timeStamp
Package:packageValue
Sign:sign completion:^(BOOL done) {
result(@(done));
}];
}
- (void)handleLaunchMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result {
NSString *userName = call.arguments[@"userName"];
NSString *path = call.arguments[@"path"];
// WXMiniProgramType *miniProgramType = call.arguments[@"miniProgramType"];
NSNumber *typeInt = call.arguments[@"miniProgramType"];
WXMiniProgramType miniProgramType = WXMiniProgramTypeRelease;
if ([typeInt isEqualToNumber:@1]) {
miniProgramType = WXMiniProgramTypeTest;
} else if ([typeInt isEqualToNumber:@2]) {
miniProgramType = WXMiniProgramTypePreview;
}
[WXApiRequestHandler launchMiniProgramWithUserName:userName
path:path
type:miniProgramType completion:^(BOOL done) {
result(@(done));
}];
}
- (void)handleSubscribeWithCall:(FlutterMethodCall *)call result:(FlutterResult)result {
NSDictionary *params = call.arguments;
NSString *appId = [params valueForKey:@"appId"];
int scene = [[params valueForKey:@"scene"] intValue];
NSString *templateId = [params valueForKey:@"templateId"];
NSString *reserved = [params valueForKey:@"reserved"];
WXSubscribeMsgReq *req = [WXSubscribeMsgReq new];
req.scene = (UInt32) scene;
req.templateId = templateId;
req.reserved = reserved;
req.openID = appId;
[WXApi sendReq:req completion:^(BOOL done) {
result(@(done));
}];
}
- (void)handleAutoDeductWithCall:(FlutterMethodCall *)call result:(FlutterResult)result {
NSMutableDictionary *paramsFromDart = [NSMutableDictionary dictionaryWithDictionary:call.arguments];
[paramsFromDart removeObjectForKey:@"businessType"];
WXOpenBusinessWebViewReq *req = [[WXOpenBusinessWebViewReq alloc] init];
NSNumber *businessType = call.arguments[@"businessType"];
req.businessType = [businessType unsignedIntValue];
req.queryInfoDic = paramsFromDart;
[WXApi sendReq:req completion:^(BOOL done) {
result(@(done));
}];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [WXApi handleOpenURL:url delegate:[FluwxResponseHandler defaultManager]];
}
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *, id> *)options {
return [WXApi handleOpenURL:url delegate:[FluwxResponseHandler defaultManager]];
}
- (BOOL) application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {
return [WXApi handleOpenUniversalLink:userActivity delegate:[FluwxResponseHandler defaultManager]];
}
- (BOOL)handleOpenURL:(NSNotification *)aNotification {
if (handleOpenURLByFluwx) {
NSString *aURLString = [aNotification userInfo][@"url"];
NSURL *aURL = [NSURL URLWithString:aURLString];
return [WXApi handleOpenURL:aURL delegate:[FluwxResponseHandler defaultManager]];
} else {
return NO;
}
} }
@end @end
//
// Created by mo on 2020/3/7.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import <Flutter/Flutter.h>
#import "WXApi.h"
#import "WXApiObject.h"
@protocol WXApiManagerDelegate <NSObject>
@optional
- (void)managerDidRecvGetMessageReq:(GetMessageFromWXReq *)request;
- (void)managerDidRecvShowMessageReq:(ShowMessageFromWXReq *)request;
- (void)managerDidRecvLaunchFromWXReq:(LaunchFromWXReq *)request;
- (void)managerDidRecvMessageResponse:(SendMessageToWXResp *)response;
- (void)managerDidRecvAuthResponse:(SendAuthResp *)response;
- (void)managerDidRecvAddCardResponse:(AddCardToWXCardPackageResp *)response;
- (void)managerDidRecvChooseCardResponse:(WXChooseCardResp *)response;
- (void)managerDidRecvChooseInvoiceResponse:(WXChooseInvoiceResp *)response;
- (void)managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *)response;
- (void)managerDidRecvLaunchMiniProgram:(WXLaunchMiniProgramResp *)response;
- (void)managerDidRecvInvoiceAuthInsertResponse:(WXInvoiceAuthInsertResp *)response;
- (void)managerDidRecvNonTaxpayResponse:(WXNontaxPayResp *)response;
- (void)managerDidRecvPayInsuranceResponse:(WXPayInsuranceResp *)response;
- (void)managerDidRecvPaymentResponse:(PayResp *)response;
@end
@interface FluwxResponseHandler : NSObject <WXApiDelegate>
@property(nonatomic, assign) id <WXApiManagerDelegate> delegate;
+ (instancetype)defaultManager;
- (void)setMethodChannel:(FlutterMethodChannel *)flutterMethodChannel;
@end
//
// Created by mo on 2020/3/7.
//
#import <Flutter/Flutter.h>
#import "FluwxStringUtil.h"
#import "WXApiObject.h"
#import "FluwxResponseHandler.h"
@implementation FluwxResponseHandler
const NSString *errStr = @"errStr";
const NSString *errCode = @"errCode";
const NSString *openId = @"openId";
const NSString *type = @"type";
const NSString *lang = @"lang";
const NSString *country = @"country";
const NSString *description = @"description";
#pragma mark - LifeCycle
+ (instancetype)defaultManager {
static dispatch_once_t onceToken;
static FluwxResponseHandler *instance;
dispatch_once(&onceToken, ^{
instance = [[FluwxResponseHandler alloc] init];
});
return instance;
}
FlutterMethodChannel *fluwxMethodChannel = nil;
- (void)setMethodChannel:(FlutterMethodChannel *)flutterMethodChannel {
fluwxMethodChannel = flutterMethodChannel;
}
#pragma mark - WXApiDelegate
- (void)onResp:(BaseResp *)resp {
if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvMessageResponse:)]) {
SendMessageToWXResp *messageResp = (SendMessageToWXResp *) resp;
[_delegate managerDidRecvMessageResponse:messageResp];
}
SendMessageToWXResp *messageResp = (SendMessageToWXResp *) resp;
NSDictionary *result = @{
description: messageResp.description == nil ? @"" : messageResp.description,
errStr: messageResp.errStr == nil ? @"" : messageResp.errStr,
errCode: @(messageResp.errCode),
type: @(messageResp.type),
country: messageResp.country == nil ? @"" : messageResp.country,
lang: messageResp.lang == nil ? @"" : messageResp.lang};
[fluwxMethodChannel invokeMethod:@"onShareResponse" arguments:result];
} else if ([resp isKindOfClass:[SendAuthResp class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvAuthResponse:)]) {
SendAuthResp *authResp = (SendAuthResp *) resp;
[_delegate managerDidRecvAuthResponse:authResp];
}
SendAuthResp *authResp = (SendAuthResp *) resp;
NSDictionary *result = @{
description: authResp.description == nil ? @"" : authResp.description,
errStr: authResp.errStr == nil ? @"" : authResp.errStr,
errCode: @(authResp.errCode),
type: @(authResp.type),
country: authResp.country == nil ? @"" : authResp.country,
lang: authResp.lang == nil ? @"" : authResp.lang,
@"code": [FluwxStringUtil nilToEmpty:authResp.code],
@"state": [FluwxStringUtil nilToEmpty:authResp.state]
};
[fluwxMethodChannel invokeMethod:@"onAuthResponse" arguments:result];
} else if ([resp isKindOfClass:[AddCardToWXCardPackageResp class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvAddCardResponse:)]) {
AddCardToWXCardPackageResp *addCardResp = (AddCardToWXCardPackageResp *) resp;
[_delegate managerDidRecvAddCardResponse:addCardResp];
}
} else if ([resp isKindOfClass:[WXChooseCardResp class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvChooseCardResponse:)]) {
WXChooseCardResp *chooseCardResp = (WXChooseCardResp *) resp;
[_delegate managerDidRecvChooseCardResponse:chooseCardResp];
}
} else if ([resp isKindOfClass:[WXChooseInvoiceResp class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvChooseInvoiceResponse:)]) {
WXChooseInvoiceResp *chooseInvoiceResp = (WXChooseInvoiceResp *) resp;
[_delegate managerDidRecvChooseInvoiceResponse:chooseInvoiceResp];
}
} else if ([resp isKindOfClass:[WXSubscribeMsgResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvSubscribeMsgResponse:)]) {
[_delegate managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *) resp];
}
WXSubscribeMsgResp *subscribeMsgResp = (WXSubscribeMsgResp *) resp;
NSDictionary *subMsgResult = @{
@"openid": subscribeMsgResp.openId,
@"templateId": subscribeMsgResp.templateId,
@"action": subscribeMsgResp.action,
@"reserved": subscribeMsgResp.reserved,
@"scene": @(subscribeMsgResp.scene),
};
[fluwxMethodChannel invokeMethod:@"onSubscribeMsgResp" arguments:subMsgResult];
} else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvLaunchMiniProgram:)]) {
[_delegate managerDidRecvLaunchMiniProgram:(WXLaunchMiniProgramResp *) resp];
}
WXLaunchMiniProgramResp *miniProgramResp = (WXLaunchMiniProgramResp *) resp;
NSDictionary *commonResult = @{
description: miniProgramResp.description == nil ? @"" : miniProgramResp.description,
errStr: miniProgramResp.errStr == nil ? @"" : miniProgramResp.errStr,
errCode: @(miniProgramResp.errCode),
type: @(miniProgramResp.type),
};
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:commonResult];
if (miniProgramResp.extMsg != nil) {
result[@"extMsg"] = miniProgramResp.extMsg;
}
// @"extMsg":miniProgramResp.extMsg == nil?@"":miniProgramResp.extMsg
[fluwxMethodChannel invokeMethod:@"onLaunchMiniProgramResponse" arguments:result];
} else if ([resp isKindOfClass:[WXInvoiceAuthInsertResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvInvoiceAuthInsertResponse:)]) {
[_delegate managerDidRecvInvoiceAuthInsertResponse:(WXInvoiceAuthInsertResp *) resp];
}
} else if ([resp isKindOfClass:[WXNontaxPayResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvNonTaxpayResponse:)]) {
[_delegate managerDidRecvNonTaxpayResponse:(WXNontaxPayResp *) resp];
}
} else if ([resp isKindOfClass:[WXPayInsuranceResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvPayInsuranceResponse:)]) {
[_delegate managerDidRecvPayInsuranceResponse:(WXPayInsuranceResp *) resp];
}
} else if ([resp isKindOfClass:[PayResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvPaymentResponse:)]) {
[_delegate managerDidRecvPaymentResponse:(PayResp *) resp];
}
PayResp *payResp = (PayResp *) resp;
NSDictionary *result = @{
description: [FluwxStringUtil nilToEmpty:payResp.description],
errStr: [FluwxStringUtil nilToEmpty:resp.errStr],
errCode: @(payResp.errCode),
type: @(payResp.type),
@"returnKey": payResp.returnKey == nil ? @"" : payResp.returnKey,
};
[fluwxMethodChannel invokeMethod:@"onPayResponse" arguments:result];
} else if ([resp isKindOfClass:[WXOpenBusinessWebViewResp class]]) {
WXOpenBusinessWebViewResp *businessResp = (WXOpenBusinessWebViewResp *) resp;
NSDictionary *result = @{
description: [FluwxStringUtil nilToEmpty:businessResp.description],
errStr: [FluwxStringUtil nilToEmpty:resp.errStr],
errCode: @(businessResp.errCode),
type: @(businessResp.type),
@"resultInfo": businessResp.result,
@"businessType": @(businessResp.businessType),
};
[fluwxMethodChannel invokeMethod:@"onAutoDeductResponse" arguments:result];
}
}
- (void)onReq:(BaseReq *)req {
if ([req isKindOfClass:[GetMessageFromWXReq class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvGetMessageReq:)]) {
GetMessageFromWXReq *getMessageReq = (GetMessageFromWXReq *) req;
[_delegate managerDidRecvGetMessageReq:getMessageReq];
}
} else if ([req isKindOfClass:[ShowMessageFromWXReq class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvShowMessageReq:)]) {
ShowMessageFromWXReq *showMessageReq = (ShowMessageFromWXReq *) req;
[_delegate managerDidRecvShowMessageReq:showMessageReq];
}
} else if ([req isKindOfClass:[LaunchFromWXReq class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvLaunchFromWXReq:)]) {
LaunchFromWXReq *launchReq = (LaunchFromWXReq *) req;
[_delegate managerDidRecvLaunchFromWXReq:launchReq];
}
}
}
@end
\ No newline at end of file
//
// Created by mo on 2020/3/7.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
@class FluwxStringUtil;
@interface FluwxShareHandler : NSObject
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar;
- (void)handleShare:(FlutterMethodCall *)call result:(FlutterResult)result;
@end
差异被折叠。
//
// Created by mo on 2020/3/7.
//
#import <Foundation/Foundation.h>
@interface FluwxStringUtil : NSObject
+ (BOOL)isBlank:(NSString *)string;
+ (NSString *)nilToEmpty:(NSString *)string;
@end
\ No newline at end of file
//
// Created by mo on 2020/3/7.
//
#import "FluwxStringUtil.h"
@implementation FluwxStringUtil
+ (BOOL)isBlank:(NSString *)string {
if (string == nil) {
return YES;
}
if ([string isKindOfClass:[NSNull class]]) {
return YES;
}
return [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0;
}
+ (NSString *)nilToEmpty:(NSString *)string {
return string == nil ? @"" : string;
}
@end
\ No newline at end of file
//
// Created by mo on 2020/3/8.
//
#import <Foundation/Foundation.h>
#define JavaNotFound -1
@interface NSString (Wrapper)
/** Return the char value at the specified index. */
- (unichar)charAt:(int)index;
/**
* Compares two strings lexicographically.
* the value 0 if the argument string is equal to this string;
* a value less than 0 if this string is lexicographically less than the string argument;
* and a value greater than 0 if this string is lexicographically greater than the string argument.
*/
- (int)compareTo:(NSString *)anotherString;
- (int)compareToIgnoreCase:(NSString *)str;
- (BOOL)contains:(NSString *)str;
- (BOOL)startsWith:(NSString *)prefix;
- (BOOL)endsWith:(NSString *)suffix;
- (BOOL)equals:(NSString *)anotherString;
- (BOOL)equalsIgnoreCase:(NSString *)anotherString;
- (int)indexOfChar:(unichar)ch;
- (int)indexOfChar:(unichar)ch fromIndex:(int)index;
- (int)indexOfString:(NSString *)str;
- (int)indexOfString:(NSString *)str fromIndex:(int)index;
- (int)lastIndexOfChar:(unichar)ch;
- (int)lastIndexOfChar:(unichar)ch fromIndex:(int)index;
- (int)lastIndexOfString:(NSString *)str;
- (int)lastIndexOfString:(NSString *)str fromIndex:(int)index;
- (NSString *)substringFromIndex:(NSInteger)beginIndex
toIndex:(NSInteger)endIndex;
- (NSString *)toLowerCase;
- (NSString *)toUpperCase;
- (NSString *)trim;
- (NSString *)replaceAll:(NSString *)origin with:(NSString *)replacement;
- (NSArray *)split:(NSString *)separator;
@end
//
// Created by mo on 2020/3/8.
//
#import "NSStringWrapper.h"
@implementation NSString (Wrapper)
/** Java-like method. Returns the char value at the specified index. */
- (unichar)charAt:(int)index {
return [self characterAtIndex:index];
}
/**
* Java-like method. Compares two strings lexicographically.
* the value 0 if the argument string is equal to this string;
* a value less than 0 if this string is lexicographically less than the string argument;
* and a value greater than 0 if this string is lexicographically greater than the string argument.
*/
- (int)compareTo:(NSString *)anotherString {
return (int)[self compare:anotherString];
}
/** Java-like method. Compares two strings lexicographically, ignoring case differences. */
- (int)compareToIgnoreCase:(NSString *)str {
return (int)[self compare:str options:NSCaseInsensitiveSearch];
}
/** Java-like method. Returns true if and only if this string contains the specified sequence of char values. */
- (BOOL)contains:(NSString *)str {
NSRange range = [self rangeOfString:str];
return (range.location != NSNotFound);
}
- (BOOL)startsWith:(NSString *)prefix {
return [self hasPrefix:prefix];
}
- (BOOL)endsWith:(NSString *)suffix {
return [self hasSuffix:suffix];
}
- (BOOL)equals:(NSString *)anotherString {
return [self isEqualToString:anotherString];
}
- (BOOL)equalsIgnoreCase:(NSString *)anotherString {
return [[self toLowerCase] equals:[anotherString toLowerCase]];
}
- (int)indexOfChar:(unichar)ch {
return [self indexOfChar:ch fromIndex:0];
}
- (int)indexOfChar:(unichar)ch fromIndex:(int)index {
int len = (int)self.length;
for (int i = index; i < len; ++i) {
if (ch == [self charAt:i]) {
return i;
}
}
return JavaNotFound;
}
- (int)indexOfString:(NSString *)str {
NSRange range = [self rangeOfString:str];
if (range.location == NSNotFound) {
return JavaNotFound;
}
return (int)range.location;
}
- (int)indexOfString:(NSString *)str fromIndex:(int)index {
NSRange fromRange = NSMakeRange(index, self.length - index);
NSRange range = [self rangeOfString:str options:NSLiteralSearch range:fromRange];
if (range.location == NSNotFound) {
return JavaNotFound;
}
return (int)range.location;
}
- (int)lastIndexOfChar:(unichar)ch {
int len = (int)self.length;
for (int i = len - 1; i >= 0; --i) {
if ([self charAt:i] == ch) {
return i;
}
}
return JavaNotFound;
}
- (int)lastIndexOfChar:(unichar)ch fromIndex:(int)index {
int len = (int)self.length;
if (index >= len) {
index = len - 1;
}
for (int i = index; i >= 0; --i) {
if ([self charAt:i] == ch) {
return index;
}
}
return JavaNotFound;
}
- (int)lastIndexOfString:(NSString *)str {
NSRange range = [self rangeOfString:str options:NSBackwardsSearch];
if (range.location == NSNotFound) {
return JavaNotFound;
}
return (int)range.location;
}
- (int)lastIndexOfString:(NSString *)str fromIndex:(int)index {
NSRange fromRange = NSMakeRange(0, index);
NSRange range = [self rangeOfString:str options:NSBackwardsSearch range:fromRange];
if (range.location == NSNotFound) {
return JavaNotFound;
}
return (int)range.location;
}
- (NSString *)substringFromIndex:(NSInteger)beginIndex
toIndex:(NSInteger)endIndex {
if (endIndex <= beginIndex) {
return @"";
}
NSRange range = NSMakeRange(beginIndex, endIndex - beginIndex);
return [self substringWithRange:range];
}
- (NSString *)toLowerCase {
return [self lowercaseString];
}
- (NSString *)toUpperCase {
return [self uppercaseString];
}
- (NSString *)trim {
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (NSString *)replaceAll:(NSString *)origin with:(NSString *)replacement {
return [self stringByReplacingOccurrencesOfString:origin withString:replacement];
}
- (NSArray *)split:(NSString *)separator {
return [self componentsSeparatedByString:separator];
}
@end
//
// SendMessageToWXReq+requestWithTextOrMediaMessage.h
// SDKSample
//
// Created by Jeason on 15/7/14.
//
//
#import "WXApiObject.h"
@interface SendMessageToWXReq (requestWithTextOrMediaMessage)
+ (SendMessageToWXReq *)requestWithText:(NSString *)text
OrMediaMessage:(WXMediaMessage *)message
bText:(BOOL)bText
InScene:(enum WXScene)scene;
@end
//
// SendMessageToWXReq+requestWithTextOrMediaMessage.m
// SDKSample
//
// Created by Jeason on 15/7/14.
//
//
#import "SendMessageToWXReq+requestWithTextOrMediaMessage.h"
@implementation SendMessageToWXReq (requestWithTextOrMediaMessage)
+ (SendMessageToWXReq *)requestWithText:(NSString *)text
OrMediaMessage:(WXMediaMessage *)message
bText:(BOOL)bText
InScene:(enum WXScene)scene {
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = bText;
req.scene = scene;
if (bText)
req.text = text;
else
req.message = message;
return req;
}
@end
//
// Created by mo on 2020/3/7.
//
#import <Foundation/Foundation.h>
@interface ThumbnailHelper : NSObject
+ (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength isPNG:(BOOL)isPNG;
@end
\ No newline at end of file
//
// Created by mo on 2020/3/7.
//
#import "ThumbnailHelper.h"
@implementation ThumbnailHelper
+ (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength isPNG:(BOOL)isPNG {
// Compress by quality
CGFloat compression = 1;
NSData *data = UIImageJPEGRepresentation(image, compression);
if (data.length < maxLength) return image;
CGFloat max = 1;
CGFloat min = 0;
for (int i = 0; i < 6; ++i) {
compression = (max + min) / 2;
data = UIImageJPEGRepresentation(image, compression);
if (data.length < maxLength * 0.9) {
min = compression;
} else if (data.length > maxLength) {
max = compression;
} else {
break;
}
}
UIImage *resultImage;
if (isPNG) {
NSData *tmp = UIImagePNGRepresentation([UIImage imageWithData:data]);
resultImage = [UIImage imageWithData:tmp];
} else {
resultImage = [UIImage imageWithData:data];
}
if (data.length < maxLength) return resultImage;
// Compress by size
NSUInteger lastDataLength = 0;
while (data.length > maxLength && data.length != lastDataLength) {
lastDataLength = data.length;
CGFloat ratio = (CGFloat) maxLength / data.length;
CGSize size = CGSizeMake((NSUInteger) (resultImage.size.width * sqrtf(ratio)),
(NSUInteger) (resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank
UIGraphicsBeginImageContext(size);
[resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
data = UIImageJPEGRepresentation(resultImage, compression);
}
return resultImage;
}
- (UIImage *)scaleFromImage:(UIImage *)image width:(CGSize)newSize {
CGSize imageSize = image.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
if (width <= newSize.width && height <= newSize.height) {
return image;
}
if (width == 0 || height == 0) {
return image;
}
CGFloat widthFactor = newSize.width / width;
CGFloat heightFactor = newSize.height / height;
CGFloat scaleFactor = (widthFactor < heightFactor ? widthFactor : heightFactor);
CGFloat scaledWidth = width * scaleFactor;
CGFloat scaledHeight = height * scaleFactor;
CGSize targetSize = CGSizeMake(scaledWidth, scaledHeight);
UIGraphicsBeginImageContext(targetSize);
[image drawInRect:CGRectMake(0, 0, scaledWidth, scaledHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
\ No newline at end of file
//
// Created by mo on 2020/3/7.
//
#import <Foundation/Foundation.h>
#import "WXApiObject.h"
#import "FluwxResponseHandler.h"
NS_ASSUME_NONNULL_BEGIN
@interface WXApiRequestHandler : NSObject
+ (void)sendText:(NSString *)text
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendImageData:(NSData *)imageData
TagName:(NSString *)tagName
MessageExt:(NSString *)messageExt
Action:(NSString *)action
ThumbImage:(UIImage *)thumbImage
InScene:(enum WXScene)scene
title:(NSString *)title
description:(NSString *)description
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendLinkURL:(NSString *)urlString
TagName:(NSString *)tagName
Title:(NSString *)title
Description:(NSString *)description
ThumbImage:(UIImage *)thumbImage
MessageExt:(NSString *)messageExt
MessageAction:(NSString *)messageAction
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendMusicURL:(NSString *)musicURL
dataURL:(NSString *)dataURL
MusicLowBandUrl:(NSString *)musicLowBandUrl
MusicLowBandDataUrl:(NSString *)musicLowBandDataUrl
Title:(NSString *)title
Description:(NSString *)description
ThumbImage:(UIImage *)thumbImage
MessageExt:(NSString *)messageExt
MessageAction:(NSString *)messageAction
TagName:(NSString *)tagName
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendVideoURL:(NSString *)videoURL
VideoLowBandUrl:(NSString *)videoLowBandUrl
Title:(NSString *)title
Description:(NSString *)description
ThumbImage:(UIImage *)thumbImage
MessageExt:(NSString *)messageExt
MessageAction:(NSString *)messageAction
TagName:(NSString *)tagName
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendEmotionData:(NSData *)emotionData
ThumbImage:(UIImage *)thumbImage
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendFileData:(NSData *)fileData
fileExtension:(NSString *)extension
Title:(NSString *)title
Description:(NSString *)description
ThumbImage:(UIImage *)thumbImage
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendMiniProgramWebpageUrl:(NSString *)webpageUrl
userName:(NSString *)userName
path:(NSString *)path
title:(NSString *)title
Description:(NSString *)description
ThumbImage:(UIImage *)thumbImage
hdImageData:(NSData *)hdImageData
withShareTicket:(BOOL)withShareTicket
miniProgramType:(WXMiniProgramType)programType
MessageExt:(NSString *)messageExt
MessageAction:(NSString *)messageAction
TagName:(NSString *)tagName
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)launchMiniProgramWithUserName:(NSString *)userName
path:(NSString *)path
type:(WXMiniProgramType)miniProgramType
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendAppContentData:(NSData *)data
ExtInfo:(NSString *)info
ExtURL:(NSString *)url
Title:(NSString *)title
Description:(NSString *)description
MessageExt:(NSString *)messageExt
MessageAction:(NSString *)action
ThumbImage:(UIImage *)thumbImage
InScene:(enum WXScene)scene
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)addCardsToCardPackage:(NSArray *)cardIds cardExts:(NSArray *)cardExts
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendAuthRequestScope:(NSString *)scope
State:(NSString *)state
OpenID:(NSString *)openID
InViewController:(UIViewController *)viewController
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendAuthRequestScope:(NSString *)scope
State:(NSString *)state
OpenID:(NSString *)openID
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)chooseCard:(NSString *)appid
cardSign:(NSString *)cardSign
nonceStr:(NSString *)nonceStr
signType:(NSString *)signType
timestamp:(UInt32)timestamp
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)openUrl:(NSString *)url
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)chooseInvoice:(NSString *)appid
cardSign:(NSString *)cardSign
nonceStr:(NSString *)nonceStr
signType:(NSString *)signType
timestamp:(UInt32)timestamp
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendPayment:(NSString *)appId
PartnerId:(NSString *)partnerId
PrepayId:(NSString *)prepayId
NonceStr:(NSString *)nonceStr
Timestamp:(UInt32)timestamp
Package:(NSString *)package
Sign:(NSString *)sign
completion:(void (^ __nullable)(BOOL success))completion;
@end
NS_ASSUME_NONNULL_END
差异被折叠。
//
// WXMediaMessage+messageConstruct.h
// SDKSample
//
// Created by Jeason on 15/7/14.
//
//
#import "WXApiObject.h"
@interface WXMediaMessage (messageConstruct)
+ (WXMediaMessage *)messageWithTitle:(NSString *)title
Description:(NSString *)description
Object:(id)mediaObject
MessageExt:(NSString *)messageExt
MessageAction:(NSString *)action
ThumbImage:(UIImage *)thumbImage
MediaTag:(NSString *)tagName;
@end
//
// WXMediaMessage+messageConstruct.m
// SDKSample
//
// Created by Jeason on 15/7/14.
//
//
#import "WXMediaMessage+messageConstruct.h"
@implementation WXMediaMessage (messageConstruct)
+ (WXMediaMessage *)messageWithTitle:(NSString *)title
Description:(NSString *)description
Object:(id)mediaObject
MessageExt:(NSString *)messageExt
MessageAction:(NSString *)action
ThumbImage:(UIImage *)thumbImage
MediaTag:(NSString *)tagName {
WXMediaMessage *message = [WXMediaMessage message];
message.title = title;
message.description = description;
message.mediaObject = mediaObject;
message.messageExt = messageExt;
message.messageAction = action;
message.mediaTagName = tagName;
[message setThumbImage:thumbImage];
return message;
}
@end
...@@ -5,18 +5,27 @@ ...@@ -5,18 +5,27 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'fluwx' s.name = 'fluwx'
s.version = '0.0.1' s.version = '0.0.1'
s.summary = 'A new Flutter plugin.' s.summary = 'A new Flutter plugin for Wechat SDK.'
s.description = <<-DESC s.description = <<-DESC
A new Flutter plugin. A new Flutter plugin for Wechat SDK.
DESC DESC
s.homepage = 'http://example.com' s.homepage = 'https://github.com/OpenFlutter/fluwx'
s.license = { :file => '../LICENSE' } s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email@example.com' } s.author = { 'JarvanMo' => 'jarvan.mo@gmail.com' }
s.source = { :path => '.' } s.source = { :path => '.' }
s.source_files = 'Classes/**/*' s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h' s.public_header_files = 'Classes/**/*.h'
s.static_framework = true
s.dependency 'Flutter' s.dependency 'Flutter'
s.platform = :ios, '8.0' s.dependency 'WechatOpenSDK', '1.8.6.2'
# s.dependency 'OpenWeChatSDK','~> 1.8.3+10'
# s.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/Headers/Public/#{s.name}" }
s.frameworks = ["SystemConfiguration", "CoreTelephony","WebKit"]
s.libraries = ["z", "sqlite3.0", "c++"]
s.preserve_paths = 'Lib/*.a'
s.vendored_libraries = "**/*.a"
s.ios.deployment_target = '8.0'
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported. # Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' } s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
......
...@@ -48,15 +48,13 @@ class WeChatShareTextModel implements WeChatShareBaseModel { ...@@ -48,15 +48,13 @@ class WeChatShareTextModel implements WeChatShareBaseModel {
/// ///
/// the default value is [MINI_PROGRAM_TYPE_RELEASE] /// the default value is [MINI_PROGRAM_TYPE_RELEASE]
/// ///[hdImagePath] only works on iOS, not sure the relationship between [thumbnail] and [hdImagePath].
/// [thumbnail] is mapped to hdImagePath in iOS and in android is thumbnail
///
class WeChatShareMiniProgramModel implements WeChatShareBaseModel { class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
final String webPageUrl; final String webPageUrl;
final WXMiniProgramType miniProgramType; final WXMiniProgramType miniProgramType;
final String userName; final String userName;
final String path; final String path;
final WeChatImage hdImagePath;
final String title; final String title;
final String description; final String description;
...@@ -73,7 +71,9 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel { ...@@ -73,7 +71,9 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
this.title, this.title,
this.description, this.description,
this.withShareTicket: false, this.withShareTicket: false,
this.thumbnail}) this.thumbnail,
this.hdImagePath
})
: assert(miniProgramType != null), : assert(miniProgramType != null),
assert(webPageUrl != null && webPageUrl.isNotEmpty), assert(webPageUrl != null && webPageUrl.isNotEmpty),
assert(userName != null && userName.isNotEmpty), assert(userName != null && userName.isNotEmpty),
...@@ -89,7 +89,8 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel { ...@@ -89,7 +89,8 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
"title": title, "title": title,
"description": description, "description": description,
"withShareTicket": withShareTicket, "withShareTicket": withShareTicket,
_thumbnail: thumbnail?.toMap() _thumbnail: thumbnail?.toMap(),
"hdImagePath":hdImagePath?.toMap()
}; };
} }
} }
......
...@@ -32,10 +32,12 @@ void main() { ...@@ -32,10 +32,12 @@ void main() {
withShareTicket: true, withShareTicket: true,
thumbnail: thumbnail, thumbnail: thumbnail,
userName: "userName", userName: "userName",
path: "path"); path: "path",
hdImagePath: thumbnail);
expect(model.webPageUrl, "http://openflutter.dev"); expect(model.webPageUrl, "http://openflutter.dev");
expect(model.miniProgramType, WXMiniProgramType.PREVIEW); expect(model.miniProgramType, WXMiniProgramType.PREVIEW);
expect(model.thumbnail, thumbnail); expect(model.thumbnail, thumbnail);
expect(model.hdImagePath, thumbnail);
expect(model.path, "path"); expect(model.path, "path");
expect(model.userName, "userName"); expect(model.userName, "userName");
}); });
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论