微信支付

来源:互联网 发布:软件合作开发协议书 编辑:程序博客网 时间:2024/05/14 22:37

//自己请求订单

- (void)weiChatPay:(NSString *)pay callback:(WXModuleCallback)callback{

    

    NSLog(@"weChat支付");

    NSString *urlStr = pay;

    NSError *error;

    NSURLRequest *request = [NSURLRequestrequestWithURL:[NSURLURLWithString:urlStr]];

    NSData *response = [NSURLConnectionsendSynchronousRequest:request returningResponse:nilerror:nil];

    if (response != nil) {

        NSMutableDictionary *dict =NULL;

        dict = [NSJSONSerializationJSONObjectWithData:response options:NSJSONReadingMutableLeaveserror:&error];

        NSLog(@"urlStr= %@", urlStr);

        

        if (dict != nil) {

            NSMutableString *retcode = [dict objectForKey:@"retcode"];

            if (retcode.intValue ==0) {

                NSMutableString *stamp = [dictobjectForKey:@"timestamp"];

                //调起微信支付

                PayReq* req             = [[PayReqalloc] init];

                /** 商家向财付通申请的商家id */

                req.partnerId           = [dictobjectForKey:@"partnerid"];

                /** 预支付订单 */

                req.prepayId            = [dictobjectForKey:@"prepayid"];

                /** 随机串,防重发 */

                req.nonceStr            = [dictobjectForKey:@"noncestr"];

                /** 时间戳,防重发 */

                req.timeStamp           = stamp.intValue;

                /** 商家根据财付通文档填写的数据和签名 */

                req.package             = [dictobjectForKey:@"package"];

                /** 商家根据微信开放平台文档对数据做的签名 */

                req.sign                = [dictobjectForKey:@"sign"];

                [WXApi sendReq:req];

                //日志输出

                NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@",[dictobjectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign );

            }else{

                NSDictionary *retmsg = [dict objectForKey:@"retmsg"];

                NSLog(@"retmsg=%@", retmsg);

            }


        }else{

            [MBProgressHUDshowError:@"服务器返回错误,未获取到json对象"];

            NSLog(@"服务器返回错误,未获取到json对象");

        }

    }else{

        [MBProgressHUD showError:@"服务器返回错误"];


        NSLog(@"服务器返回错误");

    }

    if (![@""isEqual:urlStr]) {

        [MBProgressHUD showError:@"支付失败"];

        NSLog(@"支付失败");

    }

}


0 0
原创粉丝点击