微信支付:
1.装sdk,查看AppID和AppSecret相关信息,
https://www.jianshu.com/p/ddc34f55dc35
2.创建这些是没有支付能力的,需要额外申请,还是根据提示一步步填写,填写完之后会发一封邮件到您的预留的邮箱,然后到商户平台点击打开链接填写资料,最主要的是验证下开户收款账号,
官方说明:
https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_1
二。代码部分
1.注册appID
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//注册APP,这里的字符串就是Wechat URL Scheme里面对应的ID 也是申请回来的ID,必须一致
[WXApi registerApp:@"这里填写申请回来的ID"];
return YES;
}
2.调后台接口
// 把生成的订单信息组装起来传给后台开发人员(后台的事情,接收会掉就行了)
//参数我传了
{
attach = "";//公司
body = "xxxx";//手机号
clientip = "";//xxx
"out_trade_no" = "";//xxx
"total_amount" =; //价格
}
//会掉成功
success{
NSMutableString *stamp = [data objectForKey:@"timestamp"];
//调起微信支付
PayReq* req = [[PayReq alloc] init];
req.partnerId = [data objectForKey:@"partnerid"]; //商家id
req.prepayId = [data objectForKey:@"prepayid"]; //预支付订单
req.nonceStr = [data objectForKey:@"noncestr"]; //随机串,防重发
req.timeStamp = stamp.intValue; //时间戳,防重发
req.package = [data objectForKey:@"package"]; //商家根据财付通文档填写的数据和签名
req.sign = [data objectForKey:@"sign"]; //商家根据微信开放平台文档对数据做的签名
BOOL ret = [WXApi sendReq:request];
if (!ret) {
[self showPopOnFloatingWindowText:@"未检测到微信,请下载最新版本后再点击微信支付"];
}else{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(chenggongAct:) name:@"WXPaySuccess" object:nil];
}
}
解释下意思:
{
"appid" : "wxb4b",微信开放平台审核通过的AppID
"noncestr" : "171127dd056d05e423c8b9e",随机字符串
"package" : "Sign=WXPay", 固定值
"partnerid" : "130", 微信支付分配的商户ID
"prepayid" : "wx201609291601", 预支付交易会话ID
"sign" : "684371081C049B6017641", 签名,除了sign,剩下6个组合的再次签名字符串
"timestamp" : 147513 当前时间
}
3.Appdelegate 从微信回到app
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [WXApi handleOpenURL:url delegate:self];
}
//支付成功时调用,回到第三方应用中
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [WXApi handleOpenURL:url delegate:self];
}
4.微信会掉函数(写在appdelegate里的)
-(void)onResp:(BaseResp*)resp{
if ([resp isKindOfClass:[PayResp class]]){
PayResp*response=(PayResp*)resp;
[[NSNotificationCenter defaultCenter] postNotificationName:@"WXPaySuccess" object:@{@"errCode":@(response.errCode)}];
switch(response.errCode){
case WXSuccess:
NSLog(@"支付成功");
break;
default:
NSLog(@"支付失败,retcode=%d",resp.errCode);
break;
}
}
}
参考链接
https://blog.csdn.net/sheng_bin/article/details/72082764
支付宝:
网友评论