微信支付
在入口类里微信支付注册
[WXApi registerApp:WeiXin_AppId withDescription:@"demo2.0"];
在入口类方法里添加url
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if ([[url scheme] isEqualToString:WeiXin_AppId])
{
return [WXApi handleOpenURL:url delegate:self];
}
}
支付回调
-(void)onResp:(BaseResp *)resp
{
if([resp isKindOfClass:[PayResp class]]){
switch (resp.errCode) {
case WXSuccess:
[self.narvigationController pushViewController:[[YDPayMoneySuccessViewController alloc]init] animated:YES];
break;
default:
[SVProgressHUD showView:self.window image:nil status:@"支付失败"];
break;
}
}
}
发送微信支付请求
if ([WXApi isWXAppInstalled]) {
PayReq *weiXinReq = [[PayReq alloc]init];
weiXinReq.openID = WeiXin_AppId;
weiXinReq.partnerId = WeiXin_mchId;
weiXinReq.prepayId = self.balanceRespondEntity.backInfo.prepayId;
weiXinReq.package = @"Sign=WXPay";
weiXinReq.timeStamp = [self setTimeStamp];
weiXinReq.nonceStr = [WXUtil md5:[NSString stringWithFormat:@"%d",weiXinReq.timeStamp]];
//获取签名的方法,要注意
NSMutableDictionary *signParams = [NSMutableDictionary dictionary];
[signParams setObject: WeiXin_AppId forKey:@"appid"];
[signParams setObject: weiXinReq.nonceStr forKey:@"noncestr"];
[signParams setObject: weiXinReq.package forKey:@"package"];
[signParams setObject: weiXinReq.partnerId forKey:@"partnerid"];
[signParams setObject: weiXinReq.prepayId forKey:@"prepayid"];
[signParams setObject:[NSString stringWithFormat:@"%d",weiXinReq.timeStamp] forKey:@"timestamp"];
payRequsestHandler *payHandler = [[payRequsestHandler alloc]init];
//如果出现闪退加上这句话
[payHandler setKey:WeiXin_pkey];
NSString *sign = [payHandler createMd5Sign:signParams];
weiXinReq.sign = sign;
[WXApi sendReq:weiXinReq];
}
else
{
[SVProgressHUD showView:self.view image:nil status:@"未安装微信"];
}
微信支付
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 原文链接:https://github.com/mayubao/Android-Pay支持微信和支付宝两种主流支付...
- 银联支付,支付宝支付,微信支付的三大总结,之前也有写过两篇。 微信支付,支付宝支付,银联支付——三大支付总结: h...