Procházet zdrojové kódy

短信服务接口:短信发送 短信回复 短信回执

tags/24080901
wangrenkang před 11 měsíci
rodič
revize
66b5024db6
9 změnil soubory, kde provedl 218 přidání a 0 odebrání
  1. +85
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/SmsServiceClient.java
  2. +22
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/dto/SmsDto.java
  3. +18
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceipt.java
  4. +11
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceiptVo.java
  5. +20
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReply.java
  6. +25
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReplyResponse.java
  7. +13
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendRequest.java
  8. +20
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendResponse.java
  9. +4
    -0
      hz-pm-api/src/main/resources/application-dev.yml

+ 85
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/SmsServiceClient.java Zobrazit soubor

@@ -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> smsReply(String result) {
List<SmsReply> smsReplyList;
String refreshUrl = smsUrl + SMS_REPLY;
HashMap<String,Object> 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<SmsSendResponse> smsSend(String content, List<String> phones) {
String phonesSplit = String.join(",", phones);;
String refreshUrl = smsUrl + SMS_SEND;
Map<String,Object> 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<SmsDto<SmsSendResponse>>() {
}, false);
}

/**
* 短信回执
* @param result
* @return
*/
public SmsReceipt smsReceipt(String result) {
SmsReceipt smsReceipt = null;
String refreshUrl = smsUrl + SMS_RECEIPT;
HashMap<String,Object> 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);
}

}

+ 22
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/dto/SmsDto.java Zobrazit soubor

@@ -0,0 +1,22 @@
package com.hz.pm.api.external.sms.dto;

import lombok.Data;

@Data
public class SmsDto<T> {

/**
* 成功状态码
*/
private static final int OK_CODE = 200;
/**
* 失败状态码(未找到资源)
*/
private static final int FAIL_CODE = 404;

private Integer code;

private String msg;

private T data;
}

+ 18
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceipt.java Zobrazit soubor

@@ -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;
}

+ 11
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReceiptVo.java Zobrazit soubor

@@ -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<String> successPhone;
}

+ 20
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReply.java Zobrazit soubor

@@ -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;

}

+ 25
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsReplyResponse.java Zobrazit soubor

@@ -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;
}

+ 13
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendRequest.java Zobrazit soubor

@@ -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;
}

+ 20
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/sms/vo/SmsSendResponse.java Zobrazit soubor

@@ -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;

}

+ 4
- 0
hz-pm-api/src/main/resources/application-dev.yml Zobrazit soubor

@@ -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


Načítá se…
Zrušit
Uložit