Hale Cai
2018-08-10 42c80d0b43ff8736edb5be4bbfcbc7a99fc8a119
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
//  ViewController.m
//  FreeSDKDebug
//
//  Created by 韩凯 on 7/10/15.
//  Copyright (c) 2015 江苏易乐网络科技有限公司. All rights reserved.
//
 
#import "ViewController.h"
#import "FreeSDK.h"
 
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *bindPhoneLabel;
 
@end
 
@implementation ViewController
 
- (IBAction)isCanPay:(id)sender {
    
    [FreeSDK isCanPay:^(BOOL isCanPay, NSString *msg) {
        NSLog(@"is can pay %d, msg %@", isCanPay, msg);
        [[[UIAlertView alloc] initWithTitle:@"测试是否可以支付" message: isCanPay ? @"可以支付" : msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
    }];
    
}
 
- (IBAction)showRealNameRegister:(id)sender {
    [FreeSDK showRealNameAuthentication:self];
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    //120055340 1511171001
    [FreeSDK initSDKWithAppId:@"1213113243" withSDKBlock:^(YLSDKType type, NSString *msg) {
        switch (type) {
            case YLSDKTypeInitSuccess:
                NSLog(@"初始化成功");
                break;
            case YLSDKTypeInitFailure:
                NSLog(@"初始化失败");
                break;
            case YLSDKTypeSwitchAccount:
                NSLog(@"切换账号成功,需重启游戏!");
                [FreeSDK logout];
                self.bindPhoneLabel.text = accountIdLabel.text = tokenLabel.text = tokenExpiryLabel.text = nil;
                [self loginOrLogout:self];
                break;
        }
    }];
    
    [FreeSDK setupWeChatAppId:@"wx52c39e71978b58d5" appSecret:@"0bdf260bc8057e7c9df4f93661cb7255"];
    [FreeSDK setupQQAppId:@"1106176954"];
 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidLogin) name:YLUserDidLoginNotification object:nil];
    
//    if ([YLAccount sharedInstance].loggedIn) {
//        [self userDidLogin];
//    }
}
 
- (void)userDidLogin {
    YLAccount * acc = [YLAccount sharedInstance];
    accountIdLabel.text = acc.identifier;
    tokenLabel.text = acc.token;
    NSDateFormatter * fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    tokenExpiryLabel.text = [fmt stringFromDate:acc.tokenExpiry];
//    self.bindPhoneLabel.text = acc.phoneNumber;
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
- (BOOL)prefersStatusBarHidden {
    return YES;
}
 
- (IBAction)loginOrLogout:(id)sender {
    if ([YLAccount sharedInstance].loggedIn) {
#warning logout and delete cache
        [FreeSDK logout];
       self.bindPhoneLabel.text = accountIdLabel.text = tokenLabel.text = tokenExpiryLabel.text = nil;
    } else {
        [FreeSDK presentLoginDialog:nil];
    }
}
 
- (IBAction)pay:(id)sender {
    YLOrder *order=[[YLOrder new]init];
    order.title=@"Test Payment";
    order.cpInfo=@"com.game003.zhyry.6";
    order.cpOrderId=@"1213113243";
    order.total=0.01f;
    [FreeSDK pay:order];
}
 
- (void)purchase:(id)sender
{
    NSInteger randomId = (NSInteger)(arc4random() % (1999 - 1000) + 1000);
    NSString * oid = [NSString stringWithFormat:@"%f%ld", [[NSDate date] timeIntervalSince1970], (long)randomId];
}
 
//test
- (IBAction)testPush:(id)sender {
    
    [self.navigationController pushViewController:[UIViewController new] animated:YES];
//    [self presentViewController:[UIViewController new] animated:YES completion:nil];
    
}
 
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end