delete_app_logic.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package fastgpt
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "net/http"
  8. "strconv"
  9. "wechat-api/internal/svc"
  10. "wechat-api/internal/types"
  11. )
  12. type DeleteAppLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewDeleteAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAppLogic {
  18. return &DeleteAppLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *DeleteAppLogic) DeleteApp(req *types.DeleteAppsReq) (resp *types.BaseMsgResp, err error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. organizationIdStr := strconv.FormatUint(organizationId, 10)
  26. token, err := GetToken(organizationIdStr)
  27. if err != nil {
  28. return nil, fmt.Errorf("invalid token")
  29. }
  30. AppDelete(req.Id, token)
  31. return &types.BaseMsgResp{Msg: errormsg.Success}, nil
  32. }
  33. func AppDelete(id string, token string) {
  34. url := fmt.Sprintf("https://fastgpt.gkscrm.com/api/core/app/del?appId=%s", id)
  35. // 创建一个新的请求
  36. req1, err := http.NewRequest("GET", url, nil)
  37. if err != nil {
  38. fmt.Printf("Error creating request: %v\n", err)
  39. return
  40. }
  41. // 设置请求头
  42. req1.Header.Set("Content-Type", "application/json")
  43. req1.Header.Set("Cookie", fmt.Sprintf("fastgpt_token=%s", token))
  44. // 使用 http.Client 发送请求
  45. client := &http.Client{}
  46. resp1, err := client.Do(req1)
  47. if err != nil {
  48. fmt.Printf("Error sending request: %v\n", err)
  49. return
  50. }
  51. defer resp1.Body.Close()
  52. return
  53. }