IOS - 注册手机号和重置密码请求函数

标签: MystraIOS注册手机号重置密码
796人阅读 评论(0) 收藏 举报
分类:

注册手机号请求函数:
通过单例账号类, 设置Post请求信息, 发送请求, 处理返回JSON信息.

/**
 *  注册手机号请求
 * 
 *  POST数据示例: {"version":16,"token":"","msgType":"MSG_USER_REGISTER_REQ","msgSeq":207,
 *  "appType":4,"IMEI":"356199060018702","phoneNo":"18811110000","userName":"cxxxyx18811110000",
 *  "password":"qwertyuiop","msgCode":"151551"}
 */
- (void) registerPhoneNo {

    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_USER_REGISTER_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"]; // 唯一码
    [paras setObject:currentUser.matPhoneNo forKey:@"phoneNo" ]; // 手机号
    [paras setObject:[NSString stringWithFormat:@"chunyu%@",currentUser.username] forKey:@"userName"]; // 用户名
    [paras setObject:currentUser.matPassword forKey:@"password"]; // 密码
    [paras setObject:_activiateCodeTextField.text forKey:@"msgCode"]; // 验证码[输入]

    NSLog(@"注册手机号参数: %@", paras);

    // POST请求: MSG_USER_REGISTER_REQ
    [[ChunyuAPIClient sharedClient] postPath:[ChunyuAPIClient MAT_NOAUTH_HTTP_URL]
                                  parameters:paras
                          requestContentType:kCYHttpRequestContentTypeJSON
                                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                         NSLog(@"MSG_USER_REGISTER_REQ + %@", responseObject);
                                         NSString* loginState = responseObject[@"description"];
                                         NSLog(@"注册状态: %@", loginState);
                                         [SVProgressHUD showErrorWithStatus: loginState duration:2.0f]; // 提示

                                         // 登录成功
                                         if ([responseObject[@"errorCode"] intValue] == 0) {
                                             [self dismissController]; // 关闭验证页面

                                         }
                                     }
                                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                         NSLog(@"请求错误 + %@", error);
                                         [SVProgressHUD showErrorWithStatus: @"服务器异常"]; // 提示
                                     }];
}

重置密码请求函数:
与注册手机号请求类型(msgType)不同, 去掉用户名(userName)参数.

/**
 *  重置密码请求
 *
 *  POST数据示例: {"version":16,"token":"","msgType":"MSG_RESET_PASSWORD_REQ","msgSeq":16,
 *  "appType":4,"IMEI":"356199060018702","phoneNo":"18511452178","password":"qwertyui",
 *  "msgCode":"545767"}
 */
- (void) resetPassword {

    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_RESET_PASSWORD_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"]; // 唯一码
    [paras setObject:currentUser.matPhoneNo forKey:@"phoneNo" ]; // 手机号
    [paras setObject:currentUser.matPassword forKey:@"password"]; // 密码
    [paras setObject:_activiateCodeTextField.text forKey:@"msgCode"]; // 验证码[输入]

    NSLog(@"重置密码参数: %@", paras);

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

                                         [SVProgressHUD showErrorWithStatus: loginState duration:2.0f]; // 提示

                                         // 登录成功
                                         if ([responseObject[@"errorCode"] intValue] == 0) {
                                             [self dismissController]; // 关闭验证页面
                                         }
                                     }
                                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                         NSLog(@"responseObject + %@", error);
                                         [SVProgressHUD showErrorWithStatus: @"服务器异常"]; // 提示
                                     }];
}

娱乐

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2374034次
    • 积分:31688
    • 等级:
    • 排名:第154名
    • 原创:706篇
    • 转载:1篇
    • 译文:0篇
    • 评论:381条
    自我简介
    文章分类
    最新评论