// // 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:@"EB支付" forState:UIControlStateNormal]; [btn4 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn4]; UIButton * btn5 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn5.tag = 6; btn5.frame = CGRectMake(80, 260, 200, 50); [btn5 setTitle:@"Apple Pay" forState:UIControlStateNormal]; [btn5 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn5]; } -(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"]; 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)//EB { [paramDic setObject:@"INR" forKey:@"orderCurrency"]; [paramDic setObject:@"EB" forKey:@"paymentSchema"]; [paramDic setObject:@"benson zhang" forKey:@"trxn_firstname"]; [paramDic setObject:@"benson.zhang@allpayx.com" forKey:@"trxn_email_id"]; [paramDic setObject:@"15026528888" forKey:@"trxn_phone"]; [paramDic setObject:@"1" forKey:@"trxn_is_coupon_enabled"]; [paramDic setObject:@"123456789" forKey:@"unique_id"];//不多于10位 }else if (btn.tag == 6)//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