支付宝APP支付IOS手机端java后台版

时间:2024-06-20 13:03:50

版权声明:http://blog.****.net/u012131769/article/details/76639527#t8

转载:http://blog.****.net/u012131769/article/details/76639527#t8

支付宝APP支付(IOS手机端+java后台)版

0.介绍预览

针对需要在IOS手机上接入原生微信支付宝场景,调用支付宝。如图:

支付宝APP支付IOS手机端java后台版              支付宝APP支付IOS手机端java后台版

1.资料准备

1.1 账号注册

打开https://openhome.alipay.com,注册支付宝开放平台开发者账号

1.2 开发者认证

登录,进入开发者中心,进行开发者资质认证,并创建移动应用。

1.3 签约应用

创建应用后上传相关资料,上线应用并通过审核。审核通过后点击应用,进行签约,此步骤不能省略,否则或报ISV权限不足。

支付宝APP支付IOS手机端java后台版

1.4 应用配置

打开应用信息,配置一下内容,接口签名可下载支付宝签名验签工具进行生成,生成完成后将公钥复制到平台上。

支付宝APP支付IOS手机端java后台版

2.Java后台开发

添加依赖

生成统一订单

异步通知处理

3.IOS客户端开发

导入支付宝开发包

支付宝APP支付IOS手机端java后台版

添加URL Types

支付宝APP支付IOS手机端java后台版

在需要调用支付宝的地方实现方法

[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:@""]){
// 支付成功,更新用户信息
[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.点击支付按钮

 - (void)alipayBtnClick{

     [HWSShopCartHttpRequst requestOrderPayUseAliPayWithOrderNo:self.orderNo Success:^(NSString *code, NSDictionary *dataDic) {

        NSString *paramsStr = dataDic[@"requestParams"];
[[AlipaySDK defaultService] payOrder:paramsStr fromScheme:kAppScheme callback:^(NSDictionary *resultDic) {
NSLog(@"reslut = %@",resultDic);
}]; } andFailure:^{ }]; }

2.请求内部封装的代码实例

 /**
* 统一下单支付宝支付
* @param orderNo 订单编号
*
* @param success 成功
* @param failure 失败
*/
+ (void)requestOrderPayUseAliPayWithOrderNo:(NSString*)orderNo
Success:(void (^)(NSString *code,NSDictionary *dataDic))success andFailure:(void(^)(void))failure
{ [KSHttpRequest post:[NSString stringWithFormat:@"%@%@",HOST,aliPay] parameters:@{@"orderNo":orderNo} success:^(id result) { if ([result[@"code"] isEqualToString:@""]) { NSLog(@"%@",result); NSDictionary *dataDic = result[@"data"];
success(result[@"code"],dataDic); }else{
failure();
[MBProgressHUD showMessage:result[@"message"]];
} } failure:^(NSError *error) {
failure();
}];
}

//待续

https://docs.open.alipay.com/204/105295/