Skip to content

Commit

Permalink
add calback in ios
Browse files Browse the repository at this point in the history
  • Loading branch information
charleyw committed Dec 26, 2015
1 parent b8229c7 commit db0bfb7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
13 changes: 13 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@
</feature>
</config-file>

<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<array>
<dict>
<key>CFBundleURLName</key>
<string>alipay</string>
<key>CFBundleURLSchemes</key>
<array>
<string>$PARTNER_ID</string>

This comment has been minimized.

Copy link
@jinMaoHuiHui

jinMaoHuiHui Jan 6, 2016

scheme能不能设成一个cordova参数输入?partner是数字,iOS 提交 App 时报错:URL schemes need to begin with an alphabetic character, ...

This comment has been minimized.

Copy link
@charleyw

charleyw Jan 6, 2016

Author Owner

好吧,我改了之后还没提交过Appstore,谢谢反馈,我马上改一下。
我给它前面附加一点内容吧。
不给参数输入的原因是,不是每一个人都懂URL scheme,我想尽量减少暴露这些东西。

</array>
</dict>
</array>
</config-file>

<framework src="CoreTelephony.framework" weak="true" />
<framework src="Security.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
Expand Down
1 change: 1 addition & 0 deletions src/ios/AlipayPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@property(nonatomic,strong)NSString *partner;
@property(nonatomic,strong)NSString *seller;
@property(nonatomic,strong)NSString *privateKey;
@property(nonatomic,strong)NSString *currentCallbackId;

- (void) pay:(CDVInvokedUrlCommand*)command;
@end
24 changes: 20 additions & 4 deletions src/ios/AlipayPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ -(void)pluginInitialize{

- (void) pay:(CDVInvokedUrlCommand*)command
{
self.currentCallbackId = command.callbackId;

/*
*商户的唯一的parnter和seller。
Expand Down Expand Up @@ -45,7 +46,6 @@ - (void) pay:(CDVInvokedUrlCommand*)command
NSString *subject = [args objectForKey:@"subject"];
NSString *body = [args objectForKey:@"body"];
NSString *price = [args objectForKey:@"price"];
NSString *fromUrlScheme = [args objectForKey:@"fromUrlScheme"];
NSString *notifyUrl = [args objectForKey:@"notifyUrl"];

Order *order = [[Order alloc] init];
Expand Down Expand Up @@ -77,11 +77,11 @@ - (void) pay:(CDVInvokedUrlCommand*)command
orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
orderSpec, signedString, @"RSA"];

[[AlipaySDK defaultService] payOrder:orderString fromScheme:fromUrlScheme callback:^(NSDictionary *resultDic) {
[[AlipaySDK defaultService] payOrder:orderString fromScheme:self.partner callback:^(NSDictionary *resultDic) {
if ([[resultDic objectForKey:@"resultStatus"] isEqual: @"9000"]) {
[self successWithCallbackID:command.callbackId withMessage:@"支付成功"];
[self successWithCallbackID:self.currentCallbackId withMessage:@"支付成功"];
} else {
[self failWithCallbackID:command.callbackId withMessage:@"支付失败"];
[self failWithCallbackID:self.currentCallbackId withMessage:@"支付失败"];
}

NSLog(@"reslut = %@",resultDic);
Expand All @@ -90,6 +90,22 @@ - (void) pay:(CDVInvokedUrlCommand*)command
}
}

- (void)handleOpenURL:(NSNotification *)notification
{
NSURL* url = [notification object];

if ([url isKindOfClass:[NSURL class]] && [url.scheme isEqualToString:self.partner])
{
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
if ([[resultDic objectForKey:@"resultStatus"] isEqual: @"9000"]) {
[self successWithCallbackID:self.currentCallbackId withMessage:@"支付成功"];
} else {
[self failWithCallbackID:self.currentCallbackId withMessage:@"支付失败"];
}
}];
}
}

- (void)successWithCallbackID:(NSString *)callbackID withMessage:(NSString *)message
{
CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
Expand Down

0 comments on commit db0bfb7

Please sign in to comment.