我们有时候可能会遇到需要接入支付系统的开发需求,常用的 像支付宝、微信支付、银联等,单独集成你懂得,
所以我这里推荐一个集成的SDK:PingXX。
PingXX是支付的集成解决方案,用起来也很简单,但是现在只支持公司企业使用了,对于服务端来说,需要配置回调,
生成key什么的,客户端只需要使用服务端返回的秘钥字符串调用PingXX的SDK,然后配置返回本App的方法即可
这里的charge就是验签秘钥,kUrlScheme是回调地址,也就是你的 bundle id
[Pingpp createPayment:charge viewController:nil appURLScheme:kUrlScheme withCompletion:^(NSString *result, PingppError *error){
if ([result isEqualToString:@"success"]) {
// 支付成功
NSLog(@"支付成功");
[self payResultSuccess];
} else {
// 支付失败或取消
NSLog(@"Error: code=%lu msg=%@", error.code, [error getMsg]);
[self payResultError];
}
}];
下面就是App返回时的回调,我们只需要在这里处理一下就行了, 由于iOS版本不同走的回调方法可能也不同,所以我这里使用了两个方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
BOOL isTrue = false;
//真实环境用
if ([url.description containsString:@"safepay"]) {
isTrue = [Pingpp handleOpenURL:url withCompletion:^(NSString *result, PingppError *error) {
NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
if ([result isEqualToString:@"success"]) {
[resultDic removeObjectForKey:@"result"];
[resultDic setObject:@"success" forKey:@"result"];
} else {
[resultDic removeObjectForKey:@"result"];
[resultDic setObject:@"error" forKey:@"result"];
}
self.window.userInteractionEnabled = YES;
[SVProgressHUD dismiss];
[YONotificationCenter postNotificationName:@"safepayResult" object:self userInfo:resultDic];
}];
}
//测试用
if ([url.description containsString:@"pingpp"]) {
isTrue = [Pingpp handleOpenURL:url withCompletion:^(NSString *result, PingppError *error) {
if ([result isEqualToString:@"success"]) {
NSLog(@"1回调URL:%@",url.description);
} else {
NSLog(@"2回调URL:%@",url.description);
}
}];
}
return isTrue;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
YOLog(@"回调URL:%@",url.description);
BOOL isTrue = false;
//真实环境用
if ([url.description containsString:@"safepay"]) {
isTrue = [Pingpp handleOpenURL:url withCompletion:^(NSString *result, PingppError *error) {
NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
if ([result isEqualToString:@"success"]) {
[resultDic removeObjectForKey:@"result"];
[resultDic setObject:@"success" forKey:@"result"];
} else {
[resultDic removeObjectForKey:@"result"];
[resultDic setObject:@"error" forKey:@"result"];
NSLog(@"回调URL:1111111");
}
self.window.userInteractionEnabled = YES;
[SVProgressHUD dismiss];
[YONotificationCenter postNotificationName:@"safepayResult" object:self userInfo:resultDic];
}];
}
//测试用
if ([url.description containsString:@"pingpp"]) {
isTrue = [Pingpp handleOpenURL:url withCompletion:^(NSString *result, PingppError *error) {
NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
if ([result isEqualToString:@"success"]) {
NSLog(@"1回调URL:%@",url.description);
[resultDic removeObjectForKey:@"result"];
[resultDic setObject:@"success" forKey:@"result"];
} else {
NSLog(@"2回调URL:%@",url.description);
[resultDic removeObjectForKey:@"result"];
[resultDic setObject:@"error" forKey:@"result"];
}
self.window.userInteractionEnabled = YES;
[SVProgressHUD dismiss];
[YONotificationCenter postNotificationName:@"safepayResult" object:self userInfo:resultDic];
}];
}
return isTrue;
}