微信支付

#pragma  mark- 微信支付

- (void)bizPay:(NSDictionary *)dic {
    NSString *res = [self jumpToBizPay:dic];
    if( ![@"" isEqual:res] ){
        UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"支付失败" message:res delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        
        [alter show];
    }
    
}

- (NSString *)jumpToBizPay:(NSDictionary *)dict {
    if(dict != nil){
            NSMutableString *stamp  = [dict objectForKey:@"timestamp"];
            //调起微信支付
            PayReq* req             = [[PayReq alloc] init];
            req.partnerId           = [dict objectForKey:@"partnerid"];
            req.prepayId            = [dict objectForKey:@"prepayid"];
            req.nonceStr            = [dict objectForKey:@"noncestr"];
            req.timeStamp           = stamp.intValue;
            req.package             = [dict objectForKey:@"package"];
            req.sign                = [dict objectForKey:@"sign"];
            [WXApi sendReq:req];
            //日志输出
            NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@",[dict objectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign );
            return @"";
    }else{
        return @"服务器返回错误,未获取到json对象";
    }
    return @"服务器返回错误";
}
- (void)connect{
    HUD_ = [[MyActivityView alloc] initWithSuperView:WINDOW title:HUD_TITLE];
    [HUD_ show:YES];
    NSString *tNumber = [NSString stringWithFormat:@"%@",[self.orderDictionary objectForKey:@"tNumber"]];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:tNumber,@"tradeId", nil];
    //必须实现的两步------------------------
    NSString *jsonString = [AsyConnecModel DataTOjsonString:dic];
    NSDictionary *postDic = [AsyConnecModel setPostValue:jsonString];
    //------------------------
    //拼接接口地址
    NSString *url = [NSString stringWithFormat:@"%@%@",ServerKey,AF_WXpay];
    [AsyConnecModel asyncPostWithUrl:url strparmaters:postDic finishBlock:^(id response){
        //接口返回值
        NSLog(@"response    :     %@",response);
        if ([response isKindOfClass:[NSError class]]) {
            NSError *error = (NSError *)response;
            NSLog(@"%@",error.localizedDescription);
            UIView *view = WINDOW;
            [view makeToast:error.localizedDescription duration:TOAST_TIMER position:TOAST_CENTER];
            [HUD_ hide];
            return;
        }
        NSDictionary *dic = (NSDictionary *)response;
        if ([[dic objectForKey:@"result"] integerValue] == 1) {
            [HUD_ hide];
            if (![Collect replaceNull:[[dic objectForKey:@"message"] objectForKey:@"prepayid"]].length) {
                UIView *view = WINDOW;
                [view makeToast:@"权鉴错误" duration:TOAST_TIMER position:TOAST_CENTER];
            }else{
                [self bizPay:[dic objectForKey:@"message"]];
            }
        }else{
            NSLog(ERROR_LOG);
            [HUD_ hide];
        }
    }];
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值