iOS 支付宝支付
要设置info 文件
导入依赖库 看官方文档
还要设置
-(void)zhifubao
{
/*============================================================================*/
/*=======================需要填写商户app申请的===================================*/
/*============================================================================*/
NSString *partner = PartnerID; //合作身份者id,以2088开头的16位纯数字
NSString *seller = SellerID; //收款支付宝账号
NSString *privateKey = PartnerPrivKey; //商户私钥,自助生成 没有查看支付宝帮助文档里怎么生成
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
//partner和seller获取失败,提示
if ([partner length] == 0 ||
[seller length] == 0 ||
[privateKey length] == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"缺少partner或者seller或者私钥。"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
return;
}
/*
* 生成订单信息及签名
*/
//将商品信息赋予Order的成员变量
Order *order = [[Order alloc] init];
order.partner = partner; //商户ID
order.seller = seller; //收款支付宝账号
order.tradeNO = @""; //订单ID(由商家自行制定)
order.productName =@""; //商品标题
order.productDescription =@""; //商品描述
order.amount =@""; //商品价格(重要)
order.notifyURL = @"; //回调URL(通知服务器端交易结果)(重要)
order.service = @"mobile.securitypay.pay";
order.paymentType = @"1";
order.inputCharset = @"utf-8";
order.itBPay = @"30m";
order.showUrl = @"m.alipay.com";
// 应用注册scheme, 在AlipayDEMO-Info.plist定义URL types
NSString *appScheme = @"alisdkdemo";
//将商品信息拼接成字符串
NSString *orderSpec = [order description];
NSLog(@"orderSpec = %@",orderSpec);
//获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
id<DataSigner> signer = CreateRSADataSigner(privateKey); //通过私钥创建签名
NSString *signedString = [signer signString:orderSpec]; //将订单信息签名
//将签名成功字符串格式化为订单字符串,请严格按照该格式
NSString *orderString = nil;
if (signedString != nil) {
orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"", orderSpec, signedString, @"RSA"];
//支付订单,如果安装有支付宝钱包客户端则直接进入客户端,否则进入网页支付
[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
NSLog(@"%@",resultDic);
if ([[resultDic objectForKeyedSubscript:@"resultStatus"]isEqualToString:@"9000"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"返回个人中心" object:nil];
[self.navigationController popToRootViewControllerAnimated:YES];
}else
{
[self tishi:@"支付失败,请重新支付"];
}
}];
}
}