Index.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 think\facade\Session;
  10. class Index {
  11. public function index() {
  12. $visitorId = input('visitorId');
  13. $notifyUrl = input('notify_url');
  14. $channelId = input('channelId');
  15. if (empty($channelId)){
  16. throw new ApiException('渠道id不为空');
  17. }
  18. $data = CommonService::getSetData($channelId);
  19. if (empty(Session::get('wxId'))){
  20. Session::set('visitorId','');
  21. header("Location:".CommonService::getAuthUrl($channelId));
  22. die();
  23. }
  24. $visitorId = Session::get($visitorId);
  25. if(empty($visitorId)){
  26. Session::set('visitorId', $visitorId);
  27. }
  28. //增加客户自己的验证逻辑,例如登录,关注,付费,填手机号等
  29. $key = md5($visitorId.$data['channel_auth_code']);
  30. if(strpos($notifyUrl,'?') !== false){//url参数处理,将key加到url参数中
  31. $returnUrl = $notifyUrl."&key=".$key."&expire=3600";
  32. }else{
  33. $returnUrl = $notifyUrl."?key=".$key."&expire=3600";
  34. }
  35. header("Location:".$returnUrl);//跳转到直播观看页
  36. // redirect($returnUrl);
  37. }
  38. }