版权声明:http://blog.csdn.net/u012131769/article/details/76639527#t8
转载:http://blog.csdn.net/u012131769/article/details/76639527#t8
支付宝APP支付(IOS手机端+java后台)版
0.介绍预览
针对需要在IOS手机上接入原生微信支付宝场景,调用支付宝。如图:
1.资料准备
1.1 账号注册
打开https://openhome.alipay.com,注册支付宝开放平台开发者账号
1.2 开发者认证
登录,进入开发者中心,进行开发者资质认证,并创建移动应用。
1.3 签约应用
创建应用后上传相关资料,上线应用并通过审核。审核通过后点击应用,进行签约,此步骤不能省略,否则或报ISV权限不足。
1.4 应用配置
打开应用信息,配置一下内容,接口签名可下载支付宝签名验签工具进行生成,生成完成后将公钥复制到平台上。
2.Java后台开发
添加依赖
生成统一订单
异步通知处理
3.IOS客户端开发
导入支付宝开发包
添加URL Types
在需要调用支付宝的地方实现方法
[objc] view plain copy print? -(void)aliPay { [MBProgressHUD showMessage:@"跳转中,请稍候"]; NSString *appScheme = @"alisdkdemo"; NSString *userUrlStr = [NSString stringWithFormat:@"%@?sid=%@&account=%@&desc=%@", ALI_PREPAY_URL, self.student.sid,self.payJinE,self.student.nid]; NSURL *url = [NSURL URLWithString:userUrlStr]; // NSLog(@"userUrlStr = %@", userUrlStr); NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) { [MBProgressHUD hideHUD]; // NSLog(@"支付宝支付的response = %@", operation.responseString); NSData *JSONData = [operation.responseString dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *userDict = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil]; NSString *orderString = [userDict objectForKey:@"orderStr"]; self.sign = [userDict objectForKey:@"sign"]; self.ordnum = [userDict objectForKey:@"out_trade_no"]; [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) { NSLog(@"reslut = %@",resultDic); [MBProgressHUD hideHUD]; NSString *resultStatus = [resultDic objectForKey:@"resultStatus"]; if([resultStatus isEqualToString:@"9000"]){ // 支付成功,更新用户信息 [self payDidFinish]; }else{ // 支付失败, [self setupAlertControllerWithTitle:@"支付宝支付结果" messge:@"本次支付未完成,您可以稍后重试!" confirm:@"好的"]; } }]; }failure:^(AFHTTPRequestOperation *operation, NSError *error) { [MBProgressHUD hideHUD]; NSLog(@"发生错误!%@",error); }]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [queue addOperation:operation]; }
个人实例~~
1.点击支付按钮
1 - (void)alipayBtnClick{ 2 3 [HWSShopCartHttpRequst requestOrderPayUseAliPayWithOrderNo:self.orderNo Success:^(NSString *code, NSDictionary *dataDic) { 4 5 NSString *paramsStr = dataDic[@"requestParams"]; 6 [[AlipaySDK defaultService] payOrder:paramsStr fromScheme:kAppScheme callback:^(NSDictionary *resultDic) { 7 NSLog(@"reslut = %@",resultDic); 8 }]; 9 10 } andFailure:^{ 11 12 }]; 13 14 }
2.请求内部封装的代码实例
1 /** 2 * 统一下单支付宝支付 3 * @param orderNo 订单编号 4 * 5 * @param success 成功 6 * @param failure 失败 7 */ 8 + (void)requestOrderPayUseAliPayWithOrderNo:(NSString*)orderNo 9 Success:(void (^)(NSString *code,NSDictionary *dataDic))success andFailure:(void(^)(void))failure 10 { 11 12 [KSHttpRequest post:[NSString stringWithFormat:@"%@%@",HOST,aliPay] parameters:@{@"orderNo":orderNo} success:^(id result) { 13 14 if ([result[@"code"] isEqualToString:@"1000"]) { 15 16 NSLog(@"%@",result); 17 18 NSDictionary *dataDic = result[@"data"]; 19 success(result[@"code"],dataDic); 20 21 }else{ 22 failure(); 23 [MBProgressHUD showMessage:result[@"message"]]; 24 } 25 26 } failure:^(NSError *error) { 27 failure(); 28 }]; 29 }
//待续
https://docs.open.alipay.com/204/105295/