Index.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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])
  24. ->order(['id' => 'desc'])->find();
  25. if (empty(Session::get('wxId')) || empty($info)){
  26. header("Location:".CommonService::getAuthUrl($channelId));
  27. die();
  28. }
  29. // $model = new VisitorModel();
  30. // $visitorInfo = $model::where(['unionid' => Session::get('wxId')])->find();
  31. // if (empty($visitorInfo)) {
  32. // $model->insertGetId([
  33. // 'visitorId' => $visitorId,
  34. // 'unionid' => Session::get('wxId'),
  35. // ]);
  36. // } else {
  37. // $visitorId = $visitorInfo['visitorId'];
  38. // }
  39. $params = [
  40. 'id' => $info['channel_id'],
  41. 'userid' => $info['unionid'],
  42. 'name' => $info['name'],
  43. 'avatar' => $info['avatar'],
  44. 'key' => $info['key']
  45. ];
  46. header('Location:http://mudu.tv/activity.php?a=userAssign&'.http_build_query($params));
  47. die();
  48. //增加客户自己的验证逻辑,例如登录,关注,付费,填手机号等
  49. $key = md5($visitorId.$data['channel_auth_code']);
  50. if(strpos($notifyUrl,'?') !== false){//url参数处理,将key加到url参数中
  51. $returnUrl = $notifyUrl."&key=".$key."&expire=1";
  52. }else{
  53. $returnUrl = $notifyUrl."?key=".$key."&expire=1";
  54. }
  55. header("Location:".$returnUrl);//跳转到直播观看页
  56. // redirect($returnUrl);
  57. }
  58. }