User.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/5 17:15
  5. */
  6. namespace app\index\controller;
  7. use app\common\service\CommonService;
  8. use app\index\BaseController;
  9. use app\index\exception\ApiException;
  10. use app\index\model\UserModel;
  11. use app\index\model\VisitorModel;
  12. use think\facade\Cache;
  13. use think\facade\Session;
  14. class User extends BaseController {
  15. public function login() {
  16. $channelId = input('channelId');
  17. if (empty($channelId)){
  18. throw new ApiException('渠道id不为空');
  19. }
  20. file_put_contents('log', date('Y-m-d H:i:s').'-'.json_encode(input()).PHP_EOL, FILE_APPEND);
  21. // if (empty(input('unionid'))){
  22. // throw new ApiException('unionid不为空');
  23. // }
  24. $params = [
  25. 'id' => $channelId,
  26. 'userid' => input('unionid'),
  27. 'name' => input('nickName'),
  28. 'avatar' => input('avatar'),
  29. 'key' => md5(input('unionid').CommonService::getSetData($channelId)['channel_auth_code'])
  30. ];
  31. Session::set('wxId',input('unionid'));
  32. (new UserModel())->insertGetId([
  33. 'channel_id' => $channelId,
  34. 'unionid' => input('unionid'),
  35. 'name' => input('nickName'),
  36. 'avatar' => input('avatar'),
  37. 'key' => $params['key'],
  38. ]);
  39. header('Location:http://webcasting.bizconfstreaming.com/activity.php?a=userAssign&'.http_build_query($params));
  40. }
  41. public function clearSession() {
  42. // var_dump($_SERVER);
  43. Session::clear();
  44. // var_dump($_SERVER);
  45. }
  46. }