12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // LFWSendCodeRequest.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/1/24.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LFWSendCodeRequest.h"
- @implementation LFWSendCodeRequest
- + (void)post:(NSString *)url params:(id)params success:(void(^)(id json))success failure:(void(^)(NSError *error))failure {
- // 1.创建请求管理者
- AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
- mgr.requestSerializer = [AFHTTPRequestSerializer serializer]; // 解析为data
- mgr.responseSerializer=[AFHTTPResponseSerializer serializer];
- mgr.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",nil];
- mgr.requestSerializer.timeoutInterval = 15;
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
- [mgr.requestSerializer setValue:app_Version forHTTPHeaderField:@"version"];
-
- // 2.发送请求
- [mgr POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- id responseDict =[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
- if ([responseDict[@"errno"] isEqualToString:@"0"]) {
- if (!responseDict[@"rst"]) {
- success(@{});
- }else{
- [SVProgressHUD showSuccessWithStatus:@"发送成功"];
- success(responseDict[@"rst"]);
-
- }
- }else{
- if ([responseDict[@"errno"] isEqualToString:@"1005"]) {
- [SVProgressHUD showErrorWithStatus:@"请输入合法的手机号"];
-
- }else if ([responseDict[@"errno"] isEqualToString:@"1007"]){
- [SVProgressHUD showErrorWithStatus:@"签名不合法 "];
- }else if ([responseDict[@"errno"] isEqualToString:@"1008"]){
- [SVProgressHUD showErrorWithStatus:@"请求时间不合法 "];
- }else{
- NSString *errorStr = responseDict[@"err"];
- if (errorStr) {
- return ;
- }
- [SVProgressHUD showErrorWithStatus:@"发送失败"];
- }
- NSError *error = nil;
- failure(error);
-
- }
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- if (failure) {
- failure(error);
- }
- }];
-
- }
- @end
|