省钱达人

DRWebPageViewController.m 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // DRWebPageViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/31.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRWebPageViewController.h"
  9. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  10. #import <AlibabaAuthSDK/ALBBSession.h>
  11. #import <AlibabaAuthSDK/ALBBSDK.h>
  12. #import "DRTaobaoAuthorView.h"
  13. @interface DRWebPageViewController ()<UIWebViewDelegate>
  14. @property (nonatomic, strong) UIButton *backButton;
  15. @property (nonatomic, strong) UIButton *closeButton;
  16. @property (nonatomic, strong) DRTaobaoAuthorView *authorView;
  17. @end
  18. @implementation DRWebPageViewController
  19. - (instancetype)init {
  20. self = [super init];
  21. if (self) {
  22. [self configWebView];
  23. }
  24. return self;
  25. }
  26. - (void)viewWillDisappear:(BOOL)animated {
  27. [super viewWillDisappear:animated];
  28. [SVProgressHUD dismiss];
  29. }
  30. - (void)viewWillAppear:(BOOL)animated {
  31. [super viewWillAppear:animated];
  32. [self configTaobaoAuthorView];
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. [self initHUD];
  37. [self configNavigationBar];
  38. }
  39. - (void)configTaobaoAuthorView {
  40. if ([[ALBBSession sharedInstance] isLogin]){
  41. [self openAliMyOrderWebView];
  42. self.webView.hidden = NO;
  43. self.authorView.hidden = YES;
  44. }else {
  45. self.webView.hidden = YES;
  46. self.authorView.hidden = NO;
  47. }
  48. }
  49. - (void)initHUD {
  50. [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
  51. [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
  52. [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
  53. }
  54. - (void)configWebView {
  55. self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  56. self.webView.delegate = self;
  57. [self.view addSubview:self.webView];
  58. self.authorView = [[DRTaobaoAuthorView alloc] initWithFrame:self.webView.frame text:@"授权淘宝登录,一键查看淘宝内商品" clickBlock:^{
  59. //淘宝授权
  60. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  61. [albbSDK setAppkey:ALBC_APP_KEY];
  62. [albbSDK setAuthOption:NormalAuth];
  63. [albbSDK auth:self successCallback:^(ALBBSession *session){
  64. [self configTaobaoAuthorView];
  65. } failureCallback:^(ALBBSession *session,NSError *error){
  66. }];
  67. }];
  68. [self.view addSubview:self.authorView];
  69. }
  70. - (void)configNavigationBar {
  71. self.view.backgroundColor = [UIColor whiteColor];
  72. self.navigationBar.showNavigationBarBottomLine = YES;
  73. [self.navigationBar setCustomLeftButtons:@[self.backButton]];
  74. }
  75. - (void)backAction {
  76. if (self.webView.canGoBack) {
  77. [self.webView goBack];
  78. }else{
  79. [self.navigationController popViewControllerAnimated:YES];
  80. }
  81. }
  82. - (void)closeAction {
  83. [self.navigationController popViewControllerAnimated:YES];
  84. }
  85. - (void)updateNavigationBarButtons {
  86. if (self.webView.canGoBack) {
  87. [self.navigationBar setCustomLeftButtons:@[self.backButton,self.closeButton]];
  88. }else {
  89. [self.navigationBar setCustomLeftButtons:@[self.backButton]];
  90. }
  91. }
  92. - (void)openAliMyOrderWebView {
  93. [SVProgressHUD show];
  94. switch (self.openPage) {
  95. case AlibcOpenPageShopCar:
  96. {
  97. id<AlibcTradePage> page = [AlibcTradePageFactory myCartsPage];
  98. [self openWebViewByPage:page];
  99. }
  100. break;
  101. case AlibcOpenPageMyOrder:
  102. {
  103. id<AlibcTradePage> page = [AlibcTradePageFactory myOrdersPage:0 isAllOrder:YES];
  104. [self openWebViewByPage:page];
  105. }
  106. break;
  107. default:
  108. {
  109. id<AlibcTradePage> page = [AlibcTradePageFactory myOrdersPage:0 isAllOrder:YES];
  110. [self openWebViewByPage:page];
  111. }
  112. break;
  113. }
  114. }
  115. - (void)openWebViewByPage:(id<AlibcTradePage>)page {
  116. //淘客信息
  117. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  118. taoKeParams.pid = ALTK_PID;
  119. //打开方式
  120. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  121. showParam.openType = AlibcOpenTypeH5;
  122. [[AlibcTradeSDK sharedInstance].tradeService show:self webView:self.webView page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  123. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  124. }];
  125. self.webView.delegate = self;
  126. }
  127. #pragma mark -------------- UIWebView delegate --------
  128. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  129. [self updateNavigationBarButtons];
  130. [SVProgressHUD dismiss];
  131. // NSString *jsToGetHTMLSource = @"document.getElementsByTagName('html')[0].innerHTML";
  132. //
  133. // NSString *HTMLSource = [self.webView stringByEvaluatingJavaScriptFromString:jsToGetHTMLSource];
  134. //
  135. // NSLog(@"------------:%@",HTMLSource);
  136. }
  137. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  138. [SVProgressHUD dismiss];
  139. }
  140. #pragma mark ------
  141. - (UIButton *)backButton {
  142. if (!_backButton) {
  143. _backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  144. [_backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  145. [_backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  146. }
  147. return _backButton;
  148. }
  149. - (UIButton *)closeButton {
  150. if (!_closeButton) {
  151. _closeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  152. [_closeButton setImage:[UIImage imageNamed:@"close_web"] forState:UIControlStateNormal];
  153. [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  154. }
  155. return _closeButton;
  156. }
  157. - (void)didReceiveMemoryWarning {
  158. [super didReceiveMemoryWarning];
  159. // Dispose of any resources that can be recreated.
  160. }
  161. /*
  162. #pragma mark - Navigation
  163. // In a storyboard-based application, you will often want to do a little preparation before navigation
  164. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  165. // Get the new view controller using [segue destinationViewController].
  166. // Pass the selected object to the new view controller.
  167. }
  168. */
  169. @end