IOS - 会员信息提示

会员信息提示
加载会员信息, 区分是否登录, 登录显示, 未登录不显示.

代码

/** * 获取购买信息 * * {"version":16,"token":"2EC74609C2C94F289AA7742CBE05BCDD","msgType":"MSG_QUERY_PRODUCT_REQ", * "msgSeq":10,"appType":4,"IMEI":"356199060018702"} */
- (void) loadPurchaseInfo {

    User* currentUser = [User currentUser]; // 账号

    NSMutableDictionary* paras = [[NSMutableDictionary alloc] init]; // POST参数

    [paras setObject:currentUser.matVersion forKey:@"version"]; // 版本号
    [paras setObject:(currentUser.matToken == nil)?@"":currentUser.matToken forKey:@"token"]; // Token
    [paras setObject:@"MSG_QUERY_PRODUCT_REQ" forKey:@"msgType"]; // 消息类型
    [paras setObject:[NSString stringWithFormat:@"%d",currentUser.matMsgSeq] forKey:@"msgSeq"]; // 消息序列
    [paras setObject:currentUser.matAppType forKey:@"appType"]; // APP类型
    [paras setObject:currentUser.uniqueDeviceToken forKey:@"IMEI"]; // 唯一码

    NSLog(@"获取购买信息参数: %@", paras);

    // POST请求: MSG_QUERY_PRODUCT_REQ
    [[ChunyuAPIClient sharedClient] postPath:[ChunyuAPIClient MAT_AUTH_HTTP_URL]
                                  parameters:paras
                          requestContentType:kCYHttpRequestContentTypeJSON
                                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                         NSLog(@"MSG_QUERY_PRODUCT_REQ + %@", responseObject);
                                         NSString* loginState = responseObject[@"description"];
                                         NSLog(@"注册状态: %@", loginState);

                                         // 获取成功
                                         if ([responseObject[@"errorCode"] intValue] == 0) {
                                             NSLog(@"获取购买信息成功");
                                         }

                                         // 登录后显示
                                         if ([currentUser hasLoggedIn]) {
                                             [self parseHttpResponse:responseObject];
                                         }
                                     }
                                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                         NSLog(@"请求错误 + %@", error);
                                     }];
}

/** * 解析参数 * * @param httpObject 字符串字典 */
- (void) parseHttpResponse:(id)httpObject {
    NIDPRINTMETHODNAME();

    User *user = [User currentUser];

    NSMutableArray* goodsList = [[NSMutableArray alloc] init]; // 项目信息
    NSMutableArray* serviceNumList = [[NSMutableArray alloc] init]; // 不同服务的次数
    NSMutableArray* serviceIdList = [[NSMutableArray alloc] init]; // 不同服务的标号

    goodsList = httpObject[@"goodsList"];

    for (int i=0; i<goodsList.count; ++i) {
        [serviceNumList addObject:[NSNumber numberWithInteger:1]];
        [serviceIdList addObject:goodsList[i][@"goodsCode"]];

        if ([goodsList[i][@"goodsCode"] intValue] == 33) {
            user.matMonthPrice = [NSString stringWithFormat:@"%0.1f", [goodsList[i][@"Price"] intValue]/100.0];
            [user synchronize];
        }
    }

    NSLog(@"serviceIdList信息 - %@", serviceIdList);

    NSMutableString* member =
    [NSMutableString stringWithFormat:@"%@元/月, 不限次问诊", user.matMonthPrice];
    if ([user matDays] >= 0) {
        [member appendString:@", 已开通"];
    } else {
        [member appendString:@", 未开通"];
    }

    // 会员提示
    [_memberText setText:member];
}

效果
IOS - 会员信息提示_第1张图片

IOS - 会员信息提示_第2张图片

你可能感兴趣的:(ios,Mystra,信息提示)