Created
September 5, 2018 14:54
-
-
Save payjscn/18396dd011649c745365d725a235d20a to your computer and use it in GitHub Desktop.
PAYJS 扫码支付接口 Object C DEMO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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