BGMainWebViewController.m 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. //
  2. // BGMainWebViewController.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 2017/6/3.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGMainWebViewController.h"
  9. #import "PublishLivestViewController.h"
  10. #import "AccountRechargeVC.h"
  11. #import "CarAnimationPlayer.h"
  12. #import "BogoSharePopView.h"
  13. @interface BGMainWebViewController ()
  14. {
  15. CGSize _imgSize; // 裁剪图片时的图片大小
  16. CarAnimationPlayer *play;
  17. }
  18. @end
  19. @implementation BGMainWebViewController
  20. - (void)viewWillAppear:(BOOL)animated {
  21. [super viewWillAppear:animated];
  22. self.navigationController.navigationBar.hidden = NO;
  23. }
  24. - (void)initFWUI
  25. {
  26. // 先加载当前的方法,再调用父类方法,这两个不能反了
  27. [self addUserContentC];
  28. [super initFWUI];
  29. #if kSupportH5Shopping
  30. // 加载礼物列表
  31. [[GiftListManager sharedInstance] reloadGiftList];
  32. // 互踢退出
  33. FWWeakify(self)
  34. [self xw_addNotificationForName:@"H5qiut" block:^(NSNotification * _Nonnull notification) {
  35. FWStrongify(self)
  36. [self.webView evaluateJavaScript:@"js_web_shop_logout()" completionHandler:nil];
  37. }];
  38. #endif
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wxloginback:) name:kWXLoginBack object:nil];
  40. }
  41. - (void)addUserContentC
  42. {
  43. self.userContentC = [[WKUserContentController alloc] init];
  44. [self.userContentC addScriptMessageHandler:self name:@"getClipBoardText"];
  45. [self.userContentC addScriptMessageHandler:self name:@"sdk_share"];
  46. [self.userContentC addScriptMessageHandler:self name:@"CutPhoto"];
  47. [self.userContentC addScriptMessageHandler:self name:@"open_type"];
  48. [self.userContentC addScriptMessageHandler:self name:@"pay_sdk"];
  49. [self.userContentC addScriptMessageHandler:self name:@"login_success"];
  50. [self.userContentC addScriptMessageHandler:self name:@"logout"];
  51. [self.userContentC addScriptMessageHandler:self name:@"apns"];
  52. [self.userContentC addScriptMessageHandler:self name:@"position"];
  53. [self.userContentC addScriptMessageHandler:self name:@"position2"];
  54. [self.userContentC addScriptMessageHandler:self name:@"qr_code_scan"];
  55. [self.userContentC addScriptMessageHandler:self name:@"restart"];
  56. [self.userContentC addScriptMessageHandler:self name:@"login_sdk"];
  57. [self.userContentC addScriptMessageHandler:self name:@"is_exist_installed"];
  58. [self.userContentC addScriptMessageHandler:self name:@"create_live"];
  59. [self.userContentC addScriptMessageHandler:self name:@"join_live"];
  60. [self.userContentC addScriptMessageHandler:self name:@"updateCookies"];
  61. [self.userContentC addScriptMessageHandler:self name:@"start_app_page"];
  62. [self.userContentC addScriptMessageHandler:self name:@"page_finsh"];
  63. [self.userContentC addScriptMessageHandler:self name:@"close_page"];
  64. [self.userContentC addScriptMessageHandler:self name:@"getuserinfo"];
  65. [self.userContentC addScriptMessageHandler:self name:@"js_getuserinfo"];
  66. [self.userContentC addScriptMessageHandler:self name:@"shopping_join_live"];
  67. [self.userContentC addScriptMessageHandler:self name:@"js_shopping_join_live"];
  68. [self.userContentC addScriptMessageHandler:self name:@"shopping_start_live_app"];
  69. [self.userContentC addScriptMessageHandler:self name:@"js_shopping_start_live_app"];
  70. [self.userContentC addScriptMessageHandler:self name:@"shopping_create_live"];
  71. [self.userContentC addScriptMessageHandler:self name:@"js_shopping_comeback_live_app"];
  72. [self.userContentC addScriptMessageHandler:self name:@"js_get_live_type"];
  73. }
  74. - (void)removeScriptMessageHandler
  75. {
  76. [super removeScriptMessageHandler];
  77. [self.userContentC removeAllUserScripts];
  78. [self.userContentC removeScriptMessageHandlerForName:@"getClipBoardText"];
  79. [self.userContentC removeScriptMessageHandlerForName:@"sdk_share"];
  80. [self.userContentC removeScriptMessageHandlerForName:@"CutPhoto"];
  81. [self.userContentC removeScriptMessageHandlerForName:@"open_type"];
  82. [self.userContentC removeScriptMessageHandlerForName:@"pay_sdk"];
  83. [self.userContentC removeScriptMessageHandlerForName:@"login_success"];
  84. [self.userContentC removeScriptMessageHandlerForName:@"logout"];
  85. [self.userContentC removeScriptMessageHandlerForName:@"apns"];
  86. [self.userContentC removeScriptMessageHandlerForName:@"position"];
  87. [self.userContentC removeScriptMessageHandlerForName:@"position2"];
  88. [self.userContentC removeScriptMessageHandlerForName:@"qr_code_scan"];
  89. [self.userContentC removeScriptMessageHandlerForName:@"restart"];
  90. [self.userContentC removeScriptMessageHandlerForName:@"login_sdk"];
  91. [self.userContentC removeScriptMessageHandlerForName:@"is_exist_installed"];
  92. [self.userContentC removeScriptMessageHandlerForName:@"create_live"];
  93. [self.userContentC removeScriptMessageHandlerForName:@"join_live"];
  94. [self.userContentC removeScriptMessageHandlerForName:@"updateCookies"];
  95. [self.userContentC removeScriptMessageHandlerForName:@"start_app_page"];
  96. [self.userContentC removeScriptMessageHandlerForName:@"page_finsh"];
  97. [self.userContentC removeScriptMessageHandlerForName:@"close_page"];
  98. [self.userContentC removeScriptMessageHandlerForName:@"getuserinfo"];
  99. [self.userContentC removeScriptMessageHandlerForName:@"js_getuserinfo"];
  100. [self.userContentC removeScriptMessageHandlerForName:@"shopping_join_live"];
  101. [self.userContentC removeScriptMessageHandlerForName:@"js_shopping_join_live"];
  102. [self.userContentC removeScriptMessageHandlerForName:@"shopping_start_live_app"];
  103. [self.userContentC removeScriptMessageHandlerForName:@"js_shopping_start_live_app"];
  104. [self.userContentC removeScriptMessageHandlerForName:@"shopping_create_live"];
  105. [self.userContentC removeScriptMessageHandlerForName:@"js_shopping_comeback_live_app"];
  106. [self.userContentC removeScriptMessageHandlerForName:@"js_get_live_type"];
  107. }
  108. #pragma mark- JavaScript调用
  109. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
  110. {
  111. NSLog(ASLocalizedString(@"=========js调起的方法:%@"),message.name);
  112. if ([message.name isEqualToString:@"CutPhoto"])
  113. {
  114. // 裁剪图片
  115. [self cutPhoto:[BGUtils jsonStrToDict:message.body]];
  116. }
  117. else if([message.name isEqualToString:@"sdk_share"])
  118. {
  119. // 分享
  120. [self sdkShare:[BGUtils jsonStrToDict:message.body]];
  121. }
  122. else if([message.name isEqualToString:@"getClipBoardText"])
  123. {
  124. // 从剪切板获取信息
  125. [self copyString];
  126. }
  127. else if([message.name isEqualToString:@"open_type"])
  128. {
  129. // 打开心的webview
  130. [self openNewWebView:[BGUtils jsonStrToDict:message.body]];
  131. }
  132. else if([message.name isEqualToString:@"pay_sdk"])
  133. {
  134. // SDK支付
  135. [self sdkPay:[BGUtils jsonStrToDict:message.body]];
  136. }
  137. else if([message.name isEqualToString:@"login_success"])
  138. {
  139. // 登录成功
  140. [self loginSuccess:[BGUtils jsonStrToDict:message.body]];
  141. }
  142. else if([message.name isEqualToString:@"logout"])
  143. {
  144. // 退出登录
  145. [self loginLogout:[BGUtils jsonStrToDict:message.body]];
  146. }
  147. else if([message.name isEqualToString:@"apns"])
  148. {
  149. // 上传友盟推送设备号
  150. [self umengApns:[BGUtils jsonStrToDict:message.body]];
  151. }
  152. else if([message.name isEqualToString:@"position"])
  153. {
  154. // 上传地理信息1
  155. [self uploadPosition1:[BGUtils jsonStrToDict:message.body]];
  156. }
  157. else if([message.name isEqualToString:@"position2"])
  158. {
  159. // 上传地理信息2
  160. [self uploadPosition2:[BGUtils jsonStrToDict:message.body]];
  161. }
  162. else if([message.name isEqualToString:@"qr_code_scan"])
  163. {
  164. // 扫码
  165. [self qrCodeScan:[BGUtils jsonStrToDict:message.body]];
  166. }
  167. else if([message.name isEqualToString:@"restart"])
  168. {
  169. // 重新加载webview
  170. [self reLoadCurrentWKWebView];
  171. }
  172. else if([message.name isEqualToString:@"login_sdk"])
  173. {
  174. // SDK登录
  175. [self loginWithType:[NSString stringWithFormat:@"%@",message.body]];
  176. }
  177. else if([message.name isEqualToString:@"is_exist_installed"])
  178. {
  179. // 判断是否安装了某个应用
  180. [self isExistInstalledWithScheme:[NSString stringWithFormat:@"%@",message.body]];
  181. }
  182. else if ([message.name isEqualToString:@"updateCookies"])
  183. {
  184. // 更新Cookies
  185. [self updateCookies:message.body];
  186. }
  187. else if ([message.name isEqualToString:@"create_live"])
  188. {
  189. // 开始直播
  190. [self startLiving:[BGUtils jsonStrToDict:message.body]];
  191. }
  192. else if([message.name isEqualToString:@"join_live"])
  193. {
  194. // 加入直播
  195. [self joinLiving:[BGUtils jsonStrToDict:message.body]];
  196. }
  197. else if ([message.name isEqualToString:@"start_app_page"])
  198. {
  199. // 跳转指定的页面
  200. [self goToNextController:[BGUtils jsonStrToDict:message.body]];
  201. }
  202. else if ([message.name isEqualToString:@"page_finsh"] || [message.name isEqualToString:@"close_page"])
  203. {
  204. // 回退
  205. [self.navigationController popViewControllerAnimated:YES];
  206. }
  207. else if ([message.name isEqualToString:@"getuserinfo"])
  208. {
  209. // 获取用户信息并通过js上传
  210. [self getuserinfo:[BGUtils jsonStrToDict:message.body]];
  211. }
  212. else if ([message.name isEqualToString:@"shopping_join_live"])
  213. {
  214. // 呼出直播小屏,请求成功后直接进入直播界面
  215. [self joinLiveController:[BGUtils jsonStrToDict:message.body]];
  216. }
  217. else if ([message.name isEqualToString:@"js_shopping_join_live"])
  218. {
  219. // 观众加入直播间回调
  220. [self getuserinfoWithStaute:[BGUtils jsonStrToDict:message.body]];
  221. }
  222. else if ([message.name isEqualToString:@"shopping_start_live_app"])
  223. {
  224. // 呼出直播应用,请求成功后进入app的主页
  225. [self enterMianAppView:[BGUtils jsonStrToDict:message.body]];
  226. }
  227. else if ([message.name isEqualToString:@"js_shopping_start_live_app"])
  228. {
  229. // 启动应用回调
  230. [self getuserinfoWithStaute:[BGUtils jsonStrToDict:message.body]];
  231. }
  232. else if ([message.name isEqualToString:@"shopping_create_live"])
  233. {
  234. // 呼出发起直播,请求接口成功后进入发起直播的界面
  235. [self startLiving:[BGUtils jsonStrToDict:message.body]];
  236. }
  237. else if ([message.name isEqualToString:@"js_shopping_comeback_live_app"])
  238. {
  239. // h5退回直播间
  240. [self comeBackLive:[BGUtils jsonStrToDict:message.body]];
  241. }
  242. else if ([message.name isEqualToString:@"js_get_live_type"])
  243. {
  244. // live_state h5过来获取oc直播状态
  245. [self getLiveType:[BGUtils jsonStrToDict:message.body]];
  246. }
  247. }
  248. #pragma mark - ----------------------- 裁剪图片 -----------------------
  249. - (void)cutPhoto:(NSDictionary *)dict
  250. {
  251. ShareModel *model = [ShareModel mj_objectWithKeyValues:dict];
  252. [self showControllerWithModel:model];
  253. }
  254. - (void)showControllerWithModel:(ShareModel *)model
  255. {
  256. UIActionSheet *sheet = [UIActionSheet bk_actionSheetWithTitle:nil];
  257. [sheet addButtonWithTitle:ASLocalizedString(@"取消")];
  258. [sheet addButtonWithTitle:ASLocalizedString(@"相机")];
  259. [sheet addButtonWithTitle:ASLocalizedString(@"相册")];
  260. [sheet showInView:self.view];
  261. FWWeakify(self)
  262. [sheet bk_setDidDismissBlock:^(UIActionSheet *actionSheet, NSInteger buttonIndex){
  263. FWStrongify(self)
  264. if (buttonIndex == 1)
  265. {
  266. [self openCamera];
  267. }
  268. else if(buttonIndex == 2)
  269. {
  270. [self openAlbum];
  271. }
  272. }];
  273. CGSize size;
  274. if ([model.w intValue]>300)
  275. {
  276. size = CGSizeMake([model.w intValue]*0.6, [model.h intValue]*0.6);
  277. }
  278. else if([model.w intValue]>170)
  279. {
  280. size = CGSizeMake([model.w intValue], [model.h intValue]);
  281. }
  282. else if([model.w intValue]>110)
  283. {
  284. size = CGSizeMake([model.w intValue]*1.5, [model.h intValue]*1.5);
  285. }
  286. else
  287. {
  288. size = CGSizeMake([model.w intValue]*2, [model.h intValue]*2);
  289. }
  290. _imgSize = size;
  291. }
  292. #pragma mark 调用相机
  293. - (void)openCamera
  294. {
  295. if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
  296. {
  297. return;
  298. }
  299. UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
  300. imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  301. imagePicker.delegate = self;
  302. [self presentViewController:imagePicker animated:YES completion:nil];
  303. }
  304. #pragma mark 打开图片
  305. - (void)openAlbum
  306. {
  307. if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
  308. {
  309. return;
  310. }
  311. UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
  312. imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  313. imagePicker.delegate = self;
  314. [self presentViewController:imagePicker animated:YES completion:nil];
  315. }
  316. #pragma mark UIImagePickerControllerDelegate
  317. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
  318. {
  319. [picker dismissViewControllerAnimated:YES completion:nil];
  320. // 通过UIImagePickerControllerOriginalImage获取图片
  321. // UIImage *image = info[@"UIImagePickerControllerOriginalImage"];
  322. // cutPictureView *cutPicture = [cutPictureView cutPicture];
  323. // cutPicture.control = self;
  324. // cutPicture.size = _imgSize;
  325. // cutPicture.image = image;
  326. // cutPicture.delegate = self;
  327. // [self.view addSubview:cutPicture];
  328. }
  329. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  330. {
  331. [picker dismissViewControllerAnimated:YES completion:nil];
  332. }
  333. #pragma mark 裁剪图片回调js
  334. - (void)imageDidCut:(UIImage *)image
  335. {
  336. NSData *data=UIImageJPEGRepresentation(image, 1.0);
  337. NSString *base64Data=[data base64EncodedStringWithOptions:0];
  338. NSLog(@"%@",base64Data);
  339. NSString *jsStr=[NSString stringWithFormat:@"CutCallBack(\"data:image/jpg;base64,%@\")",base64Data];
  340. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  341. }
  342. #pragma mark - ----------------------- 分享 -----------------------
  343. - (void)sdkShare:(NSDictionary *)dict
  344. {
  345. ShareModel *model = [ShareModel mj_objectWithKeyValues:dict];
  346. [self shareWithModel:model];
  347. }
  348. - (void)shareWithModel:(ShareModel *)model
  349. {
  350. NSString *share_content;
  351. if (![model.share_content isEqualToString:@""])
  352. {
  353. share_content = model.share_content;
  354. }
  355. else
  356. {
  357. share_content = model.share_title;
  358. }
  359. FWWeakify(self)
  360. [[BGUMengShareManager sharedInstance] showShareViewInControllr:self shareModel:model succ:^(UMSocialShareResponse *response) {
  361. FWStrongify(self)
  362. NSString *jsStr=[NSString stringWithFormat:@"share_compleate(\"%d\")",[model.share_key intValue]];
  363. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  364. } failed:^(int errId, NSString *errMsg) {
  365. }];
  366. }
  367. #pragma mark - ----------------------- 获取剪切板回调js -----------------------
  368. - (void)copyString
  369. {
  370. UIPasteboard *pastedBoard=[UIPasteboard generalPasteboard];
  371. NSString *jsStr=[NSString stringWithFormat:@"get_clip_board(\"%@\")",pastedBoard.string];
  372. [self.webView evaluateJavaScript:jsStr completionHandler:^(NSString *result, NSError *error)
  373. {
  374. NSLog(@"Error %@",error);
  375. NSLog(@"Result %@",result);
  376. }];
  377. }
  378. #pragma mark - ----------------------- 打开新的webview -----------------------
  379. - (void)openNewWebView:(NSDictionary *)dict
  380. {
  381. if ([[dict toString:@"open_url_type"] isEqualToString:@"1"] )
  382. {
  383. NSURL *url=[NSURL URLWithString:dict[@"url"]];
  384. [[UIApplication sharedApplication] openURL:url];
  385. }
  386. else
  387. {
  388. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:dict[@"url"] isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:YES];
  389. [self.navigationController pushViewController:tmpController animated:YES];
  390. }
  391. }
  392. #pragma mark - ----------------------- sdk支付 -----------------------
  393. - (void)sdkPay:(NSDictionary *)dict
  394. {
  395. NSString *pay_sdk_type = [dict toString:@"pay_sdk_type"];
  396. NSDictionary *config = [dict objectForKey:@"config"];
  397. if([pay_sdk_type isEqualToString:@"wxpay"])
  398. { //微信sdk支付
  399. Mwxpay *wwxpay = [Mwxpay mj_objectWithKeyValues:config];
  400. [self payWithWxpay:wwxpay];
  401. }
  402. else
  403. {
  404. [FanweMessage alert:ASLocalizedString(@"当前版本不支持该支付方式")];
  405. }
  406. }
  407. #pragma mark 微信支付
  408. - (void)payWithWxpay:(Mwxpay *)mwxpay
  409. {
  410. // if (mwxpay.appid == nil || [mwxpay.appid isEqualToString:@""])
  411. // {
  412. // [self js_pay_sdk:6];
  413. // [FanweMessage alert:ASLocalizedString(@"appid为空")];
  414. // return;
  415. // }
  416. // else if (mwxpay.partnerid == nil || [mwxpay.partnerid isEqualToString:@""])
  417. // {
  418. // [self js_pay_sdk:6];
  419. // [FanweMessage alert:ASLocalizedString(@"partnerid为空")];
  420. // return;
  421. // }
  422. // else if (mwxpay.prepayid == nil || [mwxpay.prepayid isEqualToString:@""])
  423. // {
  424. // [self js_pay_sdk:6];
  425. // [FanweMessage alert:ASLocalizedString(@"prepayid为空")];
  426. // return;
  427. // }
  428. // else if (mwxpay.noncestr == nil || [mwxpay.noncestr isEqualToString:@""])
  429. // {
  430. // [self js_pay_sdk:6];
  431. // [FanweMessage alert:ASLocalizedString(@"noncestr为空")];
  432. // return;
  433. // }
  434. // else if (mwxpay.timestamp == nil || [mwxpay.timestamp isEqualToString:@""])
  435. // {
  436. // [self js_pay_sdk:6];
  437. // [FanweMessage alert:ASLocalizedString(@"timestamp为空")];
  438. // return;
  439. // }
  440. // else if (mwxpay.package == nil || [mwxpay.package isEqualToString:@""])
  441. // {
  442. // [self js_pay_sdk:6];
  443. // [FanweMessage alert:ASLocalizedString(@"packagevalue为空")];
  444. // return;
  445. // }
  446. // else if (mwxpay.sign == nil || [mwxpay.sign isEqualToString:@""])
  447. // {
  448. // [self js_pay_sdk:6];
  449. // [FanweMessage alert:ASLocalizedString(@"sign为空")];
  450. // return;
  451. // }
  452. //
  453. // PayReq* req = [[PayReq alloc] init];
  454. // req.openID = mwxpay.appid;
  455. // req.partnerId = mwxpay.partnerid;
  456. // req.prepayId = mwxpay.prepayid;
  457. // req.nonceStr = mwxpay.noncestr;
  458. // req.timeStamp = [mwxpay.timestamp intValue];
  459. // req.package = mwxpay.package;
  460. // req.sign = mwxpay.sign;
  461. //
  462. // [WXApi sendReq:req completion:nil];
  463. }
  464. #pragma mark 各个sdk支付方式支付结果后调用js
  465. - (void)js_pay_sdk:(NSInteger)resultStatus
  466. {
  467. NSString *jsStr=[NSString stringWithFormat:@"js_pay_sdk(\"%ld\")",(long)resultStatus];
  468. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  469. }
  470. #pragma mark - ----------------------- 登录成功 -----------------------
  471. - (void)loginSuccess:(NSDictionary *)dic
  472. {
  473. // 判断上一次是否退出
  474. if ([[TIMManager sharedInstance] getLoginUser])
  475. {
  476. }
  477. }
  478. #pragma mark - ----------------------- 退出登录 -----------------------
  479. /**
  480. 1. IM 退出
  481. 2. user——default 数据清空
  482. 3.清空 cookieJar
  483. @param dict NSDictionary
  484. */
  485. - (void)loginLogout:(NSDictionary *)dict
  486. {
  487. // 如果有悬浮要先执行退出悬浮
  488. if ([AppDelegate sharedAppDelegate].sus_window.rootViewController)
  489. {
  490. FWWeakify(self)
  491. [SuspenionWindow exitSuswindowBlock:^(BOOL finished) {
  492. FWStrongify(self)
  493. if(finished)
  494. {
  495. [self goLoginOut:dict];
  496. }
  497. else
  498. {
  499. [FanweMessage alert:ASLocalizedString(@"直播退出异常")];
  500. }
  501. }];
  502. }
  503. else
  504. {
  505. [self goLoginOut:dict];
  506. }
  507. }
  508. #pragma mark 退出登录
  509. - (void)goLoginOut:(NSDictionary *)dict
  510. {
  511. [[IMAPlatform sharedInstance] logout:^{
  512. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"退出成功")];
  513. } fail:^(int code, NSString *msg) {
  514. }];
  515. NSString * preferredLang = [[NSUserDefaults standardUserDefaults] objectForKey:KAppLanguage];
  516. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  517. //因为上面的方法会全部清除本APP的所有本地存储,所以这里预言再设置一遍
  518. [[LocalizationSystem sharedLocalSystem] setLanguage:preferredLang];
  519. NSLog(@" 5当前语言 = %@",preferredLang);
  520. NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  521. NSArray *cookieArray = [NSArray arrayWithArray:[cookieJar cookies]];
  522. for (id obj in cookieArray)
  523. {
  524. [cookieJar deleteCookie:obj];
  525. }
  526. [BGIMLoginManager sharedInstance].isIMSDKOK = NO;
  527. }
  528. #pragma mark - ----------------------- 推送 -----------------------
  529. - (void)umengApns:(NSDictionary *)dict
  530. {
  531. NSString *jsStr=[NSString stringWithFormat:@"js_apns(\"ios\",\"%@\")",self.BuguLive.deviceToken];
  532. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  533. }
  534. #pragma mark - ----------------------- 上传定位信息 -----------------------
  535. - (void)uploadPosition1:(NSDictionary *)dict
  536. {
  537. NSString *jsStr=[NSString stringWithFormat:@"js_position(\"%f\",\"%f\")",self.BuguLive.latitude,self.BuguLive.longitude];
  538. [self.webView evaluateJavaScript:jsStr completionHandler:^(id str, NSError * _Nullable error) {
  539. NSLog(@"%@",str);
  540. NSLog(@"%@",error);
  541. }];
  542. }
  543. - (void)uploadPosition2:(NSDictionary *)dict
  544. {
  545. NSString *jsStr=[NSString stringWithFormat:@"js_position2(\"%f\",\"%f\",\'%@\')",self.BuguLive.latitude,self.BuguLive.longitude,self.BuguLive.addressJsonStr];
  546. [self.webView evaluateJavaScript:jsStr completionHandler:^(id str, NSError * _Nullable error) {
  547. NSLog(@"%@",str);
  548. NSLog(@"%@",error);
  549. }];
  550. }
  551. #pragma mark - ----------------------- 扫码 -----------------------
  552. - (void)qrCodeScan:(NSDictionary *)dict
  553. {
  554. }
  555. - (void)getQRCodeResult:(NSString *)qr_result
  556. {
  557. NSString *jsStr=[NSString stringWithFormat:@"js_qr_code_scan(\"%@\")",qr_result];
  558. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  559. }
  560. #pragma mark - ----------------------- 第三方sdk登录 -----------------------
  561. - (void)loginWithType:(NSString *)login_sdk_type
  562. {
  563. if ([login_sdk_type isEqualToString:@"qqlogin"])
  564. { // QQ sdk登录
  565. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:self completion:^(id result, NSError *error) {
  566. UMSocialUserInfoResponse *resp = result;
  567. if (resp)
  568. {
  569. }
  570. }];
  571. }
  572. // else if([login_sdk_type isEqualToString:@"wxlogin"])
  573. // { // 微信sdk登录
  574. // // 构造SendAuthReq结构体
  575. // SendAuthReq* req =[[SendAuthReq alloc ] init ];
  576. // req.scope = @"snsapi_userinfo" ;
  577. // req.state = @"123" ;
  578. // // 第三方向微信终端发送一个SendAuthReq消息结构
  579. //
  580. // [WXApi sendReq:req completion:nil];
  581. //
  582. // }
  583. }
  584. #pragma mark 微信登录获取code后oc调用js把code等传上去
  585. - (void)wxloginback:(NSNotification *)text
  586. {
  587. NSString *jsStr=[NSString stringWithFormat:@"js_login_sdk('%@')",text.object];
  588. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  589. }
  590. #pragma mark - ----------------------- 判断是否安装了某个应用 -----------------------
  591. - (void)isExistInstalledWithScheme:(NSString *)scheme
  592. {
  593. if (scheme && ![scheme isEqualToString:@""])
  594. {
  595. NSURL *url = [NSURL URLWithString:scheme];
  596. BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:url];
  597. NSString *jsStr;
  598. if (canOpenURL)
  599. {
  600. jsStr =[NSString stringWithFormat:@"js_is_exist_installed(\"%@\",\"%d\")",scheme,1];
  601. }
  602. else
  603. {
  604. jsStr =[NSString stringWithFormat:@"js_is_exist_installed(\"%@\",\"%d\")",scheme,0];
  605. }
  606. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  607. }
  608. else
  609. {
  610. [FanweMessage alert:ASLocalizedString(@"URL Schemes 为空")];
  611. }
  612. }
  613. #pragma mark - ----------------------- 获取PHPSESSID -----------------------
  614. - (void)updateCookies:(NSString *)cookieStr
  615. {
  616. if (cookieStr && ![cookieStr isEqualToString:@""])
  617. {
  618. NSArray *arr = [cookieStr componentsSeparatedByString:@"="];
  619. if (arr)
  620. {
  621. if ([arr count]>1 && [arr[0] isEqualToString:@"PHPSESSID"])
  622. {
  623. NSURL *url = [NSURL URLWithString:self.BuguLive.currentDoMianUrlStr];
  624. // 設定 cookie
  625. NSHTTPCookie *cookie2 = [NSHTTPCookie cookieWithProperties:
  626. [NSDictionary dictionaryWithObjectsAndKeys:
  627. [url host], NSHTTPCookieDomain,
  628. [url path], NSHTTPCookiePath,
  629. arr[0], NSHTTPCookieName,
  630. arr[1], NSHTTPCookieValue,
  631. nil]];
  632. [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie2];
  633. }
  634. }
  635. }
  636. }
  637. #pragma mark - ----------------------- 获取用户信息并通过js上传 -----------------------
  638. - (void)getuserinfo:(NSDictionary *)dict
  639. {
  640. NSString *jsonStr = [NSString stringWithFormat:@"{\"user_id\":\"%@\",\"nick_name\":\"%@\",\"head_image\":\"%@\"}",[[[IMAPlatform sharedInstance] host] imUserId],[[[IMAPlatform sharedInstance] host] imUserName],[[[IMAPlatform sharedInstance] host] imUserIconUrl]];
  641. NSString *jsStr = [NSString stringWithFormat:@"js_getuserinfo(\'%@\')",jsonStr];
  642. [self.webView evaluateJavaScript:jsStr completionHandler:^(id str, NSError * _Nullable error) {
  643. NSLog(@"%@",str);
  644. NSLog(@"%@",error);
  645. }];
  646. }
  647. #pragma mark - ----------------------- 跳转主播,等级,收益,账户的界面 -----------------------
  648. - (void)goToNextController:(NSDictionary *)dict
  649. {
  650. NSString *string = [dict toString:@"ios_page"];
  651. if ([string isEqualToString:@"detailViewController"])
  652. {
  653. AuctionItemdetailsViewController *AutionVc = [[AuctionItemdetailsViewController alloc]init];
  654. AutionVc.productId=[[dict objectForKey:@"data"]toString:@"id"];
  655. AutionVc.type = [[dict objectForKey:@"data"]toInt:@"is_anchor"]? 1:0;
  656. AutionVc.isFromWebView=YES;
  657. [self.navigationController pushViewController:AutionVc animated:YES];
  658. }
  659. else if ([string isEqualToString:@"chargerViewController"])
  660. {
  661. AccountRechargeVC * rechargeVC = [[AccountRechargeVC alloc] init];
  662. [[AppDelegate sharedAppDelegate] pushViewController:rechargeVC animated:YES];
  663. }
  664. }
  665. #pragma mark - ----------------------- 直播相关 -----------------------
  666. #pragma mark 保存session_id
  667. - (void)saveString:(NSString *)string withName:(NSString *)nameString
  668. {
  669. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  670. NSString *documentsDirectory = [paths objectAtIndex:0];
  671. NSArray *array = [NSArray arrayWithObject:string];
  672. NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:nameString];
  673. [array writeToFile:fullPathToFile atomically:NO];
  674. }
  675. #pragma mark 创建直播间(呼出发起直播)
  676. - (void)startLiving:(NSDictionary *)dict
  677. {
  678. if ([AppDelegate sharedAppDelegate].sus_window.rootViewController)
  679. {
  680. // 如果有悬浮要先执行退出悬浮
  681. __weak __typeof(self)weak_Self = self;
  682. [SuspenionWindow exitSuswindowBlock:^(BOOL finished) {
  683. if (finished)
  684. {
  685. [weak_Self goLive:dict];
  686. }
  687. }];
  688. }
  689. else
  690. {
  691. [self goLive:dict];
  692. }
  693. }
  694. - (void)goLive:(NSDictionary *)dict
  695. {
  696. if (dict)
  697. {
  698. [self saveString:[dict toString:@"session_id"] withName:@"session_id"];
  699. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  700. [mDict setObject:@"shop" forKey:@"ctl"];
  701. [mDict setObject:@"openvideo" forKey:@"act"];
  702. [mDict setObject:[dict toString:@"session_id"] forKey:@"session_id"];
  703. FWWeakify(self)
  704. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson)
  705. {
  706. FWStrongify(self)
  707. if ([responseJson toInt:@"status"] == 1)//请求成功跳转到pushViewController
  708. {
  709. if ([BGIMLoginManager sharedInstance].isIMSDKOK)
  710. {
  711. if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
  712. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
  713. return;
  714. }
  715. PublishLivestViewController *pushVC = [[PublishLivestViewController alloc]init];
  716. [self.navigationController presentViewController:pushVC animated:YES completion:nil];
  717. self.BuguLive.isHaveDelete = NO;
  718. }
  719. else
  720. {
  721. [BGIMLoginManager sharedInstance].loginParam.identifier = [[responseJson objectForKey:@"user"] toString:@"user_id"];
  722. [[BGIMLoginManager sharedInstance] getUserSig:^{
  723. [self jumpWithType:CurrentJumpPublishLive enterLivingDict:responseJson];
  724. [self hideMyHud];
  725. } failed:^(int errId, NSString *errMsg) {
  726. [self hideMyHud];
  727. }];
  728. }
  729. }
  730. } FailureBlock:^(NSError *error) {
  731. }];
  732. }
  733. }
  734. - (void)jumpWithType:(CurrentJump)type enterLivingDict:(NSDictionary *)enterLivingDict
  735. {
  736. if (type == CurrentJumpLiveRoom)
  737. {
  738. [self enterAppLiveWithDict:enterLivingDict];
  739. }
  740. else if (type == CurrentJumpMainUI)
  741. {
  742. self.BuguLive.isHaveDelete = YES;
  743. [[AppDelegate sharedAppDelegate] entertabBar];
  744. }
  745. else if (type == CurrentJumpPublishLive)
  746. {
  747. if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
  748. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
  749. return;
  750. }
  751. PublishLivestViewController *pushVC = [[PublishLivestViewController alloc]init];
  752. self.BuguLive.isHaveDelete = NO;
  753. [self.navigationController presentViewController:pushVC animated:YES completion:nil];
  754. }
  755. }
  756. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  757. // 获取完整url并进行UTF-8转码
  758. NSString *strRequest = [navigationAction.request.URL.absoluteString stringByRemovingPercentEncoding];
  759. if ([strRequest hasPrefix:@"live://"]) {
  760. // 拦截点击链接
  761. [self handleCustomAction:strRequest];
  762. // 不允许跳转
  763. decisionHandler(WKNavigationActionPolicyCancel);
  764. }
  765. else if ([strRequest hasPrefix:@"bogogame://"])
  766. {
  767. [self handleCustomAction:strRequest];
  768. // 不允许跳转
  769. decisionHandler(WKNavigationActionPolicyCancel);
  770. }
  771. else {
  772. // 允许跳转
  773. decisionHandler(WKNavigationActionPolicyAllow);
  774. }
  775. }
  776. /**
  777. url参数转字典
  778. @param urlStr 输入的url
  779. @return 转换好的字典
  780. */
  781. -(NSDictionary *)dictionaryWithUrlString:(NSString *)urlStr
  782. {
  783. NSMutableDictionary *parm = [[NSMutableDictionary alloc]init];
  784. //传入url创建url组件类
  785. NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:urlStr];
  786. //回调遍历所有参数,添加入字典
  787. [urlComponents.queryItems enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  788. [parm setObject:obj.value forKey:obj.name];
  789. }];
  790. return parm;
  791. // if (urlStr && urlStr.length && [urlStr rangeOfString:@"?"].length == 1) {
  792. // NSArray *array = [urlStr componentsSeparatedByString:@"?"];
  793. // if (array && array.count == 2) {
  794. // NSString *paramsStr = array[1];
  795. // if (paramsStr.length) {
  796. // NSMutableDictionary *paramsDict = [NSMutableDictionary dictionary];
  797. // NSArray *paramArray = [paramsStr componentsSeparatedByString:@"&"];
  798. // for (NSString *param in paramArray) {
  799. // if (param && param.length) {
  800. // NSArray *parArr = [param componentsSeparatedByString:@"="];
  801. // if (parArr.count == 2) {
  802. // [paramsDict setObject:parArr[1] forKey:parArr[0]];
  803. // }
  804. // }
  805. // }
  806. // return paramsDict;
  807. // }else{
  808. // return nil;
  809. // }
  810. // }else{
  811. // return nil;
  812. // }
  813. // }else{
  814. // return nil;
  815. // }
  816. }
  817. - (void)handleCustomAction:(NSString *)URL
  818. {
  819. // 判断跳转
  820. NSString *link_id = @"";
  821. if ([URL hasPrefix:@"live://live?action=copy_share_url&copy="]) {
  822. NSDictionary *dicP = [self dictionaryWithUrlString:URL];
  823. NSString *shareText = [URL substringFromIndex:@"live://live?action=copy_share_url&copy=".length];
  824. ShareModel *model = [ShareModel new];
  825. NSString *share_content;
  826. if (![model.share_content isEqualToString:@""])
  827. {
  828. share_content = shareText;
  829. }
  830. else
  831. {
  832. share_content = shareText;
  833. }
  834. model.share_title = @"";
  835. model.share_url = shareText;
  836. model.isNotifiService = YES;
  837. // model.roomIDStr = _roomIDStr;
  838. // model.imChatIDStr = [_liveItem liveIMChatRoomId];
  839. [[BGUMengShareManager sharedInstance] showShareViewInControllr:self shareModel:model succ:nil failed:nil];
  840. // BogoSharePopView *shareView = [BogoSharePopView new];
  841. // shareView.shareContent = shareText;
  842. // [shareView show];
  843. return;
  844. UIPasteboard*pasteboard = [UIPasteboard generalPasteboard];
  845. pasteboard.string = shareText;
  846. [BGHUDHelper alert:ASLocalizedString(@"已复制到粘贴板")];
  847. NSArray *activityItems = [[NSArray alloc] initWithObjects:shareText, nil];
  848. UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
  849. UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
  850. NSLog(@"%@",activityType);
  851. if (completed) {
  852. NSLog(ASLocalizedString(@"分享成功"));
  853. } else {
  854. NSLog(ASLocalizedString(@"分享失败"));
  855. }
  856. [vc dismissViewControllerAnimated:YES completion:nil];
  857. };
  858. vc.completionWithItemsHandler = myBlock;
  859. [self presentViewController:vc animated:YES completion:nil];
  860. }
  861. else if([URL hasPrefix:@"live://open_native"])
  862. {
  863. NSDictionary *dicP = [self dictionaryWithUrlString:URL];
  864. [self carAnimationPlayerWith:[dicP valueForKey:@"svgaurl"]];
  865. }
  866. else if([URL containsString:@"bogogame://exit"])
  867. {
  868. [self.navigationController popViewControllerAnimated:YES];
  869. [self dismissViewControllerAnimated:YES completion:nil];
  870. }
  871. }
  872. - (void)carAnimationPlayerWith:(NSString *)url {
  873. play = [[CarAnimationPlayer alloc] initWithFrame:self.view.bounds];
  874. play.titleView.hidden = YES;
  875. UserModel *user = [[UserModel alloc] init];
  876. user.nick_name = [IMAPlatform sharedInstance].host.imUserName;
  877. user.noble_car_url = url;
  878. [play setContent:user];
  879. [self.view addSubview:play];
  880. play.delegate = self;
  881. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  882. // [play removeFromSuperview];
  883. // });
  884. }
  885. - (void)CarAnimationHiddenPlayerDelegate
  886. {
  887. [play removeFromSuperview];
  888. }
  889. - (void)enterAppLiveWithDict:(NSDictionary *)dict
  890. {
  891. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  892. item.chatRoomId = [dict toString:@"groupId"];
  893. item.avRoomId = [dict toInt:@"roomId"];
  894. item.title = [dict toString:@"roomId"];
  895. TCShowUser *showUser = [[TCShowUser alloc]init];
  896. showUser.uid = [dict toString:@"createrId"];
  897. showUser.avatar = [dict toString:@"loadingVideoImageUrl"];
  898. item.host = showUser;
  899. IMAHost *new_Host = [IMAPlatform sharedInstance].host ;
  900. if ([IMAPlatform sharedInstance].host)
  901. {
  902. // 加载小屏幕悬浮直播
  903. [SVProgressHUD showWithStatus:ASLocalizedString(@"正在加载...")];
  904. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  905. [SuspenionWindow initSmallSusWindow:YES WithItem:item withRoomHost:[IMAPlatform sharedInstance].host withVagueImgeUrlStr:[dict toString:@"loadingVideoImageUrl"] withModelRoomIdStr: item.title];
  906. [SVProgressHUD dismiss];
  907. self.BuguLive.isHaveDelete = NO;
  908. });
  909. }
  910. else
  911. {
  912. //NSLog(@"--------------- identifier = %@ userSig = %@ appidAt3rd = %@ , sdkAppId = %d",new_Host.loginParm.identifier,new_Host.loginParm.userSig,new_Host.loginParm.appidAt3rd,new_Host.loginParm.sdkAppId);
  913. [FanweMessage alert:ASLocalizedString(@"加载异常")];
  914. }
  915. }
  916. #pragma mark 加入直播间
  917. - (void)joinLiving:(NSDictionary *)dict
  918. {
  919. if (dict)
  920. {
  921. [self joinOtherLiving:dict];
  922. }
  923. }
  924. #pragma mark 加入直播间
  925. - (void)joinOtherLiving:(NSDictionary *)dict
  926. {
  927. [self.BuguLive.newestLivingMArray removeAllObjects];
  928. NSArray *list = [dict objectForKey:@"list"];
  929. if (list && [list isKindOfClass:[NSArray class]])
  930. {
  931. for (NSDictionary *tmpdict in list)
  932. {
  933. LivingModel *livingModel = [LivingModel mj_objectWithKeyValues:tmpdict];
  934. [self.BuguLive.newestLivingMArray addObject:livingModel];
  935. }
  936. }
  937. IMAHost *host = [IMAPlatform sharedInstance].host;
  938. if (host)
  939. {
  940. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
  941. // videoType 视频类型 1:回播
  942. // if ([dict toInt:@"videoType"] == 1)
  943. // {
  944. // liveRoom.liveType = FW_LIVE_TYPE_RELIVE;
  945. // }
  946. // else
  947. // {
  948. // liveRoom.liveType = FW_LIVE_TYPE_AUDIENCE;
  949. // }
  950. liveRoom.liveType = FW_LIVE_TYPE_AUDIENCE;
  951. liveRoom.avRoomId = [dict toInt:@"roomId"];
  952. liveRoom.title = [dict toString:@"roomId"];
  953. liveRoom.vagueImgUrl = [dict toString:@"loadingVideoImageUrl"];
  954. liveRoom.chatRoomId = [dict toString:@"groupId"];
  955. //2020-1-7 小直播变大
  956. [LiveCenterManager sharedInstance].itemModel=liveRoom;
  957. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  958. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:liveRoom modelArr:nil isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
  959. }];
  960. }
  961. }
  962. #pragma mark 呼出直播小屏
  963. - (void)joinLiveController:(NSDictionary *)dict
  964. {
  965. if (dict)
  966. {
  967. [self saveString:[dict toString:@"session_id"] withName:@"session_id"];
  968. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  969. [mDict setObject:@"shop" forKey:@"ctl"];
  970. [mDict setObject:@"getvideo" forKey:@"act"];
  971. [mDict setObject:[dict toString:@"podcast_id"] forKey:@"podcast_id"];
  972. if ([dict toInt:@"is_small_screen"])
  973. {
  974. [mDict setObject:[dict toString:@"is_small_screen"] forKey:@"is_small_screen"];
  975. }
  976. [mDict setObject:[dict toString:@"session_id"] forKey:@"session_id"];
  977. FWWeakify(self)
  978. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson)
  979. {
  980. FWStrongify(self)
  981. if ([responseJson toInt:@"status"] == 1)//请求成功跳转到pushViewController
  982. {
  983. if ([BGIMLoginManager sharedInstance].isIMSDKOK)
  984. {
  985. [self enterAppLiveWithDict:responseJson];
  986. }
  987. else
  988. {
  989. [BGIMLoginManager sharedInstance].loginParam.identifier = [[responseJson objectForKey:@"user"] toString:@"user_id"];
  990. [[BGIMLoginManager sharedInstance] getUserSig:^{
  991. [self jumpWithType:CurrentJumpPublishLive enterLivingDict:responseJson];
  992. [self hideMyHud];
  993. } failed:^(int errId, NSString *errMsg) {
  994. [self hideMyHud];
  995. }];
  996. }
  997. }
  998. } FailureBlock:^(NSError *error) {
  999. }];
  1000. }
  1001. }
  1002. #pragma mark 进入app主页(呼出直播应用)
  1003. - (void)enterMianAppView:(NSDictionary *)dict
  1004. {
  1005. // 如果有悬浮要先执行退出悬浮
  1006. if ([AppDelegate sharedAppDelegate].sus_window.rootViewController)
  1007. {
  1008. FWWeakify(self)
  1009. [SuspenionWindow exitSuswindowBlock:^(BOOL finished) {
  1010. FWStrongify(self)
  1011. if (finished)
  1012. {
  1013. [self goLiveApp:dict];
  1014. }
  1015. }];
  1016. }
  1017. else
  1018. {
  1019. [self goLiveApp:dict];
  1020. }
  1021. }
  1022. #pragma mark 进入app原生直播的主页
  1023. - (void)goLiveApp:(NSDictionary *)dict
  1024. {
  1025. if (dict)
  1026. {
  1027. [self saveString:[dict toString:@"session_id"] withName:@"session_id"];
  1028. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1029. [mDict setObject:@"shop" forKey:@"ctl"];
  1030. [mDict setObject:@"getapp" forKey:@"act"];
  1031. [mDict setObject:[dict toString:@"session_id"] forKey:@"session_id"];
  1032. FWWeakify(self)
  1033. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson)
  1034. {
  1035. FWStrongify(self)
  1036. if ([responseJson toInt:@"status"] == 1)
  1037. {
  1038. if ([BGIMLoginManager sharedInstance].isIMSDKOK)
  1039. {
  1040. self.BuguLive.isHaveDelete = YES;
  1041. [[AppDelegate sharedAppDelegate] entertabBar];
  1042. }
  1043. else
  1044. {
  1045. [BGIMLoginManager sharedInstance].loginParam.identifier = [[responseJson objectForKey:@"user"] toString:@"user_id"];
  1046. [[BGIMLoginManager sharedInstance] getUserSig:^{
  1047. [self jumpWithType:CurrentJumpPublishLive enterLivingDict:responseJson];
  1048. [self hideMyHud];
  1049. } failed:^(int errId, NSString *errMsg) {
  1050. [self hideMyHud];
  1051. }];
  1052. }
  1053. }
  1054. } FailureBlock:^(NSError *error)
  1055. {
  1056. }];
  1057. }
  1058. }
  1059. #pragma mark 创建房间或者进入房间的回调
  1060. - (void)getuserinfoWithStaute:(NSDictionary *)dict
  1061. {
  1062. NSString *jsStr=[NSString stringWithFormat:@"js_getuserinfo(\"%@\")",@""];
  1063. [self.webView evaluateJavaScript:jsStr completionHandler:^(id str, NSError * _Nullable error) {
  1064. NSLog(@"%@",str);
  1065. NSLog(@"%@",error);
  1066. }];
  1067. }
  1068. #pragma mark h5回到直播间
  1069. - (void)comeBackLive:(NSDictionary *)dict
  1070. {
  1071. [self backLiveVC];
  1072. }
  1073. - (void)backLiveVC
  1074. {
  1075. [BGUtils closeKeyboard];
  1076. if (!self.isSmallScreen || kSupportH5Shopping)
  1077. {
  1078. UIViewController *viewCtl;
  1079. for (int i = 0; i < [self.navigationController.viewControllers count]; i ++)
  1080. {
  1081. viewCtl = [self.navigationController.viewControllers objectAtIndex:(i)];
  1082. if ([viewCtl isKindOfClass:[BGLiveServiceController class]])
  1083. {
  1084. [self.navigationController popToViewController:viewCtl animated:YES];
  1085. }
  1086. }
  1087. [self.navigationController popViewControllerAnimated:YES];
  1088. }
  1089. else
  1090. {
  1091. [[LiveCenterManager sharedInstance] showChangeAuctionLiveScreenSOfIsSmallScreen:NO nextViewController:nil delegateWindowRCNameStr:@"BGTabBarController" complete:^(BOOL finished) {
  1092. }];
  1093. }
  1094. }
  1095. #pragma mark 需要上传直播类型
  1096. - (void)getLiveType:(NSDictionary *)dict
  1097. {
  1098. if (SUS_WINDOW.recordFWTLiveController)
  1099. {
  1100. if (self.webView)
  1101. {
  1102. // control.webView 这个不存在。。需要延迟执行
  1103. NSString *jsStr = [NSString stringWithFormat:@"js_live_state('%@')",@"1"];
  1104. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  1105. }
  1106. }
  1107. else
  1108. {
  1109. if (self.webView)
  1110. {
  1111. // control.webView 这个不存在。。需要延迟执行
  1112. NSString *jsStr = [NSString stringWithFormat:@"js_live_state('%@')",@"0"];
  1113. [self.webView evaluateJavaScript:jsStr completionHandler:nil];
  1114. }
  1115. }
  1116. }
  1117. @end