短信
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -0,0 +1,70 @@
|
||||
package com.chinaunicom.mall.ebtp.common.sms.client;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.constant.ServiceNameConstants;
|
||||
import com.chinaunicom.mall.ebtp.common.sms.entity.SmsSendResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.sms.entity.SmsTemplate;
|
||||
import com.chinaunicom.mall.ebtp.common.sms.fallback.SmsFeignClientFallback;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@FeignClient(name = ServiceNameConstants.EXTEND_SERVICE, fallback = SmsFeignClientFallback.class)
|
||||
public interface SmsFeignClient {
|
||||
|
||||
/**
|
||||
* 返回:
|
||||
{
|
||||
"code":200,
|
||||
"message":"success",
|
||||
"success":true,
|
||||
"data":[
|
||||
{
|
||||
"id":"1180212",
|
||||
"title":"通知2",
|
||||
"content":"【中远海运】{1}",
|
||||
"status":"1",
|
||||
"type":"1",
|
||||
"dateCreated":"2022-03-27 12:34:28.0",
|
||||
"dateUpdated":"2022-03-27 12:40:13.0",
|
||||
"appendcode":"317806"
|
||||
},{
|
||||
"id":"142717",
|
||||
"title":"集团航运管理平台短信通知",
|
||||
"content":"【中远海运航标平台】{1}",
|
||||
"status":"1",
|
||||
"type":"1",
|
||||
"dateCreated":"2016-12-16 12:04:36.0",
|
||||
"dateUpdated":"2020-12-10 12:58:25.0",
|
||||
"appendcode":"319026"
|
||||
}
|
||||
]
|
||||
}
|
||||
* @param templateId 短信模板ID,查询所有时传null
|
||||
* @return 短信模板列表
|
||||
*/
|
||||
@GetMapping("/sms/queryTemplate")
|
||||
BaseResponse<List<SmsTemplate>> queryTemplate(@RequestParam(value = "templateId", required = false) String templateId);
|
||||
|
||||
/**
|
||||
返回:
|
||||
{
|
||||
"code":200,
|
||||
"message":"success",
|
||||
"success":true,
|
||||
"data": {
|
||||
"smsMessageSid": "b9fb1cc5acc3428c8d40c87428380b72",
|
||||
"dateCreated": "20250618100527"
|
||||
}
|
||||
}
|
||||
* @param mobiles 接收短信的手机号数组
|
||||
* @param templateId 短信模板ID
|
||||
* @param datas 短信模板替换参数数组
|
||||
* @return 发送短信的响应结果
|
||||
*/
|
||||
@GetMapping("/sms/send")
|
||||
BaseResponse<SmsSendResponse.TemplateSMS> sendSms(@RequestParam String[] mobiles, @RequestParam String templateId, @RequestParam String[] datas);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.chinaunicom.mall.ebtp.common.sms.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
{
|
||||
"statusCode":"000000",
|
||||
"templateSMS":{
|
||||
"smsMessageSid":"b21c72a8c9844843b8d87ecdb10304fb",
|
||||
"dateCreated":"20250620143237"
|
||||
}
|
||||
}
|
||||
*/
|
||||
@Data
|
||||
public class SmsSendResponse {
|
||||
private String statusCode;
|
||||
private TemplateSMS templateSMS;
|
||||
|
||||
|
||||
@Data
|
||||
public static class TemplateSMS {
|
||||
private String smsMessageSid;
|
||||
private String dateCreated;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.chinaunicom.mall.ebtp.common.sms.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
"id": "142717",
|
||||
"title": "集团航运管理平台短信通知",
|
||||
"content": "【中远海运航标平台】{1}",
|
||||
"status": "1",
|
||||
"type": "1",
|
||||
"dateCreated": "2016-12-16 12:04:36.0",
|
||||
"dateUpdated": "2020-12-10 12:58:25.0",
|
||||
"appendcode": "319026"
|
||||
*/
|
||||
@Data
|
||||
public class SmsTemplate {
|
||||
private String id;
|
||||
private String title;
|
||||
private String content;
|
||||
private String status;
|
||||
private String type;
|
||||
private String dateCreated;
|
||||
private String dateUpdated;
|
||||
private String appendcode;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.chinaunicom.mall.ebtp.common.sms.fallback;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.rm.entity.RmBaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.sms.client.SmsFeignClient;
|
||||
import com.chinaunicom.mall.ebtp.common.sms.entity.SmsSendResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.sms.entity.SmsTemplate;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
public class SmsFeignClientFallback implements SmsFeignClient {
|
||||
|
||||
@Override
|
||||
public BaseResponse<List<SmsTemplate>> queryTemplate(String templateId) {
|
||||
String json = " {\n" +
|
||||
" \"code\":200,\n" +
|
||||
" \"message\":\"success\",\n" +
|
||||
" \"success\":true,\n" +
|
||||
" \"data\":[\n" +
|
||||
" {\n" +
|
||||
" \"id\":\"1180212\",\n" +
|
||||
" \"title\":\"通知2\",\n" +
|
||||
" \"content\":\"【中远海运】{1}\",\n" +
|
||||
" \"status\":\"1\",\n" +
|
||||
" \"type\":\"1\",\n" +
|
||||
" \"dateCreated\":\"2022-03-27 12:34:28.0\",\n" +
|
||||
" \"dateUpdated\":\"2022-03-27 12:40:13.0\",\n" +
|
||||
" \"appendcode\":\"317806\"\n" +
|
||||
" },{\n" +
|
||||
" \"id\":\"142717\",\n" +
|
||||
" \"title\":\"集团航运管理平台短信通知\",\n" +
|
||||
" \"content\":\"【中远海运航标平台】{1}\",\n" +
|
||||
" \"status\":\"1\",\n" +
|
||||
" \"type\":\"1\",\n" +
|
||||
" \"dateCreated\":\"2016-12-16 12:04:36.0\",\n" +
|
||||
" \"dateUpdated\":\"2020-12-10 12:58:25.0\",\n" +
|
||||
" \"appendcode\":\"319026\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n";
|
||||
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(json, new TypeReference<BaseResponse<List<SmsTemplate>>>() {});
|
||||
} catch (Exception e) {
|
||||
return BaseResponse.fail(-1, "fail", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse<SmsSendResponse.TemplateSMS> sendSms(String[] mobiles, String templateId, String[] datas) {
|
||||
String json = " {\n" +
|
||||
" \"statusCode\": \"000000\",\n" +
|
||||
" \"templateSMS\": {\n" +
|
||||
" \"smsMessageSid\": \"b9fb1cc5acc3428c8d40c87428380b72\",\n" +
|
||||
" \"dateCreated\": \"20250618100527\"\n" +
|
||||
" }\n" +
|
||||
" }\n";
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(json, new TypeReference<BaseResponse<SmsSendResponse.TemplateSMS>>() {});
|
||||
} catch (Exception e) {
|
||||
return BaseResponse.fail(-1, "fail", null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user