Commit 2862c216 authored by xgz's avatar xgz

修改支付宝插件ios

parent a7916ee1
......@@ -8,8 +8,131 @@
#import "alipay_no_utdid-Swift.h"
#endif
#import <AlipaySDK/AlipaySDK.h>
__weak AlipayNoUtdidPlugin* __tobiasPlugin;
@interface AlipayNoUtdidPlugin()
@property (readwrite,copy,nonatomic) FlutterResult callback;
@end
@implementation AlipayNoUtdidPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftAlipayNoUtdidPlugin registerWithRegistrar:registrar];
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"alipay_no_utdid"
binaryMessenger:[registrar messenger]];
AlipayNoUtdidPlugin* instance = [[AlipayNoUtdidPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
[registrar addApplicationDelegate:instance];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"pay" isEqualToString:call.method]) {
[self pay:call result:result];
} else if([@"version" isEqualToString:call.method]){
[self getVersion:call result:result];
}else if([@"isInstalled" isEqualToString:call.method]){
[self _isAliPayInstalled:call result:result];
}else{
result(FlutterMethodNotImplemented);
}
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [self handleOpenURL:url];
}
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *, id> *)options {
return [self handleOpenURL:url];
}
+(BOOL)handleOpenURL:(NSURL*)url{
if(!__tobiasPlugin)return NO;
return [__tobiasPlugin handleOpenURL:url];
}
-(BOOL)handleOpenURL:(NSURL*)url{
if ([url.host isEqualToString:@"safepay"]) {
__weak AlipayNoUtdidPlugin* __self = self;
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
[__self onPayResultReceived:resultDic];
}];
return YES;
}
return NO;
}
-(void)onPayResultReceived:(NSDictionary*)resultDic{
if(self.callback!=nil){
NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:resultDic];
[mutableDictionary setValue:@"iOS" forKey:@"platform"];
self.callback(mutableDictionary);
self.callback = nil;
}
}
-(void) pay:(FlutterMethodCall*)call result:(FlutterResult)result{
NSString* urlScheme = [self fetchUrlScheme];
if(!urlScheme){
result([FlutterError errorWithCode:@"AliPay UrlScheme Not Found" message:@"Config AliPay First" details:nil]);
return;
}
[self _pay:call result:result urlScheme:urlScheme];
}
-(void) _pay:(FlutterMethodCall*)call result:(FlutterResult)result urlScheme:(NSString *)urlScheme{
self.callback = result;
__weak AlipayNoUtdidPlugin* __self = self;
[[AlipaySDK defaultService] payOrder:call.arguments[@"order"] fromScheme:urlScheme callback:^(NSDictionary *resultDic) {
[__self onPayResultReceived:resultDic];
}];
}
-(void) getVersion:(FlutterMethodCall*)call result:(FlutterResult)result{
NSString *version = [AlipaySDK defaultService].currentVersion;
if(version == nil){
version = @"";
}
result(version);
}
-(NSString*)fetchUrlScheme{
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSArray* types = infoDic[@"CFBundleURLTypes"];
for(NSDictionary* dic in types){
if([@"alipay" isEqualToString:dic[@"CFBundleURLName"]]){
return dic[@"CFBundleURLSchemes"][0];
}
}
return nil;
}
-(void) _isAliPayInstalled:(FlutterMethodCall*)call result:(FlutterResult)result {
BOOL isAliPayInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]||[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipay://"]];
result(@(isAliPayInstalled));
}
@end
import Flutter
import UIKit
public class SwiftAlipayNoUtdidPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "alipay_no_utdid", binaryMessenger: registrar.messenger())
......
......@@ -14,8 +14,9 @@ A new Flutter plugin.
s.author = { 'Your Company' => 'email@example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.static_framework = true
s.dependency 'Flutter'
s.platform = :ios, '8.0'
s.dependency 'PingppAlipaySDKNoUTDID', '~> 15.8.0'
# 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' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment