1:先与支付宝签约,获得商户ID(partner)和账号ID(seller)
2:下载相应的公钥私钥文件(加密签名用)
3:下载支付宝SDK
4:生成订单信息
5:调用支付宝客户端,由支付宝客户端跟支付宝安全服务器打交道
6:支付完毕后返回支付结果给商户客户端和服务 , SDK里有集成支付宝功能的一个Demo> 集成支付功能的具体操作方式,可以参考Demo
//生成订单信息及签名请求参数没有 return_URL这个参数,商户可以根据自身情况选择签名方法
NSString *appScheme=@"Practice";
NSString * orderInfo=[self getOrderInfo:indexPath.row];
NSString * signedStr=[self doRsa:orderInfo];
NSString*orderString=[NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",orderInfo,signedStr,@"RSA"];
[AlixLibService payOrder:orderString AndScheme:appScheme seletor:_result target:self];
-(NSString *)doRsa:(NSString *)orderInfo
{
idsigner;
signer=CreateRSADataSigner(PartnerPrivKey);
NSString * signedString=[signer signString:orderInfo];
return signedString;
}
-(NSString *)getOrderInfo:(NSInteger)index
{
//点击获取product实例,并初始化订单信息
Pruduct *pruduct=[_dataArray objectAtIndex:index];
AlixPayOrder * order=[[AlixPayOrder alloc]init];
order.partner=PartnerID;
order.seller=SellerID;
//订单ID
order.tradeNO=[self generateTradeNO];
// 商品标题
order.productName=pruduct.subject;
// 商品描述
order.productDescription =pruduct.body;
//商品价格
order.amount=[NSString stringWithFormat:@"%.2f",pruduct.price];
order.notifyURL = @"http%3A%2F%2Fwwww.xxx.com"; //回调URL
return order.description;
}
-(NSString *)generateTradeNO
{
const int N =15;
NSString * sourceString=@"SSSSSSSSSSSSSSSS";
NSMutableString *re=[[NSMutableString alloc]init];
srand(time(0));
for (int i=0; iunsigned index=rand()%[sourceString length];
NSString * s=[sourceString substringWithRange:NSMakeRange(index, 1)];
[re appendString:s];
}
return re;
}
-(void)paymentResultDelegate:(NSString *)result
{
NSLog(@"%@",result);
}