share.action.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | FANWE 直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class shareModule extends baseModule
  10. {
  11. var $signPackage = '';
  12. var $user_info = '';
  13. var $wx_url = '';
  14. var $video_id = '';
  15. var $user_id = '';
  16. //分享首页
  17. public function index()
  18. {
  19. $video_id = intval($_REQUEST['video_id']);
  20. $this->video_id = $video_id;
  21. $user_id = intval($_REQUEST['user_id']);
  22. $this->user_id = $user_id;
  23. $share_id = intval($_REQUEST['share_id']);
  24. $code = strim($_REQUEST['code']);
  25. $is_black = intval($_REQUEST['is_black']);
  26. $call_back = SITE_DOMAIN.'/wap/index.php?ctl=share&act=index&user_id='.$user_id.'&video_id='.$video_id;
  27. $from = $_REQUEST['from'];
  28. $isappinstalled = $_REQUEST['isappinstalled'];
  29. if($from){
  30. $call_back.='&from='.$from;
  31. }
  32. if($isappinstalled){
  33. $call_back.='&isappinstalled='.$isappinstalled;
  34. }
  35. $this->check_user_info($call_back,$code);
  36. /*if($code&&strlen($code)==32){
  37. $call_back = SITE_DOMAIN.'/wap/index.php?ctl=share&act=index&user_id='.$user_id.'&video_id='.$video_id."&code=".$code."&state=1";
  38. $this->check_user_info($call_back,$code);
  39. }else{
  40. $call_back = SITE_DOMAIN.'/wap/index.php?ctl=share&act=index&user_id='.$user_id.'&video_id='.$video_id;
  41. $this->check_user_info($call_back);
  42. }*/
  43. if($GLOBALS['user_info']){
  44. $root['user_info'] = $GLOBALS['user_info'];
  45. }else{
  46. $root['user_info'] = false;
  47. }
  48. $user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id=".$user_id );
  49. $root['wx_url'] = $this->wx_url;
  50. $m_config = load_auto_cache("m_config");//初始化手机端配置
  51. $root['app_logo'] = get_spec_image($m_config['app_logo']);
  52. $live_in = $GLOBALS['db']->getOne("select v.live_in from ".DB_PREFIX."video as v where v.id = ".$video_id );
  53. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  54. $video_redis = new VideoRedisService();
  55. if(intval($live_in)==0 || intval($live_in)==3){
  56. if(intval($live_in)==3){
  57. $video = $GLOBALS['db']->getRow("select vh.id as room_id,vh.group_id as group_id,vh.max_watch_number as watch_number,vh.video_vid,vh.room_type,vh.vote_number,vh.channelid,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex ,vh.live_in, vh.video_type, vh.begin_time,vh.is_live_pay from ".DB_PREFIX."video as vh left join ".DB_PREFIX."user as u on vh.user_id=u.id where vh.room_type=3 and vh.id = ".$video_id );
  58. }else{
  59. $video = $GLOBALS['db']->getRow("select vh.id as room_id,vh.group_id as group_id,vh.max_watch_number as watch_number,vh.video_vid,vh.room_type,vh.vote_number,vh.channelid,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex ,vh.live_in, vh.video_type, vh.begin_time,vh.is_live_pay from ".DB_PREFIX."video_history as vh left join ".DB_PREFIX."user as u on vh.user_id=u.id where vh.room_type=3 and vh.id = ".$video_id );
  60. }
  61. $video['viewer_num'] = $video_redis->get_video_watch_num($video['room_id']);
  62. $video['podcast'] = getuserinfo($user_id,$video['user_id'],$video['user_id']);
  63. $video['nick_name'] = emoji_decode($video['nick_name']);
  64. if($video['video_type'] == 1 && $video['channelid'])
  65. {
  66. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  67. $video_factory = new VideoFactory();
  68. $ret = $video_factory->GetVodUrls($video['channelid'], $video['begin_time']);
  69. if($video['is_live_pay'] == 1||(intval($m_config['qq_app_api'])&&intval($m_config['wx_app_api'])&&intval($m_config['sina_app_api']))){
  70. $video['urls'] = '';
  71. $video['file_id'] ='' ;
  72. }else{
  73. $video['urls'] = array_shift($ret['urls']);
  74. $video['file_id'] = $ret['file_id'];
  75. }
  76. } else {
  77. //播放地址
  78. if($video['is_live_pay'] == 1||(intval($m_config['qq_app_api'])&&intval($m_config['wx_app_api'])&&intval($m_config['sina_app_api']))){
  79. $video['video_list'] = '';
  80. $video['urls'] = '';
  81. $video['file_id'] = '';
  82. }else{
  83. $video_vid = get_vodset_by_video_id($video['room_id']);
  84. foreach($video_vid['vodset'] as $k=>$v){
  85. $playSet = $v['fileSet'][0]['playSet'];
  86. foreach($playSet as $kk=>$vv){
  87. if(strpos($vv['url'],'f0.mp4')){
  88. $video_vid_list[$k]['url'] = $vv['url'];
  89. }
  90. }
  91. $video_vid_list[$k]['image_url'] = $v['fileSet'][0]['image_url'];
  92. $video_vid_list[$k]['fileId'] = $v['fileSet'][0]['fileId'];
  93. }
  94. $video['video_list'] = $video_vid_list;
  95. $video['urls'] = $video_vid_list[0]['url'];
  96. $video['file_id'] = $video_vid_list[0]['fileId'];
  97. }
  98. }
  99. if(intval($video['room_id'])==0){
  100. $video = $GLOBALS['db']->getRow("select v.id as room_id,v.group_id as group_id,v.max_watch_number as watch_number,v.video_vid,v.room_type,v.vote_number,v.channelid,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex ,v.live_in,v.is_live_pay from ".DB_PREFIX."video as v left join ".DB_PREFIX."user as u on v.user_id=u.id where v.room_type=3 and v.id = ".$video_id );
  101. }
  102. }else{
  103. $video = $GLOBALS['db']->getRow("select v.id as room_id,v.group_id as group_id,v.max_watch_number as watch_number,v.video_vid,v.room_type,v.vote_number,v.channelid,v.play_flv,v.play_hls,v.play_rtmp,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex ,v.live_in,v.is_live_pay from ".DB_PREFIX."video as v left join ".DB_PREFIX."user as u on v.user_id=u.id where v.room_type=3 and v.id = ".$video_id );
  104. $video['viewer_num'] = $video_redis->get_video_watch_num($video['room_id']);
  105. if(intval($video['live_in'])!=1 && intval($video['live_in'])!=3){
  106. $video['live_in'] = 0;
  107. }
  108. }
  109. $video['nick_name'] = emoji_decode($video['nick_name']);
  110. $root['appid'] =$m_config['vodset_app_id'] ;
  111. $root['video_type'] =$m_config['video_type'] ;
  112. if(intval($video['live_in'])!=1 && intval($video['live_in'])!=3){
  113. $video['live_in'] = 0;
  114. }
  115. //禁用分享
  116. if($m_config['sina_app_api']==0&&$m_config['wx_app_api']==0&&$m_config['qq_app_api']==0){
  117. $is_close_share = 1;
  118. }
  119. // 付费直播提示下载弹窗
  120. if($video['is_live_pay'] == 1||$is_close_share){
  121. $video['play_hls'] = '';
  122. $video['play_url'] = '';
  123. }
  124. //付费不能观看
  125. if($video['is_live_pay']==1){
  126. $video['live_in'] = 4;
  127. }
  128. //若当前 视频 不在直播状态,查找当前主播的直播视频
  129. /*if($video['live_in']!=1){
  130. //查找当前主播的直播视频
  131. $noe_video = $GLOBALS['db']->getRow("select v.id as room_id,v.group_id as group_id,v.watch_number,v.video_vid,v.room_type,v.vote_number,v.channelid,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex ,v.live_in from ".DB_PREFIX."video as v left join ".DB_PREFIX."user as u on v.user_id=u.id where v.user_id = ".$user_id." and v.live_in =1" );
  132. //若视频有值
  133. if($noe_video['room_id']){
  134. $video = $noe_video;
  135. }
  136. }*/
  137. //分享链接
  138. $video['url'] = $call_back;
  139. $root['video'] = $video;
  140. //回播日志
  141. $now = NOW_TIME-3600*24;
  142. $history = $GLOBALS['db']->getAll("select vh.id as room_id,vh.begin_time,vh.group_id as group_id,vh.max_watch_number as watch_number,vh.video_vid,vh.room_type,vh.vote_number,vh.channelid,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex from ".DB_PREFIX."video_history as vh left join ".DB_PREFIX."user as u on vh.user_id=u.id where vh.room_type=3 and vh.is_del_vod =0 and vh.is_delete =0 and vh.user_id=u.id and vh.user_id = ".$user_id." and vh.begin_time>".$now." order by vh.id desc");
  143. foreach($history as $kk=>$vv){
  144. $history[$kk]['end_time'] = format_show_date($vv['begin_time']);
  145. $history[$kk]['head_image'] = get_spec_image($vv['head_image']);
  146. $history[$kk]['user_url'] = url_app('home',array('podcast_id'=>$vv['user_id']));
  147. $history[$kk]['url'] = SITE_DOMAIN.'/wap/index.php?ctl=share&act=index&user_id='.$vv['user_id'].'&video_id='.$vv['room_id'];//分享链接
  148. }
  149. $root['history'] = $history;
  150. //hot_video 热门视频
  151. $video_hot = $GLOBALS['db']->getAll("select v.id as room_id,v.group_id as group_id,v.max_watch_number as watch_number,v.video_vid,v.room_type,v.vote_number,v.channelid,v.title,v.live_image,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex from ".DB_PREFIX."video as v left join ".DB_PREFIX."user as u on v.user_id=u.id where v.room_type=3 and (v.live_in = 1 or v.live_in = 3) and v.user_id=u.id and u.head_image <>'' and v.begin_time <> 0 order by v.max_watch_number desc limit 0,10");
  152. foreach($video_hot as $k=>$v){
  153. $video_hot[$k]['head_image'] = get_spec_image($v['head_image']);
  154. $video_hot[$k]['channelid'] = $v['channelid'];
  155. $video_hot[$k]['user_url'] = url_app('home',array('podcast_id'=>$v['user_id']));
  156. $video_hot[$k]['url'] = SITE_DOMAIN.'/wap/index.php?ctl=share&act=index&user_id='.$v['user_id'].'&video_id='.$v['room_id'];//分享链接
  157. $video_hot[$k]['live_image'] = get_spec_image($v['live_image']);
  158. }
  159. $root['video_hot'] = $video_hot;
  160. $root['app_down'] = SITE_DOMAIN.'/mapi/index.php?ctl=app_download';
  161. if ((defined('DISTRIBUTION_SCAN')&&DISTRIBUTION_SCAN==1)) //二级分销开启
  162. {
  163. $root['app_down'] = $GLOBALS['db']->getOne("select distribution_url from ".DB_PREFIX."user where id = ".$user_id,true,true);
  164. }
  165. $root['signPackage'] = $this->signPackage;
  166. $share = array();
  167. $share['short_name'] = strim($m_config['short_name']);
  168. $share['share_title'] = strim($m_config['share_title']);
  169. $share['share_img_url'] =get_spec_image($user_info['head_image']);
  170. $share['share_wx_url'] = $video['url'];
  171. $share['share_desc'] = strim($m_config['share_title']).$user_info['nick_name'].'正在直播,快来一起看~';
  172. $root['share'] = $share;
  173. $tim_user_id = $root['user_info']['user_id'] ? $root['user_info']['user_id'] : 0;
  174. $usersig = load_auto_cache("usersig", array("id"=>$tim_user_id));
  175. $root['usersig'] = $usersig['usersig'];
  176. $root['tim_account_id'] = $tim_user_id;
  177. $m_config = load_auto_cache("m_config");
  178. $root['tim_sdkappid'] = $m_config['tim_sdkappid'];
  179. $root['tim_account_type'] = $m_config['tim_account_type'];
  180. //分销功能
  181. if((defined('OPEN_DISTRIBUTION')&&OPEN_DISTRIBUTION==1)&&intval($m_config['distribution'])==1){
  182. $root['register_url'] = SITE_DOMAIN.'/wap/index.php?ctl=distribution&act=init_register&user_id='.$share_id;
  183. }
  184. api_ajax_return($root);
  185. }
  186. //新分享首页
  187. public function live()
  188. {
  189. $video_id = intval($_REQUEST['video_id']);
  190. $user_id = intval($_REQUEST['user_id']);
  191. $share_id = intval($_REQUEST['share_id']);
  192. $code = strim($_REQUEST['code']);
  193. if (defined('WEIXIN_DISTRIBUTION') && WEIXIN_DISTRIBUTION && $share_id) {
  194. fanwe_require(APP_ROOT_PATH . 'mapi/lib/tools/Wx.class.php');
  195. $wx_info = Wx::getWeixinInfo();
  196. require_once APP_ROOT_PATH . 'mapi/lib/core/Model.class.php';
  197. Model::$lib = dirname(__FILE__);
  198. Model::build('weixin_distribution')->addWithUnionId($wx_info['unionid'],$share_id);
  199. }
  200. $call_back = SITE_DOMAIN.'/wap/index.php?ctl=share&act=live&user_id='.$user_id.'&video_id='.$video_id.'&share_id='.$share_id;
  201. $from = $_REQUEST['from'];
  202. $isappinstalled = $_REQUEST['isappinstalled'];
  203. if(trim($from)!=''){
  204. $call_back.='&from='.$from;
  205. }
  206. if(trim($isappinstalled)!=''){
  207. $call_back.='&isappinstalled='.$isappinstalled;
  208. }
  209. $this->check_user_info($call_back,$code);
  210. if($GLOBALS['user_info']){
  211. $root['user_info'] = $GLOBALS['user_info'];
  212. }else{
  213. $root['user_info'] = false;
  214. }
  215. $user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id=".$user_id );
  216. $root['wx_url'] = $this->wx_url;
  217. $m_config = load_auto_cache("m_config");//初始化手机端配置
  218. $root['app_logo'] = get_spec_image($m_config['app_logo']);
  219. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  220. $video_redis = new VideoRedisService();
  221. $video = $video_redis->getRow_db($video_id, array('user_id', 'is_live_pay', 'live_in', 'group_id', 'live_image', 'head_image', 'play_hls', 'play_url', 'video_type', 'channelid', 'begin_time', 'create_time', 'create_type'));
  222. if($video['live_in']!=1 && $video['live_in']!=3){
  223. $live_list=load_auto_cache("select_video");
  224. foreach($live_list as $k=>$v){
  225. if($v['user_id']==$user_id){
  226. if($video_id != $v['room_id']){
  227. $video_id=$v['room_id'];
  228. $video = $video_redis->getRow_db($video_id, array('user_id', 'is_live_pay', 'live_in', 'group_id', 'play_hls', 'play_url', 'video_type', 'channelid', 'begin_time', 'create_time'));
  229. }
  230. }
  231. }
  232. }
  233. $video['viewer_num'] = $video_redis->get_video_watch_num($video_id);
  234. $video['podcast'] = getuserinfo($user_id,$video['user_id'],$video['user_id']);
  235. //禁用分享
  236. if($m_config['sina_app_api']==0&&$m_config['wx_app_api']==0&&$m_config['qq_app_api']==0){
  237. $is_close_share = 1;
  238. }
  239. // 付费直播提示下载弹窗
  240. if($video['is_live_pay'] == 1||$is_close_share){
  241. $video['play_hls'] = '';
  242. $video['play_url'] = '';
  243. } else if($video['live_in']==0 || $video['live_in']==3){
  244. $file_info = load_auto_cache('video_file', array(
  245. 'id' => $video_id,
  246. 'video_type' => $video['video_type'],
  247. 'channelid' => $video['channelid'],
  248. 'begin_time' => $video['begin_time'],
  249. 'create_time' => $video['create_time'],
  250. ));
  251. $video['file_id'] = $file_info['file_id'];
  252. $video['urls'] = $file_info['urls'];
  253. foreach( $video['urls'] as $url)
  254. {
  255. $info = pathinfo($url);
  256. if($info['extension'] == 'mp4')
  257. {
  258. $video['play_url'] = $url;
  259. break;
  260. }
  261. }
  262. }else if ($video['live_in'] != 1) {
  263. $video['live_in'] = 0;
  264. }
  265. //分享链接
  266. $video['url'] = $call_back;
  267. $root['video'] = $video;
  268. //回播日志
  269. $now = NOW_TIME-3600*24;
  270. $history = $GLOBALS['db']->getAll("select vh.id as room_id,vh.begin_time,vh.group_id as group_id,vh.max_watch_number as watch_number,vh.video_vid,vh.room_type,vh.vote_number,vh.channelid,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex from ".DB_PREFIX."video_history as vh left join ".DB_PREFIX."user as u on vh.user_id=u.id where vh.room_type=3 and vh.is_del_vod =0 and vh.is_delete =0 and vh.user_id=u.id and vh.user_id = ".$user_id." and vh.begin_time>".$now." order by vh.id desc");
  271. foreach($history as $kk=>$vv){
  272. $history[$kk]['end_time'] = format_show_date($vv['begin_time']);
  273. $history[$kk]['head_image'] = get_spec_image($vv['head_image']);
  274. $history[$kk]['user_url'] = url_app('home',array('podcast_id'=>$vv['user_id']));
  275. $history[$kk]['url'] = SITE_DOMAIN.'/wap/index.php?ctl=share&act=live&user_id='.$vv['user_id'].'&video_id='.$vv['room_id'];//分享链接
  276. $history[$kk]['nick_name'] = emoji_decode($history[$kk]['nick_name']);
  277. }
  278. $root['history'] = $history;
  279. //hot_video 热门视频
  280. $video_hot = $GLOBALS['db']->getAll("select v.id as room_id,v.group_id as group_id,v.max_watch_number as watch_number,v.video_vid,v.room_type,v.vote_number,v.channelid,v.title,v.live_image,u.id as user_id,u.nick_name as nick_name,u.head_image as head_image,u.user_level as user_level,u.sex as sex from ".DB_PREFIX."video as v left join ".DB_PREFIX."user as u on v.user_id=u.id where v.room_type=3 and (v.live_in = 1 or v.live_in = 3) and v.user_id=u.id and u.head_image <>'' and v.begin_time <> 0 order by v.max_watch_number desc limit 0,10");
  281. foreach($video_hot as $k=>$v){
  282. $video_hot[$k]['head_image'] = get_spec_image($v['head_image']);
  283. $video_hot[$k]['channelid'] = $v['channelid'];
  284. $video_hot[$k]['user_url'] = url_app('home',array('podcast_id'=>$v['user_id']));
  285. $video_hot[$k]['url'] = SITE_DOMAIN.'/wap/index.php?ctl=share&act=live&user_id='.$v['user_id'].'&video_id='.$v['room_id'];//分享链接
  286. $video_hot[$k]['live_image'] = get_spec_image($v['live_image']);
  287. $video_hot[$k]['nick_name'] = emoji_decode($video_hot[$k]['nick_name']);
  288. }
  289. $root['video_hot'] = $video_hot;
  290. $root['app_down'] = SITE_DOMAIN.'/mapi/index.php?ctl=app_download';
  291. if ((defined('DISTRIBUTION_SCAN')&&DISTRIBUTION_SCAN==1)) //二级分销开启
  292. {
  293. $root['app_down'] = $GLOBALS['db']->getOne("select distribution_url from ".DB_PREFIX."user where id = ".$user_id,true,true);
  294. }
  295. $root['signPackage'] = $this->signPackage;
  296. $share = array();
  297. $share['short_name'] = strim($m_config['short_name']);
  298. $share['share_title'] = strim($m_config['share_title']);
  299. $share['share_img_url'] =get_spec_image($user_info['head_image']);
  300. $share['share_wx_url'] = $video['url'];
  301. $share['share_desc'] = strim($m_config['share_title']).emoji_decode($user_info['nick_name']).'正在直播,快来一起看~';
  302. $root['share'] = $share;
  303. $tim_user_id = $root['user_info']['user_id'] > 0 ? $root['user_info']['user_id'] : 0;
  304. $usersig = load_auto_cache("usersig", array("id" => $tim_user_id));
  305. $root['tim'] = array(
  306. 'sdkappid' => $m_config['tim_sdkappid'],
  307. 'account_type' => $m_config['tim_account_type'],
  308. 'account_id' => $tim_user_id,
  309. 'usersig' => $usersig['usersig'],
  310. );
  311. //分销功能
  312. if(((defined('OPEN_DISTRIBUTION')&&OPEN_DISTRIBUTION==1)&&intval($m_config['distribution'])==1)||intval(OPEN_REWARD_POINT)==1){
  313. $root['register_url'] = SITE_DOMAIN.'/wap/index.php?ctl=distribution&act=init_register&user_id='.$share_id;
  314. }
  315. $root['show_live'] = 1;
  316. if (defined('OPEN_BM')&&OPEN_BM==1) {
  317. $bm_video=$GLOBALS['db']->getRow("select is_bm,private_key from ".DB_PREFIX."video where id=".$video_id );
  318. if ($bm_video['is_bm']==1) {
  319. $root['room_pwd']=$bm_video['private_key'];
  320. $root['show_live'] = 0;
  321. }
  322. }
  323. api_ajax_return($root);
  324. }
  325. //检查用户是否登陆
  326. public function check_user_info($back_url,$code=''){
  327. fanwe_require(APP_ROOT_PATH."system/utils/weixin.php");
  328. $m_config = load_auto_cache("m_config");//手机端配置
  329. /*if($m_config['wx_secrit']||$m_config['wx_appid']){
  330. return false;
  331. }*/
  332. if($_REQUEST['ttype']==1){
  333. return true;
  334. }
  335. $is_weixin=isWeixin();
  336. if(!$is_weixin){
  337. return false;
  338. }
  339. $user_info = es_session::get('user_info');
  340. if(!$user_info){
  341. //解密
  342. if($code!=''){
  343. $weixin=new weixin($m_config['wx_gz_appid'],$m_config['wx_gz_secrit']);
  344. $wx_info=$weixin->scope_get_userinfo($code);
  345. }
  346. if($wx_info['openid']){
  347. $has_user = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where wx_unionid = '".$wx_info['unionid']."'");
  348. if(!$has_user){
  349. $data=array();
  350. $data['user_name']= $wx_info['nickname'];
  351. $data['is_effect'] = 1;
  352. $data['head_image']= $wx_info['headimgurl'];
  353. syn_to_remote_image_server($wx_info['headimgurl']);
  354. $data['gz_openid']= $wx_info['openid'];
  355. $data['wx_unionid']= $wx_info['unionid'];
  356. //用户是否关注公众号
  357. $data['subscribe']= $wx_info['subscribe'];
  358. $data['create_time']= get_gmtime();
  359. $data['user_pwd'] = md5(rand(99999,9999999));
  360. $GLOBALS['db']->autoExecute(DB_PREFIX."user",$data);
  361. $user_id = $GLOBALS['db']->insert_id();
  362. $data['id'] = $user_id ;
  363. $user_info = $data;
  364. }else{
  365. if($has_user['subscribe']!=$wx_info['subscribe']){
  366. //更新公众号是否关注的状态
  367. $GLOBALS['db']->query("update ".DB_PREFIX."user set subscribe = ".$wx_info['subscribe']." where id ='".$has_user['id']."'");
  368. $has_user['subscribe'] = $wx_info['subscribe'];
  369. }
  370. $user_info = $has_user;
  371. }
  372. es_session::set("user_info", $user_info);
  373. $GLOBALS['db']->query("update ".DB_PREFIX."user set login_time = '".get_gmtime()."' where wx_unionid ='".$wx_info['unionid']."'");
  374. $this->wx_url = '';
  375. $this->user_info = $user_info;
  376. fanwe_require(APP_ROOT_PATH."system/utils/jssdk.php");
  377. $jssdk=new JSSDK($m_config['wx_gz_appid'],$m_config['wx_gz_secrit']);
  378. $jssdk->set_url($back_url);
  379. $signPackage = $jssdk->getSignPackage();
  380. $this->signPackage = $signPackage;
  381. }else{
  382. //加密
  383. /*$weixin=new weixin($m_config['wx_appid'],$m_config['wx_secrit'],$back_url);
  384. $wx_url=$weixin->scope_get_code();
  385. $this->wx_url = $wx_url;*/
  386. $this->wx_url = '';
  387. $this->user_info = $user_info;
  388. fanwe_require(APP_ROOT_PATH."system/utils/jssdk.php");
  389. $jssdk=new JSSDK($m_config['wx_gz_appid'],$m_config['wx_gz_secrit']);
  390. $jssdk->set_url($back_url);
  391. $signPackage = $jssdk->getSignPackage();
  392. $this->signPackage = $signPackage;
  393. }
  394. }else{
  395. $this->wx_url = '';
  396. $this->user_info = $user_info;
  397. fanwe_require(APP_ROOT_PATH."system/utils/jssdk.php");
  398. $jssdk=new JSSDK($m_config['wx_gz_appid'],$m_config['wx_gz_secrit']);
  399. $jssdk->set_url($back_url);
  400. $signPackage = $jssdk->getSignPackage();
  401. $this->signPackage = $signPackage;
  402. }
  403. }
  404. }
  405. ?>