SmmAddAccount.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Distributor\Forms;
  3. use App\Distributor\Repositories\DistProductCategory;
  4. use App\Distributor\Repositories\RpcAlbum;
  5. use App\Libraries\CommonHelper;
  6. use App\Models\DistProduct;
  7. use App\Models\DistProductImage;
  8. use App\Services\SmmService;
  9. use Dcat\Admin\Widgets\Form;
  10. class SmmAddAccount extends Form
  11. {
  12. public function handle(array $input)
  13. {
  14. // 处理表单提交逻辑
  15. $mediaName = $input['media_name'];
  16. if ($mediaName) {
  17. //跳转到媒体受权页面
  18. $ssmService = new SmmService($mediaName);
  19. $result = $ssmService->login();
  20. if ($result['status']) {
  21. // 返回 JS 代码触发新窗口打开
  22. $url = $result['data']['url'];
  23. return $this->response()->script(
  24. "window.open('{$url}', '_blank')"
  25. );
  26. }
  27. return $this
  28. ->response()
  29. ->error('获取授权失败,请检查媒体名称是否正确!');
  30. } else {
  31. return $this
  32. ->response()
  33. ->error('媒体名称不能为空');
  34. }
  35. }
  36. /**
  37. * Build a form here.
  38. */
  39. public function form()
  40. {
  41. // 设置隐藏表单,传递用户id
  42. $this->select('media_name')
  43. ->options(config('dictionary.media_list'))
  44. ->required();
  45. }
  46. /**
  47. * The data of the form.
  48. *
  49. * @return array
  50. */
  51. public function default()
  52. {
  53. return [];
  54. }
  55. }