1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package add_friend
- import (
- "context"
- "wechat-api/internal/logic/chat"
- "wechat-api/internal/service/addfriend"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/suyuan32/simple-admin-common/enum/errorcode"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type AddFriendByPhoneLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewAddFriendByPhoneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddFriendByPhoneLogic {
- return &AddFriendByPhoneLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- /*
- func getWeChatIds(ids any) []string {
- nids := []string{}
- switch rv := ids.(type) {
- case []string:
- nids = rv
- case string:
- nids = append(nids, rv)
- }
- return nids
- }
- */
- func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddWechatFriendLogInfo) (resp *types.BaseMsgResp, err error) {
- // todo: add your logic here and delete this line
- if req.Type != 2 {
- req.Type = 1
- }
- if len(req.WeChatIds) == 0 {
- req.WeChatIds = append(req.WeChatIds, "")
- }
- for _, wechatId := range req.WeChatIds {
- nreq := &types.AddFriendByPhoneReq{Type: req.Type, WeChatId: wechatId, Phone: req.Phone, Message: req.Message}
- //fmt.Println(typekit.PrettyPrint(nreq))
- id, err := chat.AppendWechaFriendAddLog(l.ctx, l.svcCtx, nreq)
- if err != nil {
- logx.Errorf("chat.AppendWechaFriendAddLog err : %s", err)
- continue
- }
- logx.Infof("chat.AppendWechaFriendAddLog succ,get id:%d",
- id)
- if req.Type != 1 {
- continue //企微忽略后面
- }
- ret := addfriend.NewAddWechatFriendService(l.ctx, l.svcCtx).
- FindFriendByContent(wechatId, req.Phone)
- if ret {
- logx.Infof("call addfriend.NewAddWechatFriendService.FindFriendByContent('%s','%s') maybe succ", wechatId, req.Phone)
- }
- }
- resp = &types.BaseMsgResp{
- Msg: errormsg.Success,
- Code: errorcode.OK,
- }
- return resp, nil
- }
|