Skip to content

Instantly share code, notes, and snippets.

@payjscn
Created September 5, 2018 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save payjscn/18396dd011649c745365d725a235d20a to your computer and use it in GitHub Desktop.
Save payjscn/18396dd011649c745365d725a235d20a to your computer and use it in GitHub Desktop.
PAYJS 扫码支付接口 Object C DEMO
NSString *host = @"https://payjs.cn";
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=******************";
//或者base64
//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];
//打印应答中的body
NSLog(@"Response body: %@" , bodyString);
}];
[task resume];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment