jiaPeiManager.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. //
  2. // jiaPeiManager.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2016/12/26.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. #import "jiaPeiManager.h"
  8. #import "AFNetworking.h"
  9. #import "DES3Util.h"
  10. #import "DesUtil.h"
  11. @implementation jiaPeiManager
  12. + (NSDictionary *)getDicWithArray:(NSArray *)array
  13. {
  14. NSMutableDictionary *questDic = [NSMutableDictionary dictionaryWithCapacity:array.count];
  15. if (!array) {
  16. return questDic;
  17. }
  18. for (NSDictionary *dict in array) {
  19. //其实这个判断跟自定义addpro里面重复了,但是鉴于项目有些参数的添加没有使用addpro过滤。所以此处再次判断
  20. if (dict && dict.allValues.count != 0) {
  21. [questDic setValue:[dict.allValues firstObject] forKey:[dict.allKeys firstObject]];
  22. }
  23. }
  24. return questDic;
  25. }
  26. + (NSString *)getURLWithDict:(NSDictionary *)dic urlPre:(NSString *)urlP {
  27. /// 其他请求
  28. NSArray *anotherArray = @[
  29. @"/open-api/teachingVideo/info/treeList", /// 查询教学视频分类树形列表
  30. @"/open-api/teachingVideo/info/getTeachingVideoByTypeId", /// 根据分类ID查询教学视频
  31. ];
  32. BOOL isAnother = [anotherArray containsObject:urlP];
  33. //http://175.42.30.21:9096/xm
  34. //生成带有签名的URL
  35. NSString *httpUrl = isAnother? anotherDefaultHttp : defaultHttp;
  36. NSString *urlDefault = isAnother? anotherDefaultHttpUrl :defaultHttpUrl;
  37. //公共请求
  38. NSArray *commonArray = @[@"getAppAdsNew", //广告
  39. @"getMyYuyueInfos", //获取自主预约
  40. @"getMessageInfos", //我的系统消息
  41. @"getTeachTypes", //获取日志类型
  42. @"getMyTeachLogs", //获取日志
  43. @"stuXXList", //获取休学记录
  44. @"getMyReserveOrders", //获取订单
  45. // @"uploadReserveComplaints", //获取投诉
  46. @"getOrderComplaintsByClassId", //根据课堂ID和投诉用户ID查询投诉
  47. @"getAppParam"
  48. ];
  49. if ([commonArray containsObject:urlP]) {
  50. urlDefault = defaultCommonUrl;
  51. }
  52. //计时相关
  53. NSArray *trainArray = @[@"getCoachSignForTrain", //获取教练当天签到状态
  54. @"getSignRecords", //获取教练签到记录
  55. @"getCoachSignStuRecords", //获取学员签到列表
  56. @"uploadSignOutOrClassRecord", //签退并上传学时汇总
  57. @"uploadAppTrainSingle", //分钟学时及GPS点上传
  58. @"uploadAppTrainPl", //分钟学时批量上传
  59. @"comparisonPhoto", //学员签到/签退/随机拍照
  60. @"uploadStuSign", //学员签到
  61. @"doTeach", //我要带教
  62. @"saveCoachSignOut", //教练员签退
  63. @"saveCoachSignIn", //教练员签到
  64. @"doDeviceLogOut", //终端注销
  65. @"doDeviceReg", //终端注册
  66. @"getPrice", //培训价格
  67. @"delLogStudent", //霸王签退
  68. @"uploadReserveOrder", //计划生成订单
  69. @"delReserveOrder", //删除计划订单
  70. @"uploadBindStuImei", //学员手机设备绑定
  71. @"getEvaluationCoachList", //教练获得的评价栏目数
  72. @"doComplaint", //学时投诉
  73. @"doEvaluation", //学时评论
  74. @"getTrainFinish", //获取已完成学时
  75. @"getTrainFinishNew", //获取已完成学时新
  76. @"getEvaluationList", //查看学时评论
  77. @"getStuSignFlag", //获取当前学员签到状态
  78. @"forceSignOut", //用classid直接汇总
  79. @"uploadMnStuLogin", //模拟计时签到
  80. @"uploadMnSignOut", //模拟计时签退
  81. @"getStudentTrack", //查询轨迹
  82. @"getSchPlaces", //查询驾校训练点信息
  83. @"getSchPlaceCoachs", //查询训练场下所有教练
  84. @"updateReserveEnd" //预约订单签退
  85. ];
  86. if ([trainArray containsObject:urlP]) {
  87. urlDefault = defaultTrainUrl;
  88. }
  89. if ([urlP isEqualToString:@"comparisonPhoto"] || [urlP isEqualToString:@"takePhoto"]) {
  90. urlDefault = defaultUploadUrl;
  91. }
  92. //模拟计时
  93. NSArray *imitate1Array = @[@"userLogin",
  94. @"userLoginOut",
  95. @"getUserLearnRecord"
  96. ];
  97. if ([imitate1Array containsObject:urlP]) {
  98. urlDefault = defaultImitateUrl1;
  99. }
  100. //模拟计时
  101. NSArray *imitate2Array = @[@"getTrainInsList",
  102. @"getDeviceMnList",
  103. @"getExamQuota",
  104. @"getReserveMnByDevId",
  105. @"getReserveMnList",
  106. @"getOrderMnList",
  107. @"getDiscountHalfHour",
  108. @"uploadReserveMn",
  109. @"deteleReserveMn"
  110. ];
  111. if ([imitate2Array containsObject:urlP]) {
  112. urlDefault = defaultImitateUrl2;
  113. }
  114. // 远程理论计时
  115. NSArray *educationArr = @[@"getCurrentTime", // 获取当前时间
  116. @"uploadEduSignIn", // 远程理论签到
  117. @"uploadEduPic", // 远程理论拍照上传
  118. @"uploadEduSignOut", // 远程理论签退
  119. @"getTheoryStatus", // 获取理论签到状态
  120. @"edufaceToface" // 远程理论人脸比对
  121. ];
  122. if ([educationArr containsObject:urlP]) {
  123. urlDefault = defaultEducation;
  124. // if ([urlP isEqualToString:@"edufaceToface"] ) {
  125. // httpUrl = @"http://175.42.30.21:9096/xm";
  126. // urlDefault = @"webservice/education/";
  127. // }
  128. }
  129. NSTimeInterval timeI = [[NSDate date] timeIntervalSince1970] * 1000;//获取时间戳 单位:s *1000毫秒
  130. NSString *timeStr = [NSString stringWithFormat:@"%.0f",timeI];
  131. NSString *urlS = @"";
  132. if (dic == nil || dic.allValues.count == 0) {
  133. if (isAnother) {
  134. urlS = [NSString stringWithFormat:@"%@%@%@",httpUrl,urlDefault,urlP];
  135. } else {
  136. urlS = [NSString stringWithFormat:@"%@%@%@?ts=%@&user=ios&v=jsjp",httpUrl,urlDefault,urlP,timeStr];
  137. }
  138. } else {
  139. //添加key字段
  140. NSMutableString *contentString = [NSMutableString stringWithString:[self getSignStringWithDictionary:dic]];
  141. if (isAnother) {
  142. if (contentString.length > 1) {
  143. NSString *lastString = [contentString substringFromIndex:contentString.length-1];
  144. if ([lastString isEqualToString:@"&"]) {
  145. contentString = [contentString substringToIndex:[contentString length]-1].mutableCopy;
  146. }
  147. }
  148. urlS = [NSString stringWithFormat:@"%@%@%@?%@",httpUrl,urlDefault,urlP,contentString];
  149. } else {
  150. [contentString appendFormat:@"key=%@", timeStr];
  151. // NSString *strUrl1 = [contentString stringByReplacingOccurrencesOfString:@" " withString:@""];
  152. // NSString *strUrl2 = [strUrl1 stringByReplacingOccurrencesOfString:@"\t" withString:@""];
  153. // NSString *strUrl3 = [strUrl1 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  154. urlS = [NSString stringWithFormat:@"%@%@%@?ts=%@&sign=%@&user=ios&v=jsjp",httpUrl,urlDefault,urlP,timeStr,[[contentString md5Encrypt] uppercaseString]];
  155. //NSLog(@"urlS----><>%@----><>%@",strUrl3,urlS);
  156. }
  157. }
  158. if ([urlP containsString:@"https://api.weixin.qq.com"]) {
  159. urlS = urlP;
  160. }
  161. return urlS;
  162. }
  163. + (NSString *)getSignStringWithDictionary:(NSDictionary *)dic
  164. {
  165. NSMutableString *contentString =[NSMutableString string];
  166. NSDictionary* dict = [NSDictionary dictionaryWithDictionary:dic];
  167. NSArray *keys = [dict allKeys];
  168. //按字母顺序排序
  169. NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
  170. return [obj1 compare:obj2 options:NSNumericSearch];
  171. }];
  172. //拼接字符串
  173. for (NSString *categoryId in sortedArray) {
  174. // if (![categoryId isEqualToString:@"sign"] && ![categoryId isEqualToString:@"timestamp"]){
  175. if (![categoryId isEqualToString:@"sign"]){
  176. if([categoryId isEqualToString:@"biz_content"]){
  177. NSError *error = nil;
  178. NSDictionary* bizDict = [dict objectForKey:@"biz_content"];
  179. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:bizDict options:NSJSONWritingPrettyPrinted error: &error];
  180. NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
  181. NSString* jsonString1 = [[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding];
  182. NSString *jsonString2 = [jsonString1 stringByReplacingOccurrencesOfString:@" : " withString:@":"];
  183. [contentString appendFormat:@"biz_content=%@&",jsonString2];
  184. }else{
  185. [contentString appendFormat:@"%@=%@&", categoryId, [dict valueForKey:categoryId]];
  186. }
  187. }
  188. }
  189. return contentString;
  190. }
  191. //dic > string
  192. + (NSString *)dictionaryToJsonString:(NSDictionary *)dic
  193. {
  194. NSError *parseError = nil;
  195. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
  196. return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  197. }
  198. //jsonString > dic
  199. + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
  200. if (jsonString == nil) {
  201. return nil;
  202. }
  203. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  204. NSError *err;
  205. if (jsonData == nil) {
  206. return nil;
  207. }
  208. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
  209. options:NSJSONReadingMutableContainers
  210. error:&err];
  211. if(err) {
  212. // NSLog(@"json解析失败:%@",err);
  213. ShowMsg([NSString stringWithFormat:@"数据解析失败,%@",err]);
  214. return nil;
  215. }
  216. return dic;
  217. }
  218. + (void)requestAnythingWithURL:(NSString *)urlString array:(NSArray *)aAarray data:(NSData *)uplownData completion:(MyBlockType)finishBlock
  219. {
  220. if (uplownData) {//有媒体数据上传的请求
  221. NSString *httpUrl = defaultHttp;
  222. NSString *defaultUpload = defaultUploadUrl;
  223. NSString *urlS = [NSString stringWithFormat:@"%@%@%@",httpUrl,defaultUpload,urlString];
  224. [urlS stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  225. AFHTTPSessionManager *afSessionManager = [AFHTTPSessionManager manager];
  226. afSessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
  227. afSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  228. afSessionManager.responseSerializer.acceptableContentTypes = [afSessionManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  229. afSessionManager.requestSerializer.timeoutInterval = 30;
  230. [jiaPeiManager QMLog:urlS obj:aAarray];
  231. [afSessionManager POST:urlS parameters:nil headers:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
  232. int k = 0;
  233. for (NSData *uplownData in aAarray) {
  234. NSString *typeString = [Tools typeForImageData:uplownData];
  235. NSString *fileType = [NSString stringWithFormat:@"image.%@",typeString];
  236. NSString *mimeType = [NSString stringWithFormat:@"image/%@",typeString];
  237. k ++;
  238. [formData appendPartWithFileData:uplownData
  239. name:[NSString stringWithFormat:@"photo%d",k]
  240. fileName:fileType
  241. mimeType:mimeType];
  242. }
  243. } progress:^(NSProgress * _Nonnull uploadProgress) {
  244. //NSLog(@"uploadProgress----><>%@-----><>%@",urlS,uploadProgress);
  245. } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  246. if (responseObject == nil) {
  247. NSDictionary *dic = nil;
  248. finishBlock(dic);
  249. return;
  250. }
  251. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject
  252. options:NSJSONReadingMutableContainers
  253. error:nil];
  254. //请求成功
  255. //NSLog(@"上传图片-----><>%@----><>%@",urlS,dic);
  256. [jiaPeiManager QMLog:urlS obj:dic];
  257. RemoveHUD();
  258. finishBlock(dic);
  259. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  260. //请求失败
  261. // NSLog(@"上传---><>%@",error);
  262. [jiaPeiManager QMLog:urlS obj:error.description];
  263. RemoveHUD();
  264. //失败的时候 要把失败的事情传输回去
  265. if ([error.domain isEqualToString:NSURLErrorDomain]) {
  266. // network error
  267. finishBlock(@{@"code" : @"1",@"body" : @"请检查网络连接"});
  268. } else {
  269. NSString *errorStr = [NSError rq_tipsFromError:error];
  270. if (errorStr && ![errorStr isEqualToString:@""]) {
  271. finishBlock(@{@"code" : @"1",@"body" : errorStr});
  272. } else {
  273. NSDictionary *dic = nil;
  274. finishBlock(dic);
  275. }
  276. }
  277. }];
  278. }else{//无媒体数据上传的请求
  279. NSDictionary *dic = [jiaPeiManager getDicWithArray:aAarray];
  280. if (aAarray == nil) {
  281. dic = nil;
  282. }else {
  283. NSArray *keyArr = @[@"userOutId", @"stuOutId", @"queryValue", @"outId", @"stuId"];
  284. NSPredicate * filterPredicate = [NSPredicate predicateWithFormat:@"SELF IN %@",keyArr];
  285. NSArray * filter = [[dic allKeys] filteredArrayUsingPredicate:filterPredicate];
  286. if (filter.count > 0) {
  287. if (!dic[filter.firstObject] || [dic[filter.firstObject] length] < 1) {
  288. ShowMsg(@"未绑定运管账号,无法进行此操作");
  289. return;
  290. }
  291. }
  292. }
  293. //生成请求加密后的url
  294. NSString *urlS = [jiaPeiManager getURLWithDict:dic urlPre:urlString];
  295. [jiaPeiManager QMLog:urlS obj:dic];
  296. if (![urlString isEqualToString:@"getSchInfoListByTujian"]) {
  297. NSLog(@"发起请求---urlString---><>%@--->\n%@",urlS,dic);
  298. }
  299. //设置请求管理器
  300. AFHTTPSessionManager *afSessionManager = [AFHTTPSessionManager manager];
  301. afSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
  302. afSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  303. afSessionManager.responseSerializer.acceptableContentTypes = [afSessionManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  304. afSessionManager.requestSerializer.timeoutInterval = [urlString isEqualToString:@"uploadEduPic"]? 60 : 30;
  305. [afSessionManager POST:urlS parameters:dic headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  306. //请求成功
  307. if (responseObject == nil) {
  308. NSDictionary *dic = nil;
  309. finishBlock(dic);
  310. return;
  311. }
  312. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject
  313. options:NSJSONReadingMutableContainers
  314. error:nil];
  315. if (![urlString isEqualToString:@"getSchInfoListByTujian"]) {
  316. NSLog(@"请求成功123---urlString---><>%@--->\n%@",urlS,dic);
  317. }
  318. [jiaPeiManager QMLog:urlS obj:dic];
  319. finishBlock(dic);
  320. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  321. //请求失败
  322. // NSLog(@"请求失败123----><>%@",error);
  323. RemoveHUD();
  324. [jiaPeiManager QMLog:urlS obj:error.description];
  325. //失败的时候 要把失败的事情传输回去
  326. if ([error.domain isEqualToString:NSURLErrorDomain]) {
  327. // network error
  328. finishBlock(@{@"code" : @"1",@"body" : @"请检查网络连接"});
  329. } else {
  330. NSString *errorStr = [NSError rq_tipsFromError:error];
  331. if (errorStr && ![errorStr isEqualToString:@""]) {
  332. finishBlock(@{@"code" : @"1",@"body" : errorStr});
  333. } else {
  334. NSDictionary *dic = nil;
  335. finishBlock(dic);
  336. }
  337. }
  338. }];
  339. }
  340. }
  341. + (void)requestGetAnythingWithURL:(NSString *)urlString completion:(MyBlockType)finishBlock {
  342. [self requestGetAnythingWithURL:urlString array:nil appendurlString:nil completion:finishBlock];
  343. }
  344. + (void)requestGetAnythingWithURL:(NSString *)urlString appendurlString:(NSString *)appendurlString completion:(MyBlockType)finishBlock {
  345. [self requestGetAnythingWithURL:urlString array:nil appendurlString:appendurlString completion:finishBlock];
  346. }
  347. + (void)requestGetAnythingWithURL:(NSString *)urlString array:(NSArray *)array completion:(MyBlockType)finishBlock {
  348. [self requestGetAnythingWithURL:urlString array:array appendurlString:nil completion:finishBlock];
  349. }
  350. + (void)requestGetWithURL:(NSString *)urlString array:(NSArray *)array appendurlString:(NSString *)appendurlString completion:(MyBlockType)finishBlock
  351. {
  352. NSString *urlS = [NSString stringWithFormat:@"%@/%@",coachDefaultHttp,urlString];
  353. //设置请求管理器
  354. AFHTTPSessionManager *afSessionManager = [AFHTTPSessionManager manager];
  355. afSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
  356. afSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  357. afSessionManager.requestSerializer.timeoutInterval = 30;
  358. /// 安全策略
  359. AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
  360. //allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO
  361. //如果是需要验证自建证书,需要设置为YES
  362. securityPolicy.allowInvalidCertificates = YES;
  363. //validatesDomainName 是否需要验证域名,默认为YES;
  364. //假如证书的域名与你请求的域名不一致,需把该项设置为NO
  365. //主要用于这种情况:客户端请求的是子域名,而证书上的是另外一个域名。因为SSL证书上的域名是独立的,假如证书上注册的域名是www.google.com,那么mail.google.com是无法验证通过的;当然,有钱可以注册通配符的域名*.google.com,但这个还是比较贵的。
  366. securityPolicy.validatesDomainName = NO;
  367. afSessionManager.securityPolicy = securityPolicy;
  368. /// 支持解析
  369. afSessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
  370. @"text/json",
  371. @"text/javascript",
  372. @"text/html",
  373. @"text/plain",
  374. @"text/html; charset=UTF-8",
  375. nil];
  376. NSMutableDictionary *parameters = nil;
  377. if(array&&array.count){
  378. parameters = [NSMutableDictionary dictionary];
  379. for (NSDictionary *item in array) {
  380. [parameters addEntriesFromDictionary:item];
  381. }
  382. }
  383. [jiaPeiManager QMLog:urlS obj:array];
  384. [afSessionManager GET:urlS parameters:parameters headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  385. //NSLog(@"请求返回123-------><>%@",responseObject);
  386. if (responseObject == nil) {
  387. NSDictionary *dic = nil;
  388. finishBlock(dic);
  389. return;
  390. }
  391. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject
  392. options:NSJSONReadingMutableContainers
  393. error:nil];
  394. //NSLog(@"请求返回123---------><>%@",dic);
  395. [jiaPeiManager QMLog:urlS obj:dic];
  396. finishBlock(dic);
  397. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  398. [jiaPeiManager QMLog:urlS obj:error.description];
  399. //失败的时候 要把失败的事情传输回去 @{@"code":@"1",@"body":@"请求失败"}
  400. //在AFNetworking方法error代码块中
  401. if ([error.domain isEqualToString:NSURLErrorDomain]) {
  402. // network error
  403. finishBlock(@{@"code" : @"1",@"body" : @"请检查网络连接"});
  404. } else {
  405. NSString *errorStr = [NSError rq_tipsFromError:error];
  406. if (errorStr && ![errorStr isEqualToString:@""]) {
  407. finishBlock(@{@"code" : @"1",@"body" : errorStr});
  408. } else {
  409. NSDictionary *dic = nil;
  410. finishBlock(dic);
  411. }
  412. }
  413. }];
  414. }
  415. + (void)requestGetAnythingWithURL:(NSString *)urlString array:(NSArray *)array appendurlString:(NSString *)appendurlString completion:(MyBlockType)finishBlock {
  416. //生成请求加密后的url
  417. NSString *urlS = [jiaPeiManager getURLWithDict:[jiaPeiManager getDicWithArray:array] urlPre:urlString];
  418. if (appendurlString) {
  419. NSMutableString *mutlStr = [NSMutableString stringWithString:urlS];
  420. NSRange range = [urlS rangeOfString:urlString];
  421. [mutlStr insertString:appendurlString atIndex:NSMaxRange(range)];
  422. urlS = mutlStr.copy;
  423. }
  424. // NSLog(@"-----><>%@--------><>%@",urlString,urlS);
  425. //设置请求管理器
  426. AFHTTPSessionManager *afSessionManager = [AFHTTPSessionManager manager];
  427. afSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
  428. afSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  429. [jiaPeiManager QMLog:urlS obj:array];
  430. [afSessionManager GET:urlS parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  431. //NSLog(@"请求返回123-------><>%@",responseObject);
  432. if (responseObject == nil) {
  433. NSDictionary *dic = nil;
  434. finishBlock(dic);
  435. return;
  436. }
  437. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject
  438. options:NSJSONReadingMutableContainers
  439. error:nil];
  440. //NSLog(@"请求返回123---------><>%@",dic);
  441. [jiaPeiManager QMLog:urlS obj:dic];
  442. finishBlock(dic);
  443. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  444. [jiaPeiManager QMLog:urlS obj:error.description];
  445. //失败的时候 要把失败的事情传输回去 @{@"code":@"1",@"body":@"请求失败"}
  446. //在AFNetworking方法error代码块中
  447. if ([error.domain isEqualToString:NSURLErrorDomain]) {
  448. // network error
  449. finishBlock(@{@"code" : @"1",@"body" : @"请检查网络连接"});
  450. } else {
  451. NSString *errorStr = [NSError rq_tipsFromError:error];
  452. if (errorStr && ![errorStr isEqualToString:@""]) {
  453. finishBlock(@{@"code" : @"1",@"body" : errorStr});
  454. } else {
  455. NSDictionary *dic = nil;
  456. finishBlock(dic);
  457. }
  458. }
  459. }];
  460. }
  461. + (void)requestPostAnythingWithURL:(NSString *)urlString parameters:(NSDictionary *)parameters completion:(MyBlockType)finishBlock
  462. {
  463. //生成请求加密后的url
  464. NSString *urlS = [jiaPeiManager getURLWithDict:nil urlPre:urlString];
  465. // NSLog(@"-----><>%@--------><>%@",urlString,urlS);
  466. //设置请求管理器
  467. AFHTTPSessionManager *afSessionManager = [AFHTTPSessionManager manager];
  468. afSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
  469. afSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  470. [afSessionManager POST:urlS parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  471. //NSLog(@"请求返回123-------><>%@",responseObject);
  472. if (responseObject == nil) {
  473. NSDictionary *dic = nil;
  474. finishBlock(dic);
  475. return;
  476. }
  477. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject
  478. options:NSJSONReadingMutableContainers
  479. error:nil];
  480. //NSLog(@"请求返回123---------><>%@",dic);
  481. finishBlock(dic);
  482. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  483. //失败的时候 要把失败的事情传输回去 @{@"code":@"1",@"body":@"请求失败"}
  484. //在AFNetworking方法error代码块中
  485. if ([error.domain isEqualToString:NSURLErrorDomain]) {
  486. // network error
  487. finishBlock(@{@"code" : @"1",@"body" : @"请检查网络连接"});
  488. } else {
  489. NSString *errorStr = [NSError rq_tipsFromError:error];
  490. if (errorStr && ![errorStr isEqualToString:@""]) {
  491. finishBlock(@{@"code" : @"1",@"body" : errorStr});
  492. } else {
  493. NSDictionary *dic = nil;
  494. finishBlock(dic);
  495. }
  496. }
  497. }];
  498. }
  499. #pragma mark 公共请求
  500. +(void)requestADImage
  501. {
  502. if (![Util connectedToNetWork]) {
  503. NSString *filePath = [Tools getPathWithFileName:@"ads.plist"];
  504. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  505. NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
  506. myDelegate.adArray = arr;
  507. }
  508. }
  509. NSMutableArray *arr=[NSMutableArray array];
  510. [arr addPro:@"type" Value:@"4"];
  511. NSString* method = @"getAppAdsNew";
  512. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  513. RemoveHUD();
  514. if (!root || [root[@"code"] isEqualToString:@"1"]) {
  515. //如果没广告图片 就从这里获取
  516. NSString *filePath = [Tools getPathWithFileName:@"ads.plist"];
  517. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  518. NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
  519. myDelegate.adArray = arr;
  520. }
  521. }else{
  522. //有广告 就更新本地广告
  523. if ([(NSArray *)root[@"body"] count] > 0) {
  524. myDelegate.adArray = root[@"body"];
  525. NSString *filePath = [Tools getPathWithFileName:@"ads.plist"];
  526. [root[@"body"] writeToFile:filePath atomically:YES];
  527. }
  528. }
  529. //这个判断是否可以在广告加载钱接收到广告 其实和放另一个地方是一样的效果
  530. NSMutableArray *array = [NSMutableArray array];
  531. for (NSDictionary *dic in myDelegate.adArray) {
  532. if ([dic[@"LOCATION"] isEqualToString:@"100"]) {
  533. [array addObject:dic[@"IMG"]];
  534. }
  535. }
  536. RQ_COMMON_MANAGER.adPaths = array;
  537. NSMutableArray *adMutArr = [NSMutableArray array];
  538. [[[myDelegate.adArray.rac_sequence.signal deliverOnMainThread] filter:^BOOL(NSDictionary *dict) {
  539. if ([dict[@"OPENTYPE"] isEqualToString:@"2"] || [dict[@"OPENTYPE"] isEqualToString:@"3"]) {
  540. return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]];
  541. } else {
  542. return YES;
  543. }
  544. }] subscribeNext:^(NSDictionary *dict) {
  545. [adMutArr addObject:dict];
  546. } completed:^{
  547. myDelegate.adArray = adMutArr.copy;
  548. NSString *filePath = [Tools getPathWithFileName:@"ads.plist"];
  549. [root[@"body"] writeToFile:filePath atomically:YES];
  550. [[NSNotificationCenter defaultCenter] postNotificationName:@"updateAD" object:@"isSuccess"];
  551. }];
  552. }];
  553. }
  554. /**主要是为了更新用户数据.
  555. 比如上传头像后
  556. */
  557. +(void)reLoginWithCompletion:(BlockTypeVo)finishBlcok
  558. {
  559. NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
  560. NSMutableArray *arr=[NSMutableArray array];
  561. NSDictionary *udDic = [ud objectForKey:@"jiaPeiLoginTest"];
  562. if ([udDic[@"loginType"] isEqualToString:@"1"]) {
  563. [arr property:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.loginCode)? RQ_USER_MANAGER.currentUser.loginCode : @"" forKey:@"loginCode"];
  564. [arr property:RQ_USER_MANAGER.currentUser.password forKey:@"password"];
  565. [arr property:@"" forKey:@"openId"]; //如果是第三方登录 填写token nickName
  566. [arr property:@"" forKey:@"nickName"]; //如果是第三方登录 填写获取到的昵称
  567. [arr property:@"" forKey:@"photo"]; //如果是第三方登录 填写获取到的照片全路径
  568. [arr property:@"" forKey:@"sex"]; //如果是第三方登录 填写获取到的用户性别
  569. }else{
  570. [arr property:@"" forKey:@"loginCode"];
  571. [arr property:@"" forKey:@"password"];
  572. [arr property:udDic[@"openId"] forKey:@"openId"]; //如果是第三方登录 填写token
  573. [arr property:udDic[@"nickName"] forKey:@"nickName"]; //如果是第三方登录 填写获取到的昵称
  574. [arr property:udDic[@"photo"] forKey:@"photo"]; //如果是第三方登录 填写获取到的照片全路径
  575. [arr property:udDic[@"sex"] forKey:@"sex"]; //如果是第三方登录 填写获取到的用户性别
  576. }
  577. [arr property:udDic[@"loginType"] forKey:@"loginType"];//登录类型
  578. [arr property:@"2" forKey:@"appType"];
  579. NSString *systemName = [[UIDevice currentDevice] systemName];
  580. NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
  581. [arr property:[NSString stringWithFormat:@"%@%@",systemName,systemVersion] forKey:@"systemVersion"];
  582. NSString *identifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
  583. NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  584. [arr property:[NSString stringWithFormat:@"%@%@",identifier,currentVersion] forKey:@"version"];
  585. NSString* method = @"stuLogin";
  586. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  587. RemoveHUD();
  588. //NSLog(@"更新数据-->%@-----%@",arr,dict);
  589. if (!dict) {
  590. return;
  591. }
  592. if ( [dict[@"code"] isEqualToString:@"1"]) {
  593. return ;
  594. }
  595. if ( [dict[@"code"] isEqualToString:@"0"]) {
  596. }
  597. //更新信息
  598. // defUser.userDict = [NSMutableDictionary dictionaryWithDictionary:dict[@"body"]];
  599. // if ([defUser.userDict[@"schInfo"] isKindOfClass:[NSDictionary class]])
  600. // {
  601. // defUser.userSchDict = [NSMutableDictionary dictionaryWithDictionary:defUser.userDict[@"schInfo"]];
  602. // }else{
  603. // defUser.userSchDict = nil;
  604. // }
  605. RQUserModel *user = [RQUserModel modelWithDictionary:[NSMutableDictionary dictionaryWithDictionary:dict[@"body"]]];
  606. /// 存储用户数据
  607. [RQ_USER_MANAGER loginUser:user];
  608. myDelegate.isLogin = YES;
  609. [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
  610. }];
  611. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {}];
  612. if (finishBlcok) {
  613. finishBlcok();
  614. }
  615. }];
  616. }
  617. //QM-console-log
  618. + (void)QMLog:(NSString *)urlString obj:(id )obj
  619. {
  620. #if defined(DEBUG)||defined(_DEBUG)
  621. if(isOffQMConsole){
  622. NSMutableString *log = [NSMutableString stringWithFormat:@">>>>>>>>>>>>>>>>>>>>>jiaPeiManager>>>>>>>>>>>>>>>>>>>>>>>>>>"];
  623. [log appendFormat:@"urlString=======>:%@", urlString];
  624. [log appendFormat:@"obj======>:%@", obj];
  625. [log appendString:@"<<<<<<<<<<<<<<<<<<<<<jiaPeiManager<<<<<<<<<<<<<<<<<<<<<<<<<<"];
  626. [QMUIConsole log:log];
  627. }
  628. #endif
  629. }
  630. + (void)QMLogStr:(NSString *)log
  631. {
  632. if(isOffQMConsole){
  633. [QMUIConsole log:log];
  634. }
  635. }
  636. @end
  637. void DubugLog(NSString *logString)
  638. {
  639. if (!isOfficial) {
  640. NSLog(@"%@",logString);
  641. }
  642. }