省钱达人

DRCollectionGoodsController.m 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // DRCollectionGoodsController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRCollectionGoodsController.h"
  9. #import "DRDateHeaderView.h"
  10. #import "DRCollectionTicketCell.h"
  11. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  12. #import <AlibabaAuthSDK/ALBBSession.h>
  13. #import <AlibabaAuthSDK/ALBBSDK.h>
  14. #import "DRTaobaoAuthorView.h"
  15. @interface DRCollectionGoodsController ()<UIWebViewDelegate>
  16. @property (nonatomic, strong) UIWebView *webView;
  17. @property (nonatomic, strong) DRTaobaoAuthorView *authorView;
  18. @end
  19. @implementation DRCollectionGoodsController
  20. - (void)viewWillAppear:(BOOL)animated {
  21. [super viewWillAppear:animated];
  22. [self configTaobaoAuthorView];
  23. [self.view bringSubviewToFront:self.webView];
  24. }
  25. - (void)viewWillDisappear:(BOOL)animated {
  26. [super viewWillDisappear:animated];
  27. [SVProgressHUD dismiss];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. [self configWebView];
  32. }
  33. - (void)initHUD {
  34. [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
  35. [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
  36. [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
  37. }
  38. - (void)configWebView {
  39. self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  40. self.webView.delegate = self;
  41. [self.view addSubview:self.webView];
  42. self.authorView = [[DRTaobaoAuthorView alloc] initWithFrame:self.webView.frame text:@"授权淘宝登录,一键查看淘宝内商品" clickBlock:^{
  43. //淘宝授权
  44. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  45. [albbSDK setAppkey:ALBC_APP_KEY];
  46. [albbSDK setAuthOption:NormalAuth];
  47. [albbSDK auth:self successCallback:^(ALBBSession *session){
  48. [self configTaobaoAuthorView];
  49. } failureCallback:^(ALBBSession *session,NSError *error){
  50. }];
  51. }];
  52. [self.view addSubview:self.authorView];
  53. }
  54. - (void)configTaobaoAuthorView {
  55. if ([[ALBBSession sharedInstance] isLogin]){
  56. [self openMyCollectionGoodsWebView];
  57. self.webView.hidden = NO;
  58. self.authorView.hidden = YES;
  59. }else {
  60. self.webView.hidden = YES;
  61. self.authorView.hidden = NO;
  62. }
  63. }
  64. - (void)openMyCollectionGoodsWebView {
  65. [SVProgressHUD show];
  66. id<AlibcTradePage> page = [AlibcTradePageFactory page:@"http://tbk.726p.com/api/users/token"];
  67. //淘客信息
  68. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  69. taoKeParams.pid= ALTK_PID;
  70. //打开方式
  71. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  72. showParam.openType = AlibcOpenTypeAuto;
  73. [[AlibcTradeSDK sharedInstance].tradeService show:self.parentViewController webView:self.webView page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  74. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  75. }];
  76. self.webView.delegate = self;
  77. }
  78. - (void)webViewDidStartLoad:(UIWebView *)webView {
  79. [SVProgressHUD dismiss];
  80. }
  81. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  82. static NSString * const hiddenDiv =
  83. @"function hiddenDiv(){\
  84. var className = document.getElementsByClassName('icon-back');\
  85. className[0].style.display = 'none';\
  86. };";
  87. [self.webView stringByEvaluatingJavaScriptFromString:hiddenDiv];
  88. [self.webView stringByEvaluatingJavaScriptFromString:@"hiddenDiv()"];
  89. }
  90. - (void)didReceiveMemoryWarning {
  91. [super didReceiveMemoryWarning];
  92. // Dispose of any resources that can be recreated.
  93. }
  94. /*
  95. #pragma mark - Navigation
  96. // In a storyboard-based application, you will often want to do a little preparation before navigation
  97. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  98. // Get the new view controller using [segue destinationViewController].
  99. // Pass the selected object to the new view controller.
  100. }
  101. */
  102. @end