#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];
}
}];
}