get_business_info_logic.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package whatsapp
  2. import (
  3. "context"
  4. "wechat-api/hook/aliyun"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type GetBusinessInfoLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewGetBusinessInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBusinessInfoLogic {
  15. return &GetBusinessInfoLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx}
  19. }
  20. func (l *GetBusinessInfoLogic) GetBusinessInfo(req *types.GetBusinessReq) (*types.GetBusinessResp, error) {
  21. resp := types.GetBusinessResp{}
  22. result, err := aliyun.GetCamsBusiness(*req.Phone, *req.WaId)
  23. l.Logger.Infof("result=%v err=%v \n", result, err)
  24. if err != nil {
  25. resp.Code = 1
  26. resp.Msg = err.Error()
  27. } else {
  28. if result.Body.Data != nil {
  29. if result.Body.Data.About != nil {
  30. resp.Data.About = *result.Body.Data.About
  31. }
  32. if result.Body.Data.Address != nil {
  33. resp.Data.Address = *result.Body.Data.Address
  34. }
  35. if result.Body.Data.Description != nil {
  36. resp.Data.Description = *result.Body.Data.Description
  37. }
  38. if result.Body.Data.Email != nil {
  39. resp.Data.Email = *result.Body.Data.Email
  40. }
  41. if result.Body.Data.Vertical != nil {
  42. resp.Data.Vertical = *result.Body.Data.Vertical
  43. }
  44. if result.Body.Data.ProfilePictureUrl != nil {
  45. resp.Data.ProfilePictureUrl = *result.Body.Data.ProfilePictureUrl
  46. }
  47. if result.Body.Data.Websites != nil {
  48. websites := make([]string, 0)
  49. for _, v := range result.Body.Data.Websites {
  50. websites = append(websites, *v)
  51. }
  52. resp.Data.Websites = websites
  53. }
  54. }
  55. }
  56. return &resp, nil
  57. }