diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/SmsServiceClient.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/SmsServiceClient.java new file mode 100644 index 0000000..6df1a92 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/SmsServiceClient.java @@ -0,0 +1,85 @@ +package com.hz.pm.api.external.sms; + +import cn.hutool.core.lang.TypeReference; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hz.pm.api.external.sms.dto.SmsDto; +import com.hz.pm.api.external.sms.vo.SmsReceipt; +import com.hz.pm.api.external.sms.vo.SmsReply; +import com.hz.pm.api.external.sms.vo.SmsSendResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Component +@RequiredArgsConstructor +public class SmsServiceClient { + + /** + * 短信服务 + */ + @Value("${sms.client-url}") + private String smsUrl; + + public static final String SMS_REPLY = "/sms/reply"; + public static final String SMS_SEND = "/sms/send"; + public static final String SMS_RECEIPT = "/sms/status"; + /** + * 短信回复 + * @param result + * @return + */ + public List smsReply(String result) { + List smsReplyList; + String refreshUrl = smsUrl + SMS_REPLY; + HashMap map = new HashMap<>(); + map.put("result",result); + String responseResult = HttpUtil.post(refreshUrl, map); + JSONObject responseJson = JSON.parseObject(responseResult, JSONObject.class); + String fileData = responseJson.getString("data"); + JSONArray result1 = JSON.parseObject(fileData).getJSONArray("result"); + smsReplyList = JSONObject.parseArray(result1.toJSONString(),SmsReply.class); + return smsReplyList; + } + + /** + * 短信发送 + * @return + */ + public SmsDto smsSend(String content, List phones) { + String phonesSplit = String.join(",", phones);; + String refreshUrl = smsUrl + SMS_SEND; + Map map = new HashMap<>(); + map.put("content",content); + map.put("phones",phonesSplit); + String responseResult = HttpUtil.post(refreshUrl, JSON.toJSONString(map)); + return JSONUtil.toBean(responseResult, new TypeReference>() { + }, false); + } + + /** + * 短信回执 + * @param result + * @return + */ + public SmsReceipt smsReceipt(String result) { + SmsReceipt smsReceipt = null; + String refreshUrl = smsUrl + SMS_RECEIPT; + HashMap map = new HashMap<>(); + map.put("result",result); + String responseResult = HttpUtil.post(refreshUrl, map); + JSONObject responseJson = JSON.parseObject(responseResult, JSONObject.class); + String fileData = responseJson.getString("data"); + return JSONObject.parseObject(fileData, SmsReceipt.class); + } + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/dto/SmsDto.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/dto/SmsDto.java new file mode 100644 index 0000000..057cf35 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/dto/SmsDto.java @@ -0,0 +1,22 @@ +package com.hz.pm.api.external.sms.dto; + +import lombok.Data; + +@Data +public class SmsDto { + + /** + * 成功状态码 + */ + private static final int OK_CODE = 200; + /** + * 失败状态码(未找到资源) + */ + private static final int FAIL_CODE = 404; + + private Integer code; + + private String msg; + + private T data; +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceipt.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceipt.java new file mode 100644 index 0000000..43b25bc --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceipt.java @@ -0,0 +1,18 @@ +package com.hz.pm.api.external.sms.vo; + +import lombok.Data; + +@Data +public class SmsReceipt { +// {"result":{"successPhone":["13721760288"]},"success":true,"message":"","rows":0,"sendTime":1703835660175} + + private SmsReceiptVo result; + + private Boolean success; + + private String message; + + private Integer rows; + + private Long sendTime; +} \ No newline at end of file diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceiptVo.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceiptVo.java new file mode 100644 index 0000000..46ff2c4 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceiptVo.java @@ -0,0 +1,11 @@ +package com.hz.pm.api.external.sms.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class SmsReceiptVo { + + private List successPhone; +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReply.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReply.java new file mode 100644 index 0000000..2fa6ab3 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReply.java @@ -0,0 +1,20 @@ +package com.hz.pm.api.external.sms.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel("短信回复具体信息") +public class SmsReply { + + @ApiModelProperty("回复的内容") + private String replyContent; + + @ApiModelProperty("回复的时间") + private Long replyReplytime; + + @ApiModelProperty("回复的手机号") + private String replyMobile; + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReplyResponse.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReplyResponse.java new file mode 100644 index 0000000..045e2b0 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReplyResponse.java @@ -0,0 +1,25 @@ +package com.hz.pm.api.external.sms.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel("短信回复响应内容") +public class SmsReplyResponse { + + @ApiModelProperty("参数校验失败的错误提示") + private String error; + + @ApiModelProperty("发送失败的手机号") + private String errorPhone; + + @ApiModelProperty("回复内容") + private SmsReply result; + + @ApiModelProperty("发送时间") + private Integer sendTime; + + @ApiModelProperty("本地接口请求是否成功标识") + private Boolean success; +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendRequest.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendRequest.java new file mode 100644 index 0000000..c067d71 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendRequest.java @@ -0,0 +1,13 @@ +package com.hz.pm.api.external.sms.vo; + +import lombok.Data; + +@Data +public class SmsSendRequest { + + // 短信内容 + private String content; + + //短信 手机号,逗号拼接 + private String phones; +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendResponse.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendResponse.java new file mode 100644 index 0000000..42bfade --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendResponse.java @@ -0,0 +1,20 @@ +package com.hz.pm.api.external.sms.vo; + +import lombok.Data; + +@Data +public class SmsSendResponse { + + //发送失败的手机号 + private String errorPhone; + + //返回UUID + private String result; + + //发送时间 时间戳 + private Long sendTime; + + //本次接口请求是否成功 + private Boolean success; + +} diff --git a/hz-pm-api/src/main/resources/application-dev.yml b/hz-pm-api/src/main/resources/application-dev.yml index d8ff4c5..eaa97c0 100644 --- a/hz-pm-api/src/main/resources/application-dev.yml +++ b/hz-pm-api/src/main/resources/application-dev.yml @@ -251,3 +251,7 @@ sync-mh-unit: open: false sync-mh-user: open: false +# 短信服务 +sms: + client-url: http://10.54.38.13:8081/mh-gateway/auth-single +