1+ package me .chanjar .weixin .cp .api .impl ;
2+
3+ import com .google .gson .JsonObject ;
4+ import lombok .RequiredArgsConstructor ;
5+ import me .chanjar .weixin .common .error .WxErrorException ;
6+ import me .chanjar .weixin .cp .api .WxCpIntelligentRobotService ;
7+ import me .chanjar .weixin .cp .api .WxCpService ;
8+ import me .chanjar .weixin .cp .bean .intelligentrobot .*;
9+ import me .chanjar .weixin .cp .util .json .WxCpGsonBuilder ;
10+
11+ import static me .chanjar .weixin .cp .constant .WxCpApiPathConsts .IntelligentRobot .*;
12+
13+ /**
14+ * 企业微信智能机器人接口实现
15+ *
16+ * @author Binary Wang
17+ */
18+ @ RequiredArgsConstructor
19+ public class WxCpIntelligentRobotServiceImpl implements WxCpIntelligentRobotService {
20+
21+ private final WxCpService cpService ;
22+
23+ @ Override
24+ public WxCpIntelligentRobotCreateResponse createRobot (WxCpIntelligentRobotCreateRequest request ) throws WxErrorException {
25+ String responseText = this .cpService .post (CREATE_ROBOT , request .toJson ());
26+ return WxCpIntelligentRobotCreateResponse .fromJson (responseText );
27+ }
28+
29+ @ Override
30+ public void deleteRobot (String robotId ) throws WxErrorException {
31+ JsonObject jsonObject = new JsonObject ();
32+ jsonObject .addProperty ("robot_id" , robotId );
33+ this .cpService .post (DELETE_ROBOT , jsonObject .toString ());
34+ }
35+
36+ @ Override
37+ public void updateRobot (WxCpIntelligentRobotUpdateRequest request ) throws WxErrorException {
38+ this .cpService .post (UPDATE_ROBOT , request .toJson ());
39+ }
40+
41+ @ Override
42+ public WxCpIntelligentRobot getRobot (String robotId ) throws WxErrorException {
43+ JsonObject jsonObject = new JsonObject ();
44+ jsonObject .addProperty ("robot_id" , robotId );
45+ String responseText = this .cpService .post (GET_ROBOT , jsonObject .toString ());
46+ return WxCpIntelligentRobot .fromJson (responseText );
47+ }
48+
49+ @ Override
50+ public WxCpIntelligentRobotChatResponse chat (WxCpIntelligentRobotChatRequest request ) throws WxErrorException {
51+ String responseText = this .cpService .post (CHAT , request .toJson ());
52+ return WxCpIntelligentRobotChatResponse .fromJson (responseText );
53+ }
54+
55+ @ Override
56+ public void resetSession (String robotId , String userid , String sessionId ) throws WxErrorException {
57+ JsonObject jsonObject = new JsonObject ();
58+ jsonObject .addProperty ("robot_id" , robotId );
59+ jsonObject .addProperty ("userid" , userid );
60+ jsonObject .addProperty ("session_id" , sessionId );
61+ this .cpService .post (RESET_SESSION , jsonObject .toString ());
62+ }
63+
64+ }
0 commit comments