|
@@ -1,21 +1,18 @@
|
|
|
package com.fs.wxcid.service.impl;
|
|
package com.fs.wxcid.service.impl;
|
|
|
|
|
|
|
|
-import com.fs.common.exception.CustomException;
|
|
|
|
|
import com.fs.wxcid.ServiceUtils;
|
|
import com.fs.wxcid.ServiceUtils;
|
|
|
-import com.fs.wxcid.dto.common.ApiResponse;
|
|
|
|
|
import com.fs.wxcid.dto.common.ApiResponseCommon;
|
|
import com.fs.wxcid.dto.common.ApiResponseCommon;
|
|
|
import com.fs.wxcid.dto.common.BaseResponse;
|
|
import com.fs.wxcid.dto.common.BaseResponse;
|
|
|
import com.fs.wxcid.dto.friend.*;
|
|
import com.fs.wxcid.dto.friend.*;
|
|
|
import com.fs.wxcid.dto.login.RequestBaseVo;
|
|
import com.fs.wxcid.dto.login.RequestBaseVo;
|
|
|
import com.fs.wxcid.service.FriendService;
|
|
import com.fs.wxcid.service.FriendService;
|
|
|
-import com.fs.wxwork.utils.WxWorkHttpUtil;
|
|
|
|
|
|
|
+import com.fs.wxcid.vo.VerifyUserVo;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 好友管理服务实现类
|
|
* 好友管理服务实现类
|
|
@@ -28,95 +25,45 @@ public class FriendServiceImpl implements FriendService {
|
|
|
private ServiceUtils serviceUtils;
|
|
private ServiceUtils serviceUtils;
|
|
|
|
|
|
|
|
/** 微信接口基础 URL */
|
|
/** 微信接口基础 URL */
|
|
|
- private static final String BASE_URL = "http://114.117.215.244:7006";
|
|
|
|
|
|
|
+ private static final String BASE_URL = "/friend/";
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public ApiResponseCommon<GetContactDetailsResponseData> getContactDetailsList(
|
|
|
|
|
- String authKey, GetContactDetailsListRequest request) {
|
|
|
|
|
-
|
|
|
|
|
- String url = BASE_URL + "/friend/GetContactDetailsList?key=" + authKey;
|
|
|
|
|
- ApiResponseCommon<GetContactDetailsResponseData> response = WxWorkHttpUtil.postWithType(
|
|
|
|
|
- url,
|
|
|
|
|
- request,
|
|
|
|
|
- new TypeReference<ApiResponseCommon<GetContactDetailsResponseData>>() {}
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- //异常处理
|
|
|
|
|
- if (response.getCode() != 200 || response.getData() == null) {
|
|
|
|
|
- String errorMsg = response.getText() != null ? response.getText() : "获取联系人详情失败";
|
|
|
|
|
- throw new CustomException("获取联系人列表失败: " + errorMsg);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return response;
|
|
|
|
|
- }
|
|
|
|
|
- @Override
|
|
|
|
|
- public ApiResponseCommon<ContactListResponse> getContactList(String authKey, GetContactListRequest request) {
|
|
|
|
|
- log.info("开始获取联系人列表");
|
|
|
|
|
-
|
|
|
|
|
- String url = BASE_URL + "/friend/GetContactList?key=" + authKey;
|
|
|
|
|
- ApiResponseCommon<ContactListResponse> response = WxWorkHttpUtil.postWithType(
|
|
|
|
|
- url,
|
|
|
|
|
- request,
|
|
|
|
|
- new TypeReference<ApiResponseCommon<ContactListResponse>>() {}
|
|
|
|
|
- );
|
|
|
|
|
- if (response.getCode() != 200 || response.getData() == null) {
|
|
|
|
|
- throw new CustomException("获取联系人失败: " + response.getText());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 安全打印日志(避免 NPE)
|
|
|
|
|
- ContactListResponse data = response.getData();
|
|
|
|
|
- if (data.getContactList() != null) {
|
|
|
|
|
- log.info("联系人id合集: {}", data.getContactList().getContactUsernameList());
|
|
|
|
|
- }
|
|
|
|
|
- return response;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public GetContactDetailsResponseData getContactDetailsList(Long accountId, List<String> wxIdList) {
|
|
|
|
|
+ GetContactDetailsListRequest request = new GetContactDetailsListRequest();
|
|
|
|
|
+ request.setUserNames(wxIdList);
|
|
|
|
|
+ ApiResponseCommon<GetContactDetailsResponseData> response = serviceUtils.sendPost(BASE_URL + "GetContactDetailsList", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<GetContactDetailsResponseData>>() {});
|
|
|
|
|
+ return response.getData();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public ApiResponseCommon<SearchContactResponse> searchContact(String authKey, SearchContactRequest request) {
|
|
|
|
|
- log.info("开始搜索联系人,authKey: {}, request: {}", authKey, request);
|
|
|
|
|
-
|
|
|
|
|
- String url = BASE_URL + "/friend/SearchContact?key=" + authKey;
|
|
|
|
|
-
|
|
|
|
|
- ApiResponseCommon<SearchContactResponse> response = WxWorkHttpUtil.postWithType(
|
|
|
|
|
- url,
|
|
|
|
|
- request,
|
|
|
|
|
- new TypeReference<ApiResponseCommon<SearchContactResponse>>() {}
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // 校验响应
|
|
|
|
|
- if (response.getCode() != 200 || response.getData() == null) {
|
|
|
|
|
- throw new CustomException("搜索联系人失败: " + response.getText());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public SearchContactResponse searchContact(Long accountId, String phone) {
|
|
|
|
|
+ SearchContactRequest request = new SearchContactRequest();
|
|
|
|
|
+ request.setFromScene(0);
|
|
|
|
|
+ request.setOpCode(2);
|
|
|
|
|
+ request.setSearchScene(1);
|
|
|
|
|
+ request.setUserName(phone);
|
|
|
|
|
+ ApiResponseCommon<SearchContactResponse> response = serviceUtils.sendPost(BASE_URL + "SearchContact", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<SearchContactResponse>>() {});
|
|
|
SearchContactResponse data = response.getData();
|
|
SearchContactResponse data = response.getData();
|
|
|
String userNameStr = data.getUserNameStr();
|
|
String userNameStr = data.getUserNameStr();
|
|
|
String antispamTicket = data.getAntispamTicket();
|
|
String antispamTicket = data.getAntispamTicket();
|
|
|
-
|
|
|
|
|
log.info("搜索成功 - V3: {}, V4: {}",
|
|
log.info("搜索成功 - V3: {}, V4: {}",
|
|
|
userNameStr != null ? userNameStr : "null",
|
|
userNameStr != null ? userNameStr : "null",
|
|
|
antispamTicket != null ? antispamTicket : "null"
|
|
antispamTicket != null ? antispamTicket : "null"
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
- return response;
|
|
|
|
|
|
|
+ return data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public ApiResponseCommon<BaseResponse> verifyUser(String authKey, AgreeAddRequest request) {
|
|
|
|
|
- String url = BASE_URL + "/friend/VerifyUser?key=" + authKey;
|
|
|
|
|
-
|
|
|
|
|
- ApiResponseCommon<BaseResponse> response = WxWorkHttpUtil.postWithType(
|
|
|
|
|
- url,
|
|
|
|
|
- request,
|
|
|
|
|
- new TypeReference<ApiResponseCommon<BaseResponse>>() {}
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // 校验通用响应
|
|
|
|
|
- if (response.getCode() != 200 || response.getData() == null) {
|
|
|
|
|
- throw new CustomException("发起好友验证失败: " + response.getText());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public BaseResponse verifyUser(Long accountId, VerifyUserVo vo) {
|
|
|
|
|
+ AgreeAddRequest request = new AgreeAddRequest();
|
|
|
|
|
+ request.setChatRoomUserName(vo.getChatRoomUserName());
|
|
|
|
|
+ request.setOpCode(vo.getOpCode());
|
|
|
|
|
+ request.setScene(vo.getScene());
|
|
|
|
|
+ request.setV3(vo.getV3());
|
|
|
|
|
+ request.setV4(vo.getV4());
|
|
|
|
|
+ request.setVerifyContent(vo.getContent());
|
|
|
|
|
+ ApiResponseCommon<BaseResponse> response = serviceUtils.sendPost(BASE_URL + "VerifyUser", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<BaseResponse>>() {});
|
|
|
log.info("好友验证请求已成功发送");
|
|
log.info("好友验证请求已成功发送");
|
|
|
- return response;
|
|
|
|
|
|
|
+ return response.getData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -124,37 +71,7 @@ public class FriendServiceImpl implements FriendService {
|
|
|
GetContactListRequest request = new GetContactListRequest();
|
|
GetContactListRequest request = new GetContactListRequest();
|
|
|
request.setCurrentChatRoomContactSeq(0);
|
|
request.setCurrentChatRoomContactSeq(0);
|
|
|
request.setCurrentWxcontactSeq(0);
|
|
request.setCurrentWxcontactSeq(0);
|
|
|
- ApiResponseCommon<ContactListResponse> response = serviceUtils.sendPost("/friend/GetContactList", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<ContactListResponse>>() {});
|
|
|
|
|
|
|
+ ApiResponseCommon<ContactListResponse> response = serviceUtils.sendPost(BASE_URL + "GetContactList", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<ContactListResponse>>() {});
|
|
|
return response.getData();
|
|
return response.getData();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // ------------------ 工具方法 ------------------
|
|
|
|
|
- /**
|
|
|
|
|
- * 通用 POST 请求方法
|
|
|
|
|
- *
|
|
|
|
|
- * @param path 接口路径,如 "/friend/AgreeAdd"
|
|
|
|
|
- * @param authKey 账号唯一标识(query 参数)
|
|
|
|
|
- * @param request 请求体对象
|
|
|
|
|
- * @return 统一响应结果
|
|
|
|
|
- */
|
|
|
|
|
- private ApiResponse post(String path, String authKey, Object request) {
|
|
|
|
|
- String url = BASE_URL + path + "?key=" + authKey;
|
|
|
|
|
- return WxWorkHttpUtil.postWithType(url, request, new TypeReference<ApiResponse>() {});
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 通用 GET 请求方法(无请求体)
|
|
|
|
|
- *
|
|
|
|
|
- * @param path 接口路径
|
|
|
|
|
- * @param authKey 账号唯一标识
|
|
|
|
|
- * @return 统一响应结果
|
|
|
|
|
- */
|
|
|
|
|
- private ApiResponse get(String path, String authKey) {
|
|
|
|
|
- String url = BASE_URL + path;
|
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
|
|
- params.put("authKey", authKey);
|
|
|
|
|
- String resp = WxWorkHttpUtil.get(url, params);
|
|
|
|
|
- return com.alibaba.fastjson.JSON.parseObject(resp, ApiResponse.class);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|