LSGMainViewController.m 9.48 KB
//
//  LSGMainViewController.m
//  letsgameDemo
//
//  Created by zhy on 14-5-24.
//
//

#import "LSGMainViewController.h"
#import "LetsGameAPI.h"
#import "LetsGameActivityAPI.h"
#import "GPGameLoginSDK.h"


@interface LSGMainViewController ()

@property (nonatomic, strong) UILabel *resultLabel;

@property(nonatomic,strong) NSNumber *userId;

@property(nonatomic, assign) BOOL payToWeb;

@property(nonatomic, strong) UITextField *activityTextField;
@end

@implementation LSGMainViewController

- (void)loadView {
    [super loadView];
    NSLog(@"i come in");
//    self.view.backgroundColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor blackColor];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(110, 40, 100, 30)];
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitle:@"测试入口" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn addTarget:self action:@selector(onClickTest) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    UILabel *payWarnLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 85, 150, 10)];
    payWarnLabel.text = @"默认V3支付,点击Switch是V4支付";
    payWarnLabel.backgroundColor = [UIColor clearColor];
    payWarnLabel.font = [UIFont systemFontOfSize:9];
    [payWarnLabel setTextColor:[UIColor whiteColor]];
    [self.view addSubview:payWarnLabel];
    
    UIButton *payBtn = [[UIButton alloc] initWithFrame:CGRectMake(110, 100, 100, 30)];
    payBtn.backgroundColor = [UIColor orangeColor];
    [payBtn setTitle:@"支付" forState:UIControlStateNormal];
    [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    payBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [payBtn addTarget:self action:@selector(onPayTest) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:payBtn];
    
    self.payToWeb = NO;
    UISwitch *webVersion = [[UISwitch alloc] initWithFrame:CGRectMake(220,100,60,30)];
    [webVersion addTarget:self action:@selector(onPayWebTo) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:webVersion];
    
    UIButton *iapBtn = [[UIButton alloc] initWithFrame:CGRectMake(110, 160, 100, 30)];
    iapBtn.backgroundColor = [UIColor orangeColor];
    [iapBtn setTitle:@"IAP" forState:UIControlStateNormal];
    [iapBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    iapBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [iapBtn addTarget:self action:@selector(onIapTest) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:iapBtn];
    
    UIButton *activityBtn = [[UIButton alloc] initWithFrame:CGRectMake(110, 220, 100, 30)];
    activityBtn.backgroundColor = [UIColor orangeColor];
    [activityBtn setTitle:@"Activity" forState:UIControlStateNormal];
    [activityBtn setTintColor:[UIColor whiteColor]];
    activityBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [activityBtn addTarget:self action:@selector(onActivity) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:activityBtn];
    
    UIButton *cleanUserInfoBtn = [[UIButton alloc] initWithFrame:CGRectMake(300, 40, 100, 30)];
    cleanUserInfoBtn.backgroundColor = [UIColor orangeColor];
    [cleanUserInfoBtn setTitle:@"cleanUserInfo" forState:UIControlStateNormal];
    [cleanUserInfoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    cleanUserInfoBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [cleanUserInfoBtn addTarget:self action:@selector(cleanUserInfoClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cleanUserInfoBtn];
 
    UIButton *linkBtn = [[UIButton alloc] initWithFrame:CGRectMake(300, 100, 100, 30)];
    linkBtn.backgroundColor = [UIColor orangeColor];
    [linkBtn setTitle:@"link" forState:UIControlStateNormal];
    [linkBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    linkBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [linkBtn addTarget:self action:@selector(linkBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:linkBtn];
    
    
    UIButton *switchSysBtn = [[UIButton alloc] initWithFrame:CGRectMake(300, 160, 100, 30)];
    switchSysBtn.backgroundColor = [UIColor orangeColor];
    [switchSysBtn setTitle:@"switchGameCenter" forState:UIControlStateNormal];
    [switchSysBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    switchSysBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [switchSysBtn addTarget:self action:@selector(switchGameCentBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:switchSysBtn];
    
    UITextField *activityField = [[UITextField alloc] initWithFrame:CGRectMake(220, 220, 100, 30)];
    activityField.placeholder = @"活动类型";
    activityField.backgroundColor = [UIColor whiteColor];
    self.activityTextField = activityField;
    [self.view addSubview:self.activityTextField];
     
}

- (UILabel *)resultLabel {
    if (!_resultLabel) {
        _resultLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view.frame) - 90, self.view.frame.size.width, 60)];
        _resultLabel.backgroundColor = [UIColor clearColor];
        _resultLabel.textAlignment = NSTextAlignmentCenter;
        _resultLabel.textColor = [UIColor redColor];
        _resultLabel.font = [UIFont systemFontOfSize:15];
        _resultLabel.numberOfLines = 4;
        _resultLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [self.view addSubview:_resultLabel];
    }
    
    return _resultLabel;
}


- (void)onClickTest {
    [[GPGameLoginSDK instance] GPGameLoginWithViewController:self appID:@"10022" channelId:@"1000"];
    [GPGameLoginSDK instance].succBlock = ^(NSNumber *userId, ACCOUNTENTERTYPE type) {
        self.resultLabel.text = [NSString stringWithFormat:@"userId: %@, accountType: %ld", userId, (long)type];
        self.userId = userId;
    };
    [GPGameLoginSDK instance].failBlock = ^{
        self.resultLabel.text = @"login error";
    };
}


-(void)onPayTest{

    [LetsGameAPI instance].appId = @"100";//@"10056";//10022
    NSMutableDictionary *payInfo = [NSMutableDictionary dictionary];
    [payInfo setValue:@"100" forKey:@"serverId"];
    [payInfo setValue:@"41080" forKey:@"roleId"];
    [payInfo setValue:@"1000" forKey:@"channelId"];
    [payInfo setValue:self.userId forKey:@"userId"];
    [payInfo setValue:@"0.01" forKey:@"amount"];//商品价格
    [payInfo setValue:@"USD" forKey:@"currency"];//货币种类
    [payInfo setValue:@"ios demo" forKey:@"extraInfo"];
    [payInfo setValue:@"test" forKey:@"product"];
//    [[LetsGameAPI instance] pay:payInfo handleCallBack:^{
//        NSLog(@"第三方支付完成");
//    }];
    [[LetsGameAPI instance] pWeb:payInfo handleCallBack:^{
        NSLog(@"第三方支付完成");
    }];
}

-(void)onIapTest{

    [LetsGameAPI instance].appId = @"100";
    NSMutableDictionary *payInfo = [NSMutableDictionary dictionary];
    [payInfo setValue:@"100" forKey:@"serverId"];
    [payInfo setValue:@"41080" forKey:@"roleId"];
    [payInfo setValue:self.userId forKey:@"userId"];
    [payInfo setValue:@"1000" forKey:@"channelId"];
    [payInfo setValue:@"10" forKey:@"amount"];
    [payInfo setValue:@"ios demo" forKey:@"extraInfo"];
    [payInfo setValue:@"com.gump.pro1" forKey:@"product"];
    [[LetsGameAPI instance] iap:payInfo succCallback:^(NSString *orderId) {
        //注意测试仅仅是通知客户端成功,但是还需要向服务器请求验证是否成功,以服务端验证为准
        NSLog(@"IAP completed orderId of Gumptech:%@",orderId);
    } failCallback:^(NSString *orderId) {
        NSLog(@"IAP file orderId of Gumptech:%@",orderId);
    }];
}

-(void)onActivity{
    
    [[LetsGameActivityAPI instance] decideIsDebug:1];
    NSMutableDictionary *activityInfo = [NSMutableDictionary dictionary];
    [activityInfo setValue:@"100" forKey:@"appId"];
    [activityInfo setValue:@"17670327" forKey:@"userId"];
    [activityInfo setValue:@"55" forKey:@"serverId"];
    [activityInfo setValue:@"Pidmon" forKey:@"serverName"];
    [activityInfo setValue:@"55004444" forKey:@"roleId"];
    [activityInfo setValue:@"Marin" forKey:@"roleName"];
    [activityInfo setValue:@"140" forKey:@"diamond"];
    [activityInfo setValue:self.activityTextField.text forKey:@"campaignType"];
    [[LetsGameActivityAPI instance] GameActivityWithParaDictory:activityInfo handleCallBackL:^{
        NSLog(@"activity finish!");
    }];
}

-(void)linkBtnClick{
    NSMutableDictionary *linkParaDic = [NSMutableDictionary dictionary];
    [linkParaDic setObject:@"10022" forKey:@"appId"];
    [linkParaDic setObject:self.userId forKey:@"userId"];
    //仅在切换账号成功的时候有返回值
    [[GPGameLoginSDK instance] GPGameAccountLinkViewController:self InfoDic:linkParaDic callBack:^(NSNumber *userId, ACCOUNTENTERTYPE type) {
        self.resultLabel.text = [NSString stringWithFormat:@"userId: %@, accountType: %ld", userId, (long)type];
    }];
}

-(void)onPayWebTo{
    if (!self.payToWeb) {
        self.payToWeb = YES;
        [[LetsGameAPI instance] decideWebToVersion:1];
    }else{
        self.payToWeb = NO;
        [[LetsGameAPI instance] decideWebToVersion:0];
    }
}

-(void)switchGameCentBtnClick{
    [[GPGameLoginSDK instance] GPSwitchGameCenterWithViewController:self switchCallBack:^{
        self.resultLabel.text = @"Login Game Center";
    }];
}

-(void)cleanUserInfoClick{
    [[GPGameLoginSDK instance] cleanUserInfo];
}

@end