1+ /*
2+ * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package top .continew .admin .system .config .sms ;
18+
19+ import cn .hutool .json .JSONUtil ;
20+ import jakarta .annotation .Resource ;
21+ import lombok .extern .slf4j .Slf4j ;
22+ import org .dromara .sms4j .api .entity .SmsResponse ;
23+ import org .dromara .sms4j .api .proxy .CoreMethodProcessor ;
24+ import org .springframework .stereotype .Component ;
25+ import top .continew .admin .system .model .req .SmsRecordReq ;
26+ import top .continew .admin .system .service .SmsRecordService ;
27+
28+ import java .lang .reflect .Method ;
29+ import java .util .LinkedHashMap ;
30+ import java .util .List ;
31+
32+ @ Slf4j
33+ @ Component
34+ public class SmsRecordProcessor implements CoreMethodProcessor {
35+
36+ @ Resource
37+ private SmsRecordService smsRecordService ;
38+
39+ @ Override
40+ public Object [] preProcessor (Method method , Object source , Object [] param ) {
41+ return CoreMethodProcessor .super .preProcessor (method , source , param );
42+ }
43+
44+ @ Override
45+ public void sendMessagePreProcess (String phone , Object message ) {
46+ System .out .println ("发送短信前处理" + phone + message );
47+ }
48+
49+ @ Override
50+ public void sendMessageByTemplatePreProcess (String phone ,
51+ String templateId ,
52+ LinkedHashMap <String , String > messages ) {
53+ log .debug ("发送短信前处理 sendMessageByTemplatePreProcess " + phone + templateId + JSONUtil .toJsonPrettyStr (messages ));
54+ }
55+
56+ @ Override
57+ public void massTextingPreProcess (List <String > phones , String message ) {
58+ log .debug ("发送短信前处理 massTextingPreProcess " + JSONUtil .toJsonPrettyStr (phones ) + message );
59+ }
60+
61+ @ Override
62+ public void massTextingByTemplatePreProcess (List <String > phones ,
63+ String templateId ,
64+ LinkedHashMap <String , String > messages ) {
65+ log .debug ("发送短信前处理 massTextingByTemplatePreProcess " + JSONUtil .toJsonPrettyStr (phones ) + JSONUtil
66+ .toJsonPrettyStr (messages ));
67+ }
68+
69+ @ Override
70+ public Object postProcessor (SmsResponse result , Object [] param ) {
71+ SmsRecordReq record = new SmsRecordReq ();
72+ record .setConfigId (Long .parseLong (result .getConfigId ()));
73+ record .setPhone (param [0 ].toString ());
74+ record .setParams (JSONUtil .toJsonPrettyStr (param [1 ]));
75+ record .setStatus (result .isSuccess ());
76+ record .setResMsg (JSONUtil .toJsonPrettyStr (result .getData ()));
77+ smsRecordService .add (record );
78+ return CoreMethodProcessor .super .postProcessor (result , param );
79+ }
80+
81+ @ Override
82+ public void exceptionHandleProcessor (Method method ,
83+ Object source ,
84+ Object [] param ,
85+ Exception exception ) throws RuntimeException {
86+ CoreMethodProcessor .super .exceptionHandleProcessor (method , source , param , exception );
87+ }
88+ }
0 commit comments