IOS 微信支付宝支付调用详解

2017-09-22  本文已影响0人  iOS小开发

首先关于支付宝跟微信的前期配置我就是不多说了直接进入正题

1.支付宝

通过后台加签,当然这绝对是最好的做法,也是支付宝支持的,自己加签也可以但是最好不要这么做

代码

+(void)aliPay:(NSString *)order{

//order为后台加签的订单

NSString *appScheme = @"bikeAlipay";//回掉到自己app随便设置

// NOTE: 调用支付结果开始支付

[[AlipaySDK defaultService] payOrder:order fromScheme:appScheme callback:^(NSDictionary *resultDic) {

NSLog(@"reslut = %@",resultDic);

NSNotification * notification = [NSNotification notificationWithName:@"alPay" object:[NSString stringWithFormat:@"%@",[resultDic objectForKey:@"resultStatus"]]];

[[NSNotificationCenter defaultCenter] postNotification:notification];

}];

}

微信支付

// 客户端首先发送请求给后台,后台生成prepayid 跟订单信息然后用得到的信息与下面方法对应唤起微信

+(void)WxpayappID:(NSString * )appid

partnerID:(NSString *)partnertid

noncestr:(NSString *)noncestr

package :(NSString *)package

timestamp :(NSString *)timestamp

prepayid:(NSString *)prepayid

sign:(NSString *)sign

{

// 调起微信支付

PayReq *request = [[PayReq alloc] init];

request.partnerId = partnertid;

request.prepayId  = prepayid;

request.package  = package;

request.nonceStr  = noncestr;

request.timeStamp = [timestamp intValue];

//添加签名

request.sign = sign;

[WXApi sendReq:request];

}

上一篇下一篇

猜你喜欢

热点阅读