Index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/5 17:55
  5. */
  6. namespace app\index\controller;
  7. use app\common\service\CommonService;
  8. use app\index\exception\ApiException;
  9. use app\index\model\UserModel;
  10. use think\console\command\make\Model;
  11. use think\facade\Cache;
  12. use think\facade\Session;
  13. class Index {
  14. public function index() {
  15. $visitorId = input('visitorId');
  16. $notifyUrl = input('notify_url');
  17. $channelId = input('channelId');
  18. if (empty($channelId)){
  19. throw new ApiException('渠道id不为空');
  20. }
  21. $data = CommonService::getSetData($channelId);
  22. $info = (new UserModel())::where(['unionid' => Session::get('wxId'), 'channel_id' => $channelId])->find();
  23. if (empty(Session::get('wxId')) || empty($info)){
  24. Cache::set(Session::get('wxId'), '');
  25. header("Location:".CommonService::getAuthUrl($channelId));
  26. die();
  27. }
  28. if (empty(Cache::get(Session::get('wxId')))) {
  29. Cache::set(Session::get('wxId'), $visitorId);
  30. }
  31. $visitorId = Cache::get(Session::get('wxId'));
  32. // $params = [
  33. // 'id' => $info['channel_id'],
  34. // 'userid' => $info['unionid'],
  35. // 'name' => $info['nickName'],
  36. // 'avatar' => $info['avatar'],
  37. // 'key' => $info['key']
  38. // ];
  39. // header('Location:http://mudu.tv/activity.php?a=userAssign&'.http_build_query($params));
  40. // die();
  41. //增加客户自己的验证逻辑,例如登录,关注,付费,填手机号等
  42. $key = md5($visitorId.$data['channel_auth_code']);
  43. if(strpos($notifyUrl,'?') !== false){//url参数处理,将key加到url参数中
  44. $returnUrl = $notifyUrl."&key=".$key."&expire=3600";
  45. }else{
  46. $returnUrl = $notifyUrl."?key=".$key."&expire=3600";
  47. }
  48. header("Location:".$returnUrl);//跳转到直播观看页
  49. // redirect($returnUrl);
  50. }
  51. }