视频直播源码中关于服务端直播开播推送实现

视频直播源码中直播app开播时需向客户推送开播消息通知用户,实现方式如下:
1.申请相应的推送服务三方,如下使用极光推送,获取相应的配置资料,并做好相应的配置
2.推送代码如下:

 /* 极光推送 */
				$app_key = $configpri['jpush_key'];
				$master_secret = $configpri['jpush_secret'];
				$info = $data;
				if($app_key && $master_secret  && $info){	
					require './api/public/JPush/autoload.php';
					// 初始化
					$client = new \JPush\Client($app_key, $master_secret,null);
					$userinfo=getUserInfo($uid);
					$anthorinfo=array(
						"uid"=>$info['uid'],
						"avatar"=>$info['avatar'],
						"avatar_thumb"=>$info['avatar_thumb'],
						"user_nicename"=>$info['user_nicename'],
						"title"=>$info['title'],
						"city"=>$info['city'],
						"stream"=>$info['stream'],
						"pull"=>$info['pull'],
						"thumb"=>$info['thumb'],
						"isvideo"=>'0',
						"type"=>$info['type'],
						"type_val"=>$info['type_val'],
						"game_action"=>'0',
						"goodnum"=>$info['goodnum'],
						"anyway"=>$info['anyway'],
						"nums"=>0,
						"level_anchor"=>$userinfo['level_anchor'],
						"game"=>'',
					);
					$title='你的好友:'.$anthorinfo['user_nicename'].'正在直播,邀请你一起';
					$apns_production=false;
					if($configpri['jpush_sandbox']){
						$apns_production=true;
					}
					$pushids = $this->getFansIds_a($uid,$title); 
					$nums=count($pushids);	
					for($i=0;$i<$nums;){
						$alias=array_slice($pushids,$i,900);
						$i+=900;
						try{	
							$result = $client->push()
									->setPlatform('all')
									->addRegistrationId($alias)
									->setNotificationAlert($title)
									->iosNotification($title, array(
										'sound' => 'sound.caf',
										'category' => 'jiguang',
										'extras' => array(
											'type' => '1',
											'userinfo' => $anthorinfo
										),
									))
									->androidNotification('', array(
										'extras' => array(
											'title' => $title,
											'type' => '1',
											'userinfo' => $anthorinfo
										),
									))
									->options(array(
										'sendno' => 100,
										'time_to_live' => 0,
										'apns_production' =>  $apns_production,
									))
									->send();	
							$result1 = $client->push()
									->setPlatform('all')
									->addRegistrationId($alias)
									->setNotificationAlert($title)
									->iosNotification($title, array(
										'sound' => 'sound.caf',
										'category' => 'jiguang',
										'extras' => array(
											'type' => '2',
											'userinfo' => $anthorinfo
										),
									))
									->androidNotification('', array(
										'extras' => array(
											'title' => $title,
											'type' => '2',
											'userinfo' => $anthorinfo
										),
									))
									->options(array(
										'sendno' => 100,
										'time_to_live' => 0,
										'apns_production' =>  $apns_production,
									))
									->send();							
						} catch (Exception $e) {   
							file_put_contents('./jpush.txt',date('y-m-d h:i:s').'提交参数信息 设备
名:'.json_encode($alias)."\r\n",FILE_APPEND);
							file_put_contents('./jpush.txt',date('y-m-d h:i:s').'提交参数信息:'.$e."\r\n",FILE_APPEND);
						}					
					}			
				}
				/* 极光推送 */			

3.直播推送可以在主播执行开播同时执行上述代码,实现主播开播后给已关注的app用户发送通知的功能。
以上就是视频直播源码中关于服务端直播开播推送实现的方式,后期还会更新更多关于直播源码开发的相关知识,关注本博主,持续为大家带来干货。
声明:本篇文章为小编原创文章,转载请注明出处及作者。

你可能感兴趣的:(直播系统源码)