SmmAddAccount.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Distributor\Actions;
  3. use App\Distributor\Forms\ImportProduct;
  4. use App\Services\SmmService;
  5. use Dcat\Admin\Grid\RowAction;
  6. use Dcat\Admin\Grid\Tools\AbstractTool;
  7. use Dcat\Admin\Widgets\Modal;
  8. use App\Distributor\Forms\SmmAddAccount as SmmAddAccountForm;
  9. use Illuminate\Http\Request;
  10. class SmmAddAccount extends RowAction
  11. {
  12. /**
  13. * 返回字段标题
  14. *
  15. * @return string
  16. */
  17. public function title()
  18. {
  19. return admin_trans_label('add_platform_account');
  20. }
  21. /**
  22. * 处理请求
  23. *
  24. */
  25. public function handle(Request $request)
  26. {
  27. // 获取 parameters 方法传递的参数
  28. $title = $request->get('title');
  29. if ($title) {
  30. //跳转到媒体受权页面
  31. $ssmService = new SmmService($title);
  32. $result = $ssmService->login();
  33. if ($result['status']) {
  34. // 返回 JS 代码触发新窗口打开
  35. $url = $result['data']['url'];
  36. return $this->response()->script(
  37. "window.open('{$url}', '_blank')"
  38. );
  39. }
  40. return $this
  41. ->response()
  42. ->error('获取授权失败,请检查媒体名称是否正确!');
  43. } else {
  44. return $this
  45. ->response()
  46. ->error('媒体名称不能为空');
  47. }
  48. }
  49. public function parameters()
  50. {
  51. return [
  52. // 发送当前行 username 字段数据到接口
  53. 'title' => $this->row->title,
  54. ];
  55. }
  56. }