Index.php 2.1 KB

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