123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- //
- // ViewController.m
- // Demo
- //
- // Created by BensonZhang on 15/11/13.
- // Copyright © 2015年 xunlian. All rights reserved.
- //
- #import "ViewController.h"
- #import "AllPayRequest.h"
- #import "PayOrder.h"
- #import "DateUtil.h"
- #import "SignUtil.h"
- #import "AllPaySDK.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // [self.view setBackgroundColor:[UIColor yellowColor]];
- UIButton * btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- btn1.tag = 2;
- btn1.frame = CGRectMake(80, 60, 200, 50);
- [btn1 setTitle:@"支付宝支付" forState:UIControlStateNormal];
- [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:btn1];
- UIButton * btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- btn2.tag = 3;
- btn2.frame = CGRectMake(80, 110, 200, 50);
- [btn2 setTitle:@"微信支付" forState:UIControlStateNormal];
- [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:btn2];
-
- UIButton * btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- btn3.tag = 4;
- btn3.frame = CGRectMake(80, 160, 200, 50);
- [btn3 setTitle:@"UP支付" forState:UIControlStateNormal];
- [btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:btn3];
-
-
- UIButton * btn4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- btn4.tag = 5;
- btn4.frame = CGRectMake(80, 210, 200, 50);
- [btn4 setTitle:@"Apple Pay" forState:UIControlStateNormal];
- [btn4 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:btn4];
-
-
-
-
- }
- -(void)btnClick:(UIButton *)btn
- {
-
-
-
- NSMutableDictionary * paramDic=[[NSMutableDictionary alloc]init];
- [paramDic setObject:@"VER000000002" forKey:@"version"];
- [paramDic setObject:@"UTF-8" forKey:@"charSet"];
- [paramDic setObject:@"PURC" forKey:@"transType"];
- [paramDic setObject:[DateUtil getDate:@"YYYYMMddHHmmss"] forKey:@"orderNum"];
- [paramDic setObject:@"0.1" forKey:@"orderAmount"];
- [paramDic setObject:@"CNY" forKey:@"orderCurrency"];
- [paramDic setObject:@"nil" forKey:@"frontURL"];
- [paramDic setObject:@"http://example.com/example" forKey:@"backURL"];
- [paramDic setObject:@"你好吗" forKey:@"merReserve"];
- [paramDic setObject:@"test" forKey:@"goodsInfo"];
- [paramDic setObject:@"000000000000015" forKey:@"merID"];
- [paramDic setObject:@"99020344" forKey:@"acqID"];
- [paramDic setObject:[DateUtil getDate:@"YYYYMMddHHmmss"] forKey:@"transTime"];
- [paramDic setObject:@"MD5" forKey:@"signType"];
-
- NSString *detailInfo = @"IFt7Imdvb2RzX25hbWUiOiLkuIDkuKrlj4jlpKflj4jlnIbnmoToi7nmnpwiLCJxdWFudGl0eSI6IjEifSx7Imdvb2RzX25hbWUiOiLljY7kuLpQMjAgcGx1cyIsInF1YW50aXR5IjoiNCJ9XQ==";
-
-
- [paramDic setObject:detailInfo forKey:@"detailInfo"];
-
-
- if (btn.tag == 2)//支付宝
- {
- [paramDic setObject:@"APMP" forKey:@"paymentSchema"];
-
- }else if (btn.tag == 3)//微信
- {
- [paramDic setObject:@"WX" forKey:@"paymentSchema"];
- }else if (btn.tag == 4)//银联UP
- {
- [paramDic setObject:@"UP" forKey:@"paymentSchema"];
- }else if (btn.tag == 5)//APP
- {
- [paramDic setObject:@"APP" forKey:@"paymentSchema"];
- }
-
- [self startPay:paramDic];
-
- }
- -(void)startPay:(NSMutableDictionary*)paramDic
- {
- [paramDic setObject:[SignUtil getSign:paramDic] forKey:@"signature"];
-
- NSString *url = @"https://testapi.allpayx.com/app/pay";
-
- // NSString *url = @"https://api.allpayx.com/app/pay";
-
-
- [AllPayRequest postRequestWithURL:url paramters:paramDic succeed:^(id finResponseData)
- {
- NSError *error;
- NSDictionary * diction = [NSJSONSerialization JSONObjectWithData:finResponseData options:NSJSONReadingMutableContainers error:&error];
- if(!error){
- NSLog(@"-----输出数据---%@",diction);
-
-
- [AllPaySDK pay:[diction objectForKey:@"tn"] mode:NO scheme:@"com.xxx.xxx" ViewController:self onResult: ^(NSDictionary *resultDic) {
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:resultDic options:NSJSONWritingPrettyPrinted error:nil];
- NSString *message =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"支付结果" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- [alert show];
-
- }];
-
-
-
- }else{
- NSString * dataString = [[NSString alloc]initWithData:finResponseData encoding:NSUTF8StringEncoding];
- NSLog(@"参数出错===\n %@",dataString);
-
-
- }
-
-
-
- } failed:^(id faiResponseData) {
-
- }];
-
-
-
- }
- - (NSString *)getCurrentLanguage
- {
- NSArray *languages = [NSLocale preferredLanguages];
- NSString *currentLanguage = [languages objectAtIndex:0];
- NSLog( @"%@" , currentLanguage);
- return currentLanguage;
- }
- @end
|