YH_HttpEngine.m
46.1 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
//
// YH_HttpEngine.m
// YH_FRAME
//
// Created by Leo on 14-5-23.
// Copyright (c) 2014年 YOHO. All rights reserved.
//
#import "YH_HttpEngine.h"
#import "YH_HttpDNS.h"
#import "YH_HTTPRequestOperationManager.h"
#import "YH_HTTPRequestSerializer.h"
#import "UtilsMacros.h"
#import "NSDictionary+YOHO.h"
#import "YH_Log.h"
#import "NSString+YOHO.h"
#define YoHoErrorDomain @"YOHOErrorDomain"
#define YH_ServiceHost @"http://dev-service.yohops.com:9999"
#define YH_SingleApiHost @"http://192.168.102.31:8092/brower"
#define YH_CmtApiHost @"http://192.168.102.31:8095/social"
#define YH_LiveHost @"http://api.live.yoho.cn/v1/living/detail"
#define YH_SocketAddress @"http://api.live.yoho.cn/v1/system/gethosts"
//
// YH_APIConstants.h
// YH_Mall
//
// Created by Cloud on 15/1/22.
// Copyright (c) 2015年 YOHO. All rights reserved.
//
#ifndef YH_Mall_YH_APIConstants_h
#define YH_Mall_YH_APIConstants_h
//错误信息
#define YoHoErrorDomain @"YOHOErrorDomain"
#define YoHoErrorCode -10000
#define YoHoErrorCodeInputNil -10001
#define YoHoErrorCodeNotLogin -10002
#define YoHoErrorCodeOverFlow -10003
//接口公共参数
#define kKeyJSONPrivate @"private_key"
#define kKeyJSONClient @"client_secret"
#define kIphonePrivate @"a85bb0674e08986c6b115d5e3a4884fa"
#define kIpadPrivate @"ad9fcda2e679cf9229e37feae2cdcf80"
#define kClientSecret @"client_secret"
#define kAppVersion @"app_version"
#define kV @"v"
#define kOsVersion @"os_version"
#define kClientType @"client_type"
#define kScreenSize @"screen_size"
#ifdef TESTENV
#define kServiceType @"7"
#else
#define kServiceType @"7"
#endif
#define YH_ApiHost @"http://dev-api.yohops.com:9999"
static NSInteger const kCode_AddFavErrorCode = 413;
//公有
static NSString* const kJSONKeyMethod = @"method";
static NSString* const kJSONKeyPlatform = @"platform";
static NSString* const kJSONKeyAppChannel = @"yh_channel";
static NSString* const kJSONKeyStoreId = @"shop_id";
static NSString* const kJSONKeyProductPool = @"productPool";
static NSString* const kJSONKeyOutlets = @"outlets";
static NSString* const kJSONKeyGender = @"gender";
static NSString* const kJSONKeyPage = @"page";
static NSString* const kJSONKeyTotalPage = @"total_page";
static NSString* const kJSONKeyTotal = @"total";
static NSString* const kJSONKeyPageSize = @"pagesize";
static NSString* const kJSONValuePageSize = @"20";
static NSString* const kJSONKeyLimit = @"limit";
static NSString* const kJSONKeyCode = @"code";
static NSString* const kJSONKeyContentCode = @"content_code";
static NSString* const kJSONKeyUrl = @"url";
static NSString* const kJSONKeyOpenID = @"opend_id";
static NSString* const kJSONKeyUid = @"uid";
static NSString* const kJSONKeyData = @"data";
static NSString* const kJSONKeyList = @"list";
static NSString* const kJSONKeyMessage = @"message";
static NSString* const kJSONKeyMobile = @"mobile";
static NSString* const YHBAPIErrorDomain = @"YHBAPIErrorDomain";
static NSString* const kJSONKeyIsSupportApplePay = @"is_support_apple_pay";
//获取gende 图片数据(app.cover.getNewCover)
static NSString* const kJSONValueNewCover = @"app.cover.getNewCover";
static NSString* const kJSONMethodLaunchAd = @"app.cover.getCoverStart";
//获取浮动广告(app.cover.getfloat)
static NSString* const kJSONMethodFloat = @"app.cover.getfloat";
//品类、品牌搜索 (app.search.getSort、app.search.getBrand)
static NSString* const kJSONValueGetSortMethod = @"app.search.getSort";
static NSString* const kJSONKeyType = @"type";
static NSString* const kJSONKeyMisort = @"misort";
static NSString* const kJSONKeyMsort = @"msort";
static NSString* const kJSONKeySubCategory = @"subCategoryId";
static NSString* const kJSONKeyCategory = @"categoryId";
static NSString* const kJSONKeySize = @"size";
static NSString* const kJSONKeyBrand = @"brand";
static NSString* const kJSONKeyColor = @"color";
static NSString* const kJSONKeyAge = @"age_level";
static NSString* const kJSONKeyPrice = @"price";
static NSString* const kJSONKeyPd = @"p_d";
static NSString* const kJSONKeyShelveTime = @"shelve_time";
static NSString* const kJSONKeyOrder = @"order";
static NSString* const kJSONKeyID = @"id";
static NSString* const kJSONKeyBrandId = @"brand_id";
static NSString* const kJSONKeyFavoriteFavId = @"fav_id";
//品牌
static NSString *const kJSONValueBrandList = @"app.brand.brandlist";//品牌列表
static NSString *const kJSONValueNewBrandList = @"app.brand.newBrandList";
static NSString *const kJSONValueBrandIntro = @"app.brand.getBrandIntro";//品牌简介
static NSString *const kJSONValueBrandBanner = @"app.brand.banner";//品牌banner
static NSString* const kJSONValueAddFavorite = @"app.favorite.add";//添加收藏
static NSString* const kJSONValueCancelFavorite = @"app.favorite.cancel";//取消收藏
static NSString* const kJSONValueSearchBrand = @"app.search.getBrand";//品牌商品
static NSString* const kJSONValueSortGet = @"app.sort.get";//分类列表
static NSString* const kJSONMethodBrandListing = @"app.brand.listing";
//店铺
static NSString *const kJSONValueStoreIntro = @"app.shops.getIntro";//查询店铺介绍接口
static NSString *const kJSONValueStoreSortInfo = @"app.shop.getSortInfo";//店铺品类列表
static NSString *const kJSONValueStoreBrands = @"app.shops.getShopsBrands";//店铺品牌列表
static NSString *const kJSONValueStoredBanner = @"app.shop.banner";//店铺banner
//地址管理
static NSString* const kJSONMethodGetAddress = @"app.address.gethidden";
static NSString* const kJSONMethodAddAddress = @"app.address.add";
static NSString* const kJSONMEthodUpdateAddress = @"app.address.update";
static NSString* const kJSONMethodDeleteAddress = @"app.address.del";
static NSString* const kJSONMethodGetProvince = @"app.address.getlist";//@"app.address.provinces";
static NSString* const kJSONMethodSetDefaultAddress = @"app.address.setdefault";
//购物车(app.Shopping.cart)
static NSString* const kJSONValueShoppingCart = @"app.Shopping.cart";
static NSString* const kJSONValueShoppingCartIncrease = @"app.Shopping.increase"; // 购物车 ‘+’
static NSString* const kJSONValueShoppingCartDecrease = @"app.Shopping.decrease"; // 购物车 ‘-’
static NSString* const kJSONValueShoppingCartSwap = @"app.Shopping.swap";
static NSString *const kJSONMethodBuyYohoodTicket = @"app.shopping.ticket";
static NSString *const kJSONMethodSubmitYohoodTicketOrder = @"app.shopping.submitTicket";
static NSString *const kJSONMethodGetQROrderCode = @"app.SpaceOrders.getQrByOrderCode";
static NSString* const kJSONKeyShoppingKey = @"shopping_key";
static NSString* const kJSONKeyProductSku = @"product_sku";
static NSString* const kJSONKeyOrderCode = @"order_code";
static NSString* const kJSONKeyUseYohoCoin = @"use_yoho_coin";
static NSString* const kJSONKeyOldProductSku = @"old_product_sku";
static NSString* const kJSONKeyNewProductSku = @"new_product_sku";
static NSString* const kJSONKeySwapData = @"swap_data";
static NSString* const kJSONKeyBuyNum = @"buy_number";
static NSString* const kJSONKeyIncreaseNum = @"increase_number";
static NSString* const kJSONKeyDecreaseNum = @"decrease_number";
static NSString *const kJSONKeyEditProductSku = @"edit_product_sku";
static NSString *const kJSONKeyShoppingCarType = @"cart_type";
static NSString *const kJSONKeyPromotionID = @"promotion_id";
static NSString *const kJSONKeyGoodsType = @"goods_type";
static NSString *const kJSONKeyIsSelected = @"selected";
static NSString *const kJSONKeyFrom = @"from";
static NSString *const kJSONValueGoodsTypeOrdinary = @"ordinary"; // 普通
static NSString *const kJSONValueGoodsTypePriceGift = @"price_gift"; // 加价购
static NSString *const kJSONValueGoodsTypeGift = @"gift"; // 赠品
static NSString *const kJSONValueGoodsTypeAdvance = @"advance"; // 预售商品
static NSString *const kJSONValueGoodsTypeFree = @"free"; // 面单商品
static NSString *const kJSONValueGoodsTypeOutlet = @"outlet"; // 批发
static NSString *const kJSONValueGoodsTypeAll = @"all"; // 全选
//获取购物车商品总数(app.Shopping.count)
static NSString *const kJSONValueShoppingCount = @"app.Shopping.count";
static NSString *const kJSONKeyShoppingCarGoodsCount = @"cart_goods_count";
//添加商品到购物车(app.Shopping.add)
static NSString* const kJSONValueAddShoppingCart = @"app.Shopping.add";
//购物车结算(app.Shopping.payment)
static NSString* const kJSONValueShoppingCartPayment = @"app.Shopping.payment";
static NSString *const kJSONValueLimitProductPayment = @"app.Shopping.easyPayment";
//获取商品信息 (app.product.data)
static NSString* const kJSONValueProductData = @"app.product.data";
//获取商品促销信息
static NSString* const kJSONMethodGetProductPromotion = @"app.product.promotion";
//获取商品介绍 (app.product.intro)
static NSString* const kJSONValueProductIntro = @"app.product.intro";
static NSString* const kJSONValueProductNotifi = @"app.product.notify";
//通过brand_id查询所关联的店铺列表(app.shop.queryShopsByBrandId)
static NSString* const kJSONValueShopQueryByBrandId = @"app.shop.queryShopsByBrandId";
//获取潮流密码(app.config.fashioncodeTemplate)
static NSString* const kJSONValueTrendKey = @"app.config.fashioncodeTemplate";
/**
* 提交咨询(app.consult.add)
*/
static NSString* const kJSONValueConsultAdd = @"app.consult.add";
/**
* 咨询列表(app.consult.li)
*/
static NSString* const kJSONValueConsultLi = @"app.consult.li";
static NSString* const kJSONValueConsultCommon = @"app.consult.common";
static NSString* const kJSONValueConsultLike = @"app.consult.like";
static NSString* const kJSONValueConsultUseful = @"app.consult.useful";
//获取最近的两条咨询列表
static NSString* const kJSONValueConsultLastTwo = @"app.consult.lastTwo";
/**
* 评价列表(app.comment.li)
*/
static NSString* const kJSONValueEvaluationLi = @"app.comment.li";
//获取分享信息(app.activity.getshare)
static NSString* const kJSONValueActivityGetShare = @"app.activity.getshare";
//已分享统计(app.activity.addshare)
static NSString* const kJSONValueActivityAddShare = @"app.activity.addshare";
//账号绑定(app.activity.bindaccount)
static NSString* const kJSONValueActivityBindaccount = @"app.activity.bindaccount";
//移除购物车的单个商品
static NSString* const kAPIShoppingCartRemove = @"app.Shopping.removeAndCart"; //app.Shopping.remove
static NSString* const kJSONValueSkuList = @"product_sku_list";
//选择商品
static NSString* const kAPIShoppingCartSelected = @"app.Shopping.selectedAndCart"; //app.Shopping.selected
static NSString* const kJSONVAlueSelected = @"selected";
//购物车商品移入收藏夹
static NSString* const kAPIShoppingCartAddToFav = @"app.Shopping.addfavoriteAndCart"; //app.Shopping.addfavorite
//购物车修改打个商品
static NSString* const kAPIShoppingCartModify = @"app.Shopping.remove";
//退换货申请列表
static NSString* const kAPIRefundGetList = @"app.refund.getList";
//换货详情
static NSString* const kAPIChangeDetail = @"app.change.detail";
//退货详情
static NSString* const kAPIRefundDetail = @"app.refund.detail";
//取消退货
static NSString* const kAPIRefundCancel = @"app.refund.cancel";
//取消换货
static NSString *const kAPIChangeCancel = @"app.change.cancel";
//退货快递单设置
static NSString* const kAPIRefundExpressage = @"app.refund.setexpress";
//换货快递单设置
static NSString* const kAPIExchangeExpressage = @"app.change.setexpress";
//订单
static NSString* const kJSONMethodCancelOrder = @"app.SpaceOrders.close";
static NSString* const kJSONMethodDeleteOrder = @"app.SpaceOrders.delOrderByCode";
static NSString* const kJSONMethodBuyAgain = @"app.Shopping.readd";
static NSString* const kJSONMethodConfirmOrder = @"app.SpaceOrders.confirm";
static NSString* const kJSONMethodGetOrderList = @"app.SpaceOrders.get";
static NSString* const kJSONMethodGetOrderDetail = @"app.SpaceOrders.detail";//@"app.SpaceOrders.info";
static NSString* const kJSONMethodGetExpressDetail = @"app.express.li";
static NSString *const kJSONMethodGetExpressageList = @"app.express.getExpressCompany";
static NSString *const kJSONMethodSpaceOrdersPayConfirm = @"app.SpaceOrders.payConfirm";
static NSString *const kJSONMethodAoolePayConfirm = @"app.SpaceOrders.payConfirm";
static NSString *const kJSONMethodGetShareInfo = @"app.activity.getInfoOfOrderShare";
//热卖排行
static NSString *const kJSONMethodGetSearchTopList = @"app.search.top";
//退换货
static NSString* const kJSONMethodGetRefundGoodsList = @"app.refund.goodsList";
static NSString* const kJSONMethodGetRefundApplySubmit = @"app.refund.submit";
static NSString* const kJSONMethodGetExchangeGoodsList = @"app.change.goodsList";
static NSString* const kJSONMethodGetExchangeDeliveryType = @"app.change.getDelivery";
static NSString* const kJSONMethodGetExchangeApplySubmit = @"app.change.submit";
static NSString* const kJSONMethodWaitCommentProduct = @"app.comment.product";
static NSString* const kJSONMethodAddComment = @"app.comment.add";
static NSString* const kJSONMethodGetNewExpress = @"app.express.getNewExpress";
//领取生日券
static NSString* const kJSONMethodCouponSendCode = @"app.promotion.sendCheckCode";
static NSString* const kJSONMethodVerifyCode = @"app.promotion.validCode";
static NSString* const kJSONMethodGetCouponList = @"app.promotion.queryBirthCoupon";
static NSString* const kJSONMethodGetCoupon = @"app.promotion.getCoupon";
//获取赠品和加价购商品信息
static NSString* const kJSONValueGiftProduct = @"app.product.gift";
static NSString* const kJSONkeyGiftProductSkn = @"product_skn";
static NSString* const kJSONkeyGiftPromationID = @"promotion_id";
static NSString *const kContentCode_HomeBoy = @"201504091403001";
static NSString *const kContentCode_HomeGirl = @"201504091403002";
static NSString *const kContentCode_HomeKid = @"e9875682c1599a886bfbdb965b740022";
static NSString *const kContentCode_HomeLife = @"9aa25f5133f011ec96c2045eb15ae425";
static NSString *const kContentCode_HomeGlobal = @"f09603fce3a13f871b43db38b0a3b42b";
static NSString *const kContentCodeHomeBannerBoy = @"8c48745a39373d621bf5fd80edf59b5e";
static NSString *const kContentCodeHomeBannerGirl = @"c63939b2ad458e9cb51147940c1da2e5";
static NSString *const kContentCodeHomeBannerKid = @"";
static NSString *const kContentCodeHomeBannerLife = @"";
static NSString *const kContentCodeYohoCoinBanner = @"05afedf76886d732573f10f7451a1703";
static NSString *const kContentCodeLogisticBanner = @"1fc9b2484fcd559049f2f7e0db313f20";
static NSString *const kContentCodePaySuccessBanner = @"78d0fb6c97d691863286edcb4d8abfa9";
//签到页banner
static NSString *const kContentCodeSignBanner = @"b99901a444f488858b6200c1d553f4f3";
static NSString *const kConetentCodeTextAD = @"f9e5a5aabddeb4592299fdf5c6edd079";
static NSString *const kBrandBannerContentCodeForBoy = @"ce6ac059493ec26241a8cbe0bfa1b17a";
static NSString *const kBrandBannerContentCodeForGirl = @"dac99cdedc1f948e84c145aca561f7d2";
static NSString *const kBrandBannerContentCodeForLife = @"f1aa914fd23cbcda71a87de6f5416c75";
static NSString *const kBrandBannerContentCodeForKid = @"713784f93f52bb1a7b93916b2bb15510";
static NSString *const kBrandBannerContentCodeForGlobal = @"b9cf4567a36ae3c905f6f99c08727ad0";
static NSString *const kNewBannerContentCodeForBoy = @"a7989369aa86681c678bc40f171b8f1d";
static NSString *const kNewBannerContentCodeForGirl = @"b0ba12104cfecacdcfd7ad74117a22b8";
static NSString *const kNewBannerContentCodeForKid = @"c39607aa21219117976848819cf81a69";
static NSString *const kNewBannerContentCodeForLife = @"7c9ae01071f7a75d3911782feb4caebd";
static NSString *const kDiscountBannerContentCodeForBoy = @"7c2b77093421efa8ae9302c91460db73";
static NSString *const kDiscountBannerContentCodeForGirl = @"707222adfd1cb9e60a32a8ba706072ed";
static NSString *const kDiscountBannerContentCodeForKid = @"3f2550d6e2883c63028cd9d8850477bf";
static NSString *const kDiscountBannerContentCodeForLife = @"a305642bc73c34e19aa0af170df1e7bf";
static NSString *const kShortSizeBannerContentCodeForBoy = @"46c103030409b85f4abde76bec63fa85";
static NSString *const kShortSizeBannerContentCodeForGirl = @"d163fcd6d2868b17f63fda0e034bb393";
static NSString *const kShortSizeBannerContentCodeForKid = @"46ac23814c5241d521c990c3c10eefea";
static NSString *const kShortSizeBannerContentCodeForLife = @"7478a0fa5e8dbf3414dd4e83f1a376f7";
static NSString *const kVipProBannerContentCodeForBoy = @"03c68a478dee4544e97966fa5162aed0";
static NSString *const kVipProBannerContentCodeForGirl = @"22939d2544f29f297634831f795340c9";
static NSString *const kVipProBannerContentCodeForKid = @"e4210810f37fd45ecc01bec99e531741";
static NSString *const kVipProBannerContentCodeForLife = @"bd54b0e0927ae2b978c94451f0082946";
static NSString *const kRegisterSuccessBannerContentCode = @"b618d6dee43bdaade222752fdf0c154f";
static NSString *const kPaySuccessBannerForGlobal = @"aad57340faa976af2ccebba609b4b4c8";
static NSString *const kJSONMethodFavoriteKid = @"app.search.kids";
static NSString *const kJSONMethodFavorite = @"app.search.newLast7day";
static NSString *const kJSONMethodHotNew = @"app.search.lifeStyle";
static NSString *const kJSONMethodRecommendPop = @"app.recommend.popup";
//个人VIP
static NSString *const kJSONMethodModifyAvatar =@"app.passport.modifyHead";
static NSString *const kJSONMethodModifyInfo = @"app.passport.modifyBase";
static NSString *const kJSONMethodMyVIP = @"app.passport.vip";
static NSString *const kJSONMethodPrivilegeInfo = @"app.passport.getPrivilege";
//浏览记录
static NSString *const kJSONMethodBrowseHistory = @"app.browse.product";
static NSString *const kJSONMethodDeleteBrowse = @"app.browse.delete";
static NSString *const kJSONMethodGetDiscountList = @"app.activity.get";
static NSString *const kJSONMethodAddBrowseHistory = @"app.browse.addBrowseBatch";
//YOHOOD
#ifdef SUPPORT_YOHOOD
static NSString *const kJSONPathGetYHDModuleList = @"/getMobileModuleList";
static NSString *const kJSONMethodGetTicketSKN = @"Yohood.Ticket.ticketList";
static NSString *const kJSONMethodGetUserInfo = @"Yohood.passport.pass";
static NSString *const kJSONMethodIfBind = @"Yohood.passport.ifbinding";
static NSString *const kJSONMethodGetPasskit = @"yohood.passkit.get";
static NSString *const kJSONMethodTop10 = @"Yohood.LargeView.top";
static NSString *const kKeyJSONOpenKey = @"open_key";
#endif
//签到
static NSString *const kJSONMethodSignIn = @"app.sign.userSignInfo";
static NSString *const kJSONMethodUserSign = @"app.sign.userSign";
static NSString *const kJSONMethodChangePushFlag = @"app.sign.changePushFlag";
static NSString *const kJSONKeyPushFlag = @"pushFlag";
/**
* banner
*/
static NSString *const kIdentifier_Focus = @"focus";
/**
* 图标入口
*/
static NSString *const kIdentifier_App_Icon_List = @"app_icon_list";
/**
* 文字公告cell
*/
static NSString *const kIdentifier_TextAnnouncement = @"announcement";
/**
* 热门品牌推荐 男生
*/
static NSString *const kIdentifier_App_Hot_Brands = @"app_hot_brands";
/**
* 热门品牌推荐 女生
*/
static NSString *const kIdentifier_Hot_Brands = @"custom_brands";
/**
* 热门品牌推荐 潮童
*/
static NSString *const kIdentifier_Kids_Brands = @"kids_brands";
/**
* 一张大图一个大的推荐和4个小图推荐
*/
static NSString *const kIdentifier_Recommend_Content_One = @"recommend_content_one";
/**
* 创意生活(一张大图和6个小图推荐)
*/
static NSString *const kIdentifier_Recommend_Content_Two = @"recommend_content_two";
/**
* 女生1张大图 12个小图
*/
static NSString *const kIdentifier_Recommend_Content_Three = @"recommend_content_three";
/**
* 全球购,一张大图和2个大的推荐,T1+F2
*/
static NSString *const kIdentifier_Image_Group = @"imageGroup";
/**
* 女生title + 12个小图
*/
static NSString *const kIdentifier_Recommend_Content_Five = @"recommend_content_five";
/**
* 只有一张图片banner
*/
static NSString *const kIdentifier_Single_Image = @"single_image";
/**
* 带标题的图片banner
*/
static NSString *const kIdentifier_Single_Name_Image = @"single_name_image";
/**
* 潮品话题
*/
static NSString *const kIdentifier_Trendgoods_Topic = @"trendgoods_topic";
/**
* 潮人搭配固定内容
*/
static NSString *const kIdentifier_Trendsetter_Collocation = @"trendsetter_collocation";
/**
* 潮品话题cell
*/
static NSString *const kIdentifier_Trendsetter_Collocation_Cell = @"trend_goods_topic";
static NSString *const kIdentifier_Small_Pic = @"small_pic";
/**
* banner滚动cell
*/
static NSString *const kIdentifier_ImageBanner_Cell = @"imagebanner_cell";
/**
* 首页猜我喜欢列表
*/
static NSString *const kFloorProduct_Identifier = @"FloorProductIdentifier";
/**
* 首页底部banner
*/
static NSString *const kFloorBottomBanner_Identifier = @"FloorBottomBannerIdentifier";
/**
* 全球购潮流好物头部参数模版
*/
static NSString *const kIdentifier_Param_Group = @"paramsGroup";
/**
* 意见反馈红点key
*/
static NSString *const kFeedbackRedDot = @"FeedbackRedDot";
//新会员专享
static NSString *const kIdentifier_NewUser = @"new_user_floor";
//两张小图, 后台暂未实现,不可用
static NSString *const kIdentifier_TwoSmallPic = @"twoSmallPic";
//一左两右
static NSString *const kIdentifier_n_left_two_right = @"NL2R";
//品类导航
static NSString *const kIdentifier_category_navigation = @"categoryNavigation";
//即将上线 结束预告
static NSString *const kIdentifier_event_action = @"event_action";
/**
* @brief 有货直播楼层 资源位 3张图片 + 更多跳转
*
* @since 4.9
*/
static NSString *const kIdentifier_live_three = @"threePicture";
#endif
@implementation YH_HttpEngine
+ (instancetype)manager {
return [[self alloc] init];
}
+ (instancetype)roomEngine {
YH_HttpEngine *manager = [YH_HttpEngine manager];
[manager setHttpURLString:@"http://api.live.yoho.cn/v1/room/getpushroom"];
return manager;
}
+ (instancetype)validateAnchorEngine {
YH_HttpEngine *manager = [YH_HttpEngine manager];
[manager setHttpURLString:@"http://api.live.yoho.cn/v1/room/validmaster"];
return manager;
}
+ (instancetype)pushStatusEngine {
YH_HttpEngine *manager = [YH_HttpEngine manager];
[manager setHttpURLString:@"http://api.live.yoho.cn/v1/room/setstat"];
return manager;
}
+ (instancetype)roomListEngine {
YH_HttpEngine *manager = [YH_HttpEngine manager];
[manager setHttpURLString:@"http://api.live.yoho.cn/v1/room/getpushflow"];
return manager;
}
+ (instancetype)socketAddrEngine {
YH_HttpEngine *manager = [YH_HttpEngine manager];
[manager setHttpURLString:@"http://api.live.yoho.cn/v1/system/gethosts"];
return manager;
}
+ (instancetype)paymentEngine:(NSString *)hostName
{
YH_HttpEngine *engine = [YH_HttpEngine manager];
[engine setHttpURLString:hostName];
return engine;
}
- (NSString *)checkHttpsPrefix:(NSString *)urlString
{
return urlString;
}
+ (BOOL)handleRequestError:(AFHTTPRequestOperation *)operation response:(id)responseObject failBlock:(void (^)(AFHTTPRequestOperation *, NSError *))failure
{
NSString *message = [responseObject yh_stringForKey:@"message"];
NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
NSDictionary *userInfo = nil;
NSError *error = nil;
LogInfo(@"%ld",operation.response.statusCode);
if (operation.response.statusCode == 200) {
if (code == 9999991) {
return NO;
}else if (code == 9999992){
userInfo = [NSDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
error = [NSError errorWithDomain:YoHoErrorDomain code:code userInfo:userInfo];
BLOCK_EXEC(failure, operation, error);
return YES;
}
}
if (code != 200) {
if (IsNilOrNull(message) || IsStrEmpty(message)) {
userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"data format error", nil) forKey:NSLocalizedDescriptionKey];
error = [NSError errorWithDomain:YoHoErrorDomain code:YoHoErrorCode userInfo:userInfo];
}else{
userInfo = [NSDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
error = [NSError errorWithDomain:YoHoErrorDomain code:code userInfo:userInfo];
}
[YH_HttpEngine handlePocError:operation response:responseObject];
BLOCK_EXEC(failure, operation, error);
return YES;
}
return NO;
}
+ (void)handlePocError:(AFHTTPRequestOperation *)operation response:(id)responseObject
{
#ifdef APPYOHO
NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
NSString *url = operation.request.URL.absoluteString;
NSString *method = [operation.request.HTTPMethod uppercaseString];
NSString *body = [[NSString alloc] initWithData:operation.request.HTTPBody encoding:NSUTF8StringEncoding];
NSString *response = [responseObject description];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
//超时返回是0,但是为了和android的统一性,ios修改成-1。
if (code == 0) {
parameters[JsonKeyErrorEC] = @(-1);
} else {
parameters[JsonKeyErrorEC] = @(code);
}
if (!IsStrEmpty(url)) {
parameters[JsonKeyErrorEI] = url;
}
if (!IsStrEmpty(method)) {
parameters[JsonKeyErrorMethod] = method;
}
if (!IsStrEmpty(body)) {
parameters[JsonKeyErrorBody] = body;
}
if (!IsStrEmpty(response)) {
parameters[JsonKeyErrorResponse] = response;
}
// 上报网络错误
[[YH_Analytics sharedInstance] logError:kErrorTypePoc parameters:parameters];
#endif
}
+ (void)handleHTTPError:(AFHTTPRequestOperation *)operation error:(NSError *)error
{
#ifdef APPYOHO
NSString *url = operation.request.URL.absoluteString;
NSString *method = [operation.request.HTTPMethod uppercaseString];
NSString *body = [[NSString alloc] initWithData:operation.request.HTTPBody encoding:NSUTF8StringEncoding];
NSString *response = error.localizedDescription;
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
//超时返回是0,但是为了和android的统一性,ios修改成-1。
if (operation.response.statusCode == 0) {
parameters[JsonKeyErrorEC] = @(-1);
} else {
parameters[JsonKeyErrorEC] = @(operation.response.statusCode);
}
if (!IsStrEmpty(url)) {
parameters[JsonKeyErrorEI] = url;
}
if (!IsStrEmpty(method)) {
parameters[JsonKeyErrorMethod] = method;
}
if (!IsStrEmpty(body)) {
parameters[JsonKeyErrorBody] = body;
}
if (!IsStrEmpty(response)) {
parameters[JsonKeyErrorResponse] = response;
}
[[YH_Analytics sharedInstance] logError:kErrorTypeHTTP parameters:parameters];
#endif
}
- (void)post:(NSDictionary*)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
timeout:(NSTimeInterval)timeoutInterval
{
if (timeoutInterval <= 0) {
timeoutInterval = YHNetworkingTimeoutInterval;
}
//对数据进行鉴权
NSMutableDictionary *dic = [self encodeParams:parameters];
if ([self APIFilter:[dic yh_stringForKey:kJSONKeyMethod]]) {
BLOCK_EXEC(failure,nil,nil);
return;
}
//获取当前的url
NSString *url = IsStrEmpty(self.httpURLString)?YH_ApiHost:self.httpURLString;
url = [self checkHttpsPrefix:url];
AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer = [YH_HttpRequestSerializer serializer];
[requestSerializer setTimeoutInterval:timeoutInterval];
[manager setRequestSerializer:requestSerializer];
// if ([YH_Global sharedInstance].securityBodyVeify) {
// [manager setResponseSerializer:[YH_JSONResponseSerializer serializer]];
// }
DLog(@"Request: /n%@",url);
[[YH_HttpDNS shareInstance] getHostByNameAsync:url reqSerializer:requestSerializer dnsCallback:^(AFHTTPRequestSerializer<AFURLRequestSerialization> *requestSerializer, NSString *url) {
[manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([YH_HttpEngine handleRequestError:operation response:responseObject failBlock:failure]) {
return;
}
BLOCK_EXEC(success, operation, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[YH_HttpEngine handleHTTPError:operation error:error];
BLOCK_EXEC(failure, operation, error);
}];
}];
}
- (void)post:(NSDictionary *)parameters
success:(void (^)(AFHTTPRequestOperation *, id))success
failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure
{
[self post:parameters success:success failure:failure timeout:YHNetworkingTimeoutInterval];
}
- (void)post:(NSDictionary *)parameters resourcePath:(NSString *)path success:(void (^)(AFHTTPRequestOperation *, id))success failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure
{
//对数据进行鉴权
NSMutableDictionary *dic = [self encodeParams:parameters];
if ([self APIFilter:[dic yh_stringForKey:kJSONKeyMethod]] || [self APIFilter:path]) {
BLOCK_EXEC(failure,nil,nil);
return;
}
//获取当前的url
NSString *url = IsStrEmpty(self.httpURLString)?YH_ServiceHost:self.httpURLString;
url = [[self checkHttpsPrefix:url] stringByAppendingString:path];
AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer = [YH_HttpRequestSerializer serializer];
[requestSerializer setTimeoutInterval:YHNetworkingTimeoutInterval];
[manager setRequestSerializer:requestSerializer];
// if ([YH_Global sharedInstance].securityBodyVeify) {
// [manager setResponseSerializer:[YH_JSONResponseSerializer serializer]];
// }
[[YH_HttpDNS shareInstance] getHostByNameAsync:url reqSerializer:requestSerializer dnsCallback:^(AFHTTPRequestSerializer<AFURLRequestSerialization> *requestSerializer, NSString *url) {
[manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([YH_HttpEngine handleRequestError:operation response:responseObject failBlock:failure]) {
return;
}
BLOCK_EXEC(success, operation, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// if (operation.response.statusCode == 401) {
// [[NSNotificationCenter defaultCenter] postNotificationName:YH_LoginMgrNeedShowLoginVCNotifi object:nil];
// }
[YH_HttpEngine handleHTTPError:operation error:error];
BLOCK_EXEC(failure, operation, error);
}];
}];
}
- (void)post:(NSDictionary *)parameters resourcePath:(NSString *)path success:(void (^)(AFHTTPRequestOperation *, id))success failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure timeout:(NSTimeInterval)timeoutInterval
{
if (timeoutInterval <= 0) {
timeoutInterval = YHNetworkingTimeoutInterval;
}
//对数据进行鉴权
NSMutableDictionary *dic = [self encodeParams:parameters];
if ([self APIFilter:[dic yh_stringForKey:kJSONKeyMethod]] || [self APIFilter:path]) {
BLOCK_EXEC(failure,nil,nil);
return;
}
//获取当前的url
NSString *url = IsStrEmpty(self.httpURLString)?YH_ServiceHost:self.httpURLString;
url = [[self checkHttpsPrefix:url] stringByAppendingString:path];
AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer = [YH_HttpRequestSerializer serializer];
[requestSerializer setTimeoutInterval:timeoutInterval];
[manager setRequestSerializer:requestSerializer];
// if ([YH_Global sharedInstance].securityBodyVeify) {
// [manager setResponseSerializer:[YH_JSONResponseSerializer serializer]];
// }
[[YH_HttpDNS shareInstance] getHostByNameAsync:url reqSerializer:requestSerializer dnsCallback:^(AFHTTPRequestSerializer<AFURLRequestSerialization> *requestSerializer, NSString *url) {
[manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([YH_HttpEngine handleRequestError:operation response:responseObject failBlock:failure]) {
return;
}
BLOCK_EXEC(success, operation, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// if (operation.response.statusCode == 401) {
// [[NSNotificationCenter defaultCenter] postNotificationName:YH_LoginMgrNeedShowLoginVCNotifi object:nil];
// }
[YH_HttpEngine handleHTTPError:operation error:error];
BLOCK_EXEC(failure, operation, error);
}];
}];
}
- (AFHTTPRequestOperation *)POST:(NSDictionary *)parameters
constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block
completion:(void (^)(id response, NSError *error))completion
{
//对数据进行鉴权
NSMutableDictionary *dic = [self encodeParams:parameters];
if ([self APIFilter:[dic yh_stringForKey:kJSONKeyMethod]]) {
BLOCK_EXEC(completion,nil,nil);
return nil;
}
AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer = [YH_HttpRequestSerializer serializer];
[requestSerializer setTimeoutInterval:YHNetworkingTimeoutIntervalUpload];
[manager setRequestSerializer:requestSerializer];
[manager.requestSerializer setValue:@"admin.yohobuy.com" forHTTPHeaderField:@"HTTP_REFERER"];
// if ([YH_Global sharedInstance].securityBodyVeify) {
// [manager setResponseSerializer:[YH_JSONResponseSerializer serializer]];
// }
//获取当前的url
NSString *url = IsStrEmpty(self.httpURLString)?YH_ApiHost:self.httpURLString;
url = [self checkHttpsPrefix:url];
NSString *requestURL = [[YH_HttpDNS shareInstance] getHostByNameSync:url reqSerializer:requestSerializer];
AFHTTPRequestOperation *op = [manager POST:requestURL parameters:dic constructingBodyWithBlock:block success:^(AFHTTPRequestOperation *operation, id responseObject) {
BOOL flag = [YH_HttpEngine handleRequestError:operation response:responseObject failBlock:^(AFHTTPRequestOperation *operation, NSError *error) {
BLOCK_EXEC(completion, operation.responseObject, error);
}];
if (!flag) {
BLOCK_EXEC(completion, responseObject, nil);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
BLOCK_EXEC(completion, operation.responseObject, error);
}];
return op;
}
- (void)get:(NSDictionary*)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
//对数据进行鉴权
NSMutableDictionary *dic = [self encodeParams:parameters];
if ([self APIFilter:[dic yh_stringForKey:kJSONKeyMethod]]) {
BLOCK_EXEC(failure,nil,nil);
return;
}
//获取当前的url
NSString *url = IsStrEmpty(self.httpURLString)?YH_ApiHost:self.httpURLString;
url = [self checkHttpsPrefix:url];
AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer = [YH_HttpRequestSerializer serializer];
[requestSerializer setTimeoutInterval:YHNetworkingTimeoutInterval];
[manager setRequestSerializer:requestSerializer];
AFHTTPRequestOperation *opration = [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([YH_HttpEngine handleRequestError:operation response:responseObject failBlock:failure]) {
return;
}
BLOCK_EXEC(success, operation, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// if (operation.response.statusCode == 401) {
// [[NSNotificationCenter defaultCenter] postNotificationName:YH_LoginMgrNeedShowLoginVCNotifi object:nil];
// }
[YH_HttpEngine handleHTTPError:operation error:error];
BLOCK_EXEC(failure, operation, error);
}];
DLog(@"Request url: ..................\n%@",opration.request.URL.absoluteString);
}
- (void)get:(NSDictionary*)parameters resourcePath:(NSString *)path success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
//对数据进行鉴权
NSMutableDictionary *dic = [self encodeParams:parameters];
if ([self APIFilter:[dic yh_stringForKey:kJSONKeyMethod]] || [self APIFilter:path]) {
BLOCK_EXEC(failure,nil,nil);
return;
}
//获取当前的url
NSString *url = IsStrEmpty(self.httpURLString)?YH_ServiceHost:self.httpURLString;
url = [[self checkHttpsPrefix:url] stringByAppendingString:path];
AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer = [YH_HttpRequestSerializer serializer];
[requestSerializer setTimeoutInterval:YHNetworkingTimeoutInterval];
[manager setRequestSerializer:requestSerializer];
// if ([YH_Global sharedInstance].securityBodyVeify) {
// [manager setResponseSerializer:[YH_JSONResponseSerializer serializer]];
// }
[[YH_HttpDNS shareInstance] getHostByNameAsync:url reqSerializer:requestSerializer dnsCallback:^(AFHTTPRequestSerializer<AFURLRequestSerialization> *requestSerializer, NSString *url) {
[manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([YH_HttpEngine handleRequestError:operation response:responseObject failBlock:failure]) {
return;
}
BLOCK_EXEC(success, operation, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// if (operation.response.statusCode == 401) {
// [[NSNotificationCenter defaultCenter] postNotificationName:YH_LoginMgrNeedShowLoginVCNotifi object:nil];
// }
[YH_HttpEngine handleHTTPError:operation error:error];
BLOCK_EXEC(failure, operation, error);
}];
}];
}
- (void)getHtml:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *, id))success failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure {
//对数据进行鉴权
NSMutableDictionary *dic = [self encodeParams:parameters];
if ([self APIFilter:[dic yh_stringForKey:kJSONKeyMethod]]) {
BLOCK_EXEC(failure,nil,nil);
return;
}
//获取当前的url
NSString *url = IsStrEmpty(self.httpURLString)?YH_ApiHost:self.httpURLString;
url = [self checkHttpsPrefix:url];
AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
manager.requestSerializer = [YH_HttpRequestSerializer serializer];
// if ([YH_Global sharedInstance].securityBodyVeify) {
// [manager setResponseSerializer:[YH_HTTPResponseSerializer serializer]];
// }else{
[manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
// }
[[YH_HttpDNS shareInstance] getHostByNameAsync:url reqSerializer:manager.requestSerializer dnsCallback:^(AFHTTPRequestSerializer<AFURLRequestSerialization> *requestSerializer, NSString *url) {
[manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (IsNilOrNull(operation.responseData)) {
failure(operation, [NSError errorWithDomain:@"" code:-1 userInfo:@{}]);
return;
}
BLOCK_EXEC(success, operation, operation.responseData);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[YH_HttpEngine handleHTTPError:operation error:error];
BLOCK_EXEC(failure, operation, error);
}];
}];
}
//- (void)getPaymentData:(NSDictionary *)parameters
// success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
// failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
//{
// //对数据进行鉴权 kIphonePrivateKey YHApiPrivateKey_Pay
// NSMutableDictionary *dic = [self encodePaymentParams:parameters withPrivateKey:YHApiPrivateKey_Pay];
//
// //获取当前的url
// NSString *url = self.httpURLString;
// url = [self checkHttpsPrefix:url];
//
// AFHTTPRequestOperationManager *manager = [YH_HTTPRequestOperationManager manager];
// AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer = [YH_HttpRequestSerializer serializer];
// [manager setRequestSerializer:requestSerializer];
//
//// if ([YH_Global sharedInstance].securityBodyVeify) {
//// [manager setResponseSerializer:[YH_JSONResponseSerializer serializer]];
//// }
//
// [[YH_HttpDNS shareInstance] getHostByNameAsync:url reqSerializer:manager.requestSerializer dnsCallback:^(AFHTTPRequestSerializer<AFURLRequestSerialization> *requestSerializer, NSString *url) {
// [manager GET:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
// if ([YH_HttpEngine handleRequestError:operation response:responseObject failBlock:failure]) {
// return;
// }
// BLOCK_EXEC(success, operation, responseObject);
// } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// if (operation.response.statusCode == 401) {
// [[NSNotificationCenter defaultCenter] postNotificationName:YH_LoginMgrNeedShowLoginVCNotifi object:nil];
// }
// [YH_HttpEngine handleHTTPError:operation error:error];
// BLOCK_EXEC(failure, operation, error);
// }];
// }];
//
//}
#pragma mark - encode
- (NSMutableDictionary *)encodeParams:(NSDictionary *)parameters
{
return [self encodeParams:parameters withPrivateKey:kIphonePrivate];
}
- (NSMutableDictionary *)encodeParams:(NSDictionary *)parameters withPrivateKey:(NSString *)key
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameters];
[params setObject:@"4.9.1.1608040001" forKey:kAppVersion];
[params setObject:kServiceType forKey:kV];
[params setObject:@"9.3" forKey:kOsVersion];
[params setObject:@"iphone" forKey:kClientType];
NSString *screenSize = [NSString stringWithFormat:@"%ldx%ld", (long)kScreenWidth,(long)kScreenHeight];
[params setObject:screenSize forKey:kScreenSize];
[params setObject:key forKey:kKeyJSONPrivate];
NSMutableArray *keys = [NSMutableArray array];
for (NSString *key in params.keyEnumerator) {
[keys addObject:key];
}
[keys sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSString *s1 = (NSString *)obj1;
NSString *s2 = (NSString *)obj2;
return [s1 compare:s2];
}];
NSMutableArray *strings = [NSMutableArray array];
for (NSString *key in keys) {
id value = [params objectForKey:key];
if ([value isKindOfClass:[NSString class]]) {
value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
value = [value stringByReplacingOccurrencesOfString:@"\n" withString:@""];
value = [value stringByReplacingOccurrencesOfString:@"\t" withString:@""];
value = [value stringByReplacingOccurrencesOfString:@"\r" withString:@""];
}
[params setObject:value forKey:key];
[strings addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
}
NSString *source = [strings componentsJoinedByString:@"&"];
NSString *secret = [[source yh_md5String] lowercaseString];
[params removeObjectForKey:kKeyJSONPrivate];
[params setObject:secret forKey:kClientSecret];
return params;
}
- (NSMutableDictionary *)encodePaymentParams:(NSDictionary *)parameters withPrivateKey:(NSString *)privateKey
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameters];
[params setObject:IsNilOrNull(privateKey)?@"":privateKey forKey:kKeyJSONPrivate];
NSMutableArray *keys = [NSMutableArray array];
for (NSString *key in params.keyEnumerator) {
[keys addObject:key];
}
[keys sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSString *s1 = (NSString *)obj1;
NSString *s2 = (NSString *)obj2;
return [s1 compare:s2];
}];
NSMutableArray *strings = [NSMutableArray array];
for (NSString *key in keys) {
NSString *value = [params objectForKey:key];
if ([value isKindOfClass:[NSString class]]) {
value = [value stringByReplacingOccurrencesOfString:@" " withString:@""];
value = [value stringByReplacingOccurrencesOfString:@"\n" withString:@""];
value = [value stringByReplacingOccurrencesOfString:@"\t" withString:@""];
value = [value stringByReplacingOccurrencesOfString:@"\r" withString:@""];
}
[strings addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
}
NSString *source = [strings componentsJoinedByString:@"&"];
NSString *secret = [[source yh_md5String] lowercaseString];
[params removeObjectForKey:kKeyJSONPrivate];
[params setObject:secret forKey:kKeyJSONClient];
return params;
}
- (BOOL)APIFilter:(NSString *)apiString
{
return NO;
// BOOL isDemote = NO;
// if (!IsStrEmpty(apiString)) {
// NSDictionary *dic = [YH_Global sharedInstance].blackAPIDic;
// if (IsDictionaryClass(dic)) {
// NSString *apiID = [dic yh_stringForKey:apiString];
// BOOL demoteFlag = [YH_Global sharedInstance].demoteAPIFlag;
// NSDictionary *demoteDic = [YH_Global sharedInstance].demoteAPIDic;
// NSString *value = [demoteDic yh_stringForKey:apiID];
// if ([value isEqualToString:@"Y"] && demoteFlag) {
// isDemote = YES;
// }
// LogInfo(@"%@===%@ 是否降级: %zd",apiString, apiID, isDemote);
// }
// }
// return isDemote;
}
@end