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