Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PAYJS 扫码支付接口 Object C DEMO
NSString *host = @"";
NSString *path = @"/api/native";
NSString *method = @"POST";
NSString *querys = @"";
NSString *url = [NSString stringWithFormat:@"%@%@%@", host, path , querys];
NSString *bodys = @"mchid=****&total_fee=12&out_trade_no=2134099892932&sign=******************";
//NSString *bodys = @"image=data:image/jpeg;base64,/9j/4A......";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:1 timeoutInterval: 5];
request.HTTPMethod = method;
NSData *data = [bodys dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data];
NSURLSession *requestSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionDataTask *task = [requestSession dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable body , NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"Response object: %@" , response);
NSString *bodyString = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
NSLog(@"Response body: %@" , bodyString);
[task resume];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment