Commit e1f2d441 by YG8999

短信平台接口更换

parent db25fb7f
package share.web.controller.system;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import share.system.domain.vo.SmsDownResultVo;
import share.system.service.SmsService;
import java.util.List;
import java.util.Map;
/**
* @className: share.web.controller.system.OtherCallbackController
* @description: 其他平台回调、回执、推送
* @author: lwj
* @create: 2024-06-04 15:47
*/
@Slf4j
@RestController
@RequestMapping("/admin/callback")
@Api(tags = "其他回调推送")
public class OtherCallbackController {
@Autowired
private SmsService smsService;
/**
* 短信发送下行回执推送
*/
@ApiOperation(value = "短信发送下行回执推送")
@RequestMapping(value = "/sms/downResult", method = RequestMethod.POST)
public String downResult(@RequestBody List<SmsDownResultVo> data, @RequestHeader Map<String, String> headers) {
String tKey = headers.get("zt-tkey");
String password = headers.get("zt-password");
System.out.println("短信发送下行回执推送 request ===> " + JSONUtil.toJsonStr(data));
System.out.println("短信发送下行回执推送 request ===> " + tKey);
System.out.println("短信发送下行回执推送 request ===> " + password);
String response = smsService.updateDownResult(tKey, password, data);
return response;
}
}
...@@ -4,14 +4,11 @@ package share.common.constant; ...@@ -4,14 +4,11 @@ package share.common.constant;
*/ */
public class SmsConts { public class SmsConts {
public final static String BASE_URL = "http://sms.xiaoyantong.com/sms";
public final static String USERNAME = "332450";
public final static String PASSWORD = "ML4pI31j";
/** /**
* 接口返回状态:成功 * 接口返回状态:成功
*/ */
public final static Integer SUCCESS_CODE = 0; public final static Integer SUCCESS_CODE = 200;
/** /**
* 查询短信模板接口 * 查询短信模板接口
......
...@@ -10,38 +10,56 @@ import cn.hutool.core.util.StrUtil; ...@@ -10,38 +10,56 @@ import cn.hutool.core.util.StrUtil;
*/ */
public enum SmsStatusEnum { public enum SmsStatusEnum {
SMS_STATUS_0(0, "成功"), // SMS_STATUS_0(0, "成功"),
SMS_STATUS_1(1, "帐号名为空"), // SMS_STATUS_1(1, "帐号名为空"),
SMS_STATUS_2(2, "帐号名或密码鉴权错误"), // SMS_STATUS_2(2, "帐号名或密码鉴权错误"),
SMS_STATUS_3(3, "帐号已被锁定"), // SMS_STATUS_3(3, "帐号已被锁定"),
SMS_STATUS_4(4, "此帐号业务未开通"), // SMS_STATUS_4(4, "此帐号业务未开通"),
SMS_STATUS_5(5, "帐号余额不足"), // SMS_STATUS_5(5, "帐号余额不足"),
SMS_STATUS_6(6, "缺少发送号码"), // SMS_STATUS_6(6, "缺少发送号码"),
SMS_STATUS_7(7, "超过最大发送号码数"), // SMS_STATUS_7(7, "超过最大发送号码数"),
SMS_STATUS_8(8, "发送消息内容为空"), // SMS_STATUS_8(8, "发送消息内容为空"),
SMS_STATUS_9(9, "无效的RCS模板ID"), // SMS_STATUS_9(9, "无效的RCS模板ID"),
SMS_STATUS_10(10, "非法的IP地址,提交来源IP地址与帐号绑定IP不一致"), // SMS_STATUS_10(10, "非法的IP地址,提交来源IP地址与帐号绑定IP不一致"),
SMS_STATUS_11(11, "24小时发送时间段限制"), // SMS_STATUS_11(11, "24小时发送时间段限制"),
SMS_STATUS_12(12, "定时发送时间错误或超过15天"), // SMS_STATUS_12(12, "定时发送时间错误或超过15天"),
SMS_STATUS_13(13, "请求过于频繁,每次获取数据最小间隔为30秒"), // SMS_STATUS_13(13, "请求过于频繁,每次获取数据最小间隔为30秒"),
SMS_STATUS_14(14, "错误的用户扩展码"), // SMS_STATUS_14(14, "错误的用户扩展码"),
SMS_STATUS_16(16, "时间戳差异过大,与系统时间误差不得超过5分钟"), // SMS_STATUS_16(16, "时间戳差异过大,与系统时间误差不得超过5分钟"),
SMS_STATUS_18(18, "帐号未进行实名认证"), // SMS_STATUS_18(18, "帐号未进行实名认证"),
SMS_STATUS_19(19, "帐号未开放回执状态"), // SMS_STATUS_19(19, "帐号未开放回执状态"),
SMS_STATUS_22(22, "缺少必填参数"), // SMS_STATUS_22(22, "缺少必填参数"),
SMS_STATUS_23(23, "用户帐号名重复"), // SMS_STATUS_23(23, "用户帐号名重复"),
SMS_STATUS_24(24, "用户无签名限制"), // SMS_STATUS_24(24, "用户无签名限制"),
SMS_STATUS_25(25, "签名需要包含【】符"), // SMS_STATUS_25(25, "签名需要包含【】符"),
SMS_STATUS_50(50, "缺少模板标题"), // SMS_STATUS_50(50, "缺少模板标题"),
SMS_STATUS_51(51, "缺少模板内容"), // SMS_STATUS_51(51, "缺少模板内容"),
SMS_STATUS_52(52, "模板内容不全"), // SMS_STATUS_52(52, "模板内容不全"),
SMS_STATUS_53(53, "不支持的模板帧类型"), // SMS_STATUS_53(53, "不支持的模板帧类型"),
SMS_STATUS_54(54, "不支持的文件类型"), // SMS_STATUS_54(54, "不支持的文件类型"),
SMS_STATUS_97(97, "此链接不支持GET请求"), // SMS_STATUS_97(97, "此链接不支持GET请求"),
SMS_STATUS_98(98, "HTTP Content-Type错误, 请设置Content-Type: application/json"), // SMS_STATUS_98(98, "HTTP Content-Type错误, 请设置Content-Type: application/json"),
SMS_STATUS_99(99, "错误的请求JSON字符串"), // SMS_STATUS_99(99, "错误的请求JSON字符串"),
SMS_STATUS_500(500, "系统异常,请联系管理员"), // SMS_STATUS_500(500, "系统异常,请联系管理员"),
SMS_STATUS_200(200, "提交成功"),
SMS_STATUS_4001(4001, "用户名错误"),
SMS_STATUS_4002(4002, "密码不能为空"),
SMS_STATUS_4003(4003, "短信内容不能为空"),
SMS_STATUS_4004(4004, "手机号码错误"),
SMS_STATUS_4006(4006, "IP鉴权错误"),
SMS_STATUS_4007(4007, "用户禁用"),
SMS_STATUS_4008(4008, "tKey错误"),
SMS_STATUS_4009(4009, "密码错误"),
SMS_STATUS_4010(4010, "短信内容超过1000个字符"),
SMS_STATUS_4011(4011, "请求错误"),
SMS_STATUS_4013(4013, "定时时间错误"),
SMS_STATUS_4015(4015, "扩展号错误"),
SMS_STATUS_4019(4019, "用户类型错误"),
SMS_STATUS_4026(4026, "手机号码数最大2000个"),
SMS_STATUS_4029(4029, "请使用post请求"),
SMS_STATUS_4030(4030, "Content-Type请使用application/json"),
SMS_STATUS_9998(9998, "JSON解析错误"),
SMS_STATUS_9999(9999, "非法请求"),
; ;
private Integer code; private Integer code;
......
...@@ -53,10 +53,6 @@ public class SmsUtil { ...@@ -53,10 +53,6 @@ public class SmsUtil {
return result; return result;
} }
public String sign(long timestamp) {
return SecureUtil.md5(SmsConts.USERNAME + timestamp + SecureUtil.md5(SmsConts.PASSWORD));
}
/** /**
* 短信平台密码加密 * 短信平台密码加密
* @param password * @param password
...@@ -98,32 +94,31 @@ public class SmsUtil { ...@@ -98,32 +94,31 @@ public class SmsUtil {
// param.put("extno", "10690"); // param.put("extno", "10690");
//// param.put("atTime", ""); //// param.put("atTime", "");
String smsContent = StrUtil.concat(true, "【凑角】", content); String smsContent = StrUtil.concat(true,
Long timestamp = DateUtil.date().getTime(); "【凑角】", "提醒您:凑角【人信汇店】(999房),已被预订!请确认房间卫生情况,保证客户体验!");
JSONObject param = JSONUtil.createObj(); Long timestamp = DateUtil.date().getTime() / 1000;
param.put("userName", "799046"); JSONObject param = JSONUtil.createObj();
param.put("sign",SecureUtil.md5("799046" + timestamp + SecureUtil.md5("mTPLoCadtv2V"))); param.put("username", "yxkjhy");
param.put("timestamp", timestamp); param.put("password", SecureUtil.md5(SecureUtil.md5(")@nhctX7") + timestamp));
// 短信发送集合messageList param.put("tKey", timestamp);
JSONObject sendParam = JSONUtil.createObj();
sendParam.put("phone", "18062577819"); param.put("mobile", "18062577819,18062677049");
sendParam.put("content", smsContent); param.put("content", smsContent);
JSONArray array = JSONUtil.createArray(); param.put("time", DateUtil.now());
array.add(sendParam); param.put("ext", "9999");
param.put("messageList", array);
System.out.println(JSONUtil.toJsonStr(param));
System.out.println(JSONUtil.toJsonStr(param)); HttpHeaders headers = new HttpHeaders();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
headers.setContentType(MediaType.APPLICATION_JSON_UTF8); headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers);
HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers); RestTemplate restTemplate = new RestTemplate();
RestTemplate restTemplate = new RestTemplate(); cn.hutool.json.JSONObject body = restTemplate.postForEntity("https://api-shss.zthysms.com/v2/sendSms", requestEntity, cn.hutool.json.JSONObject.class).getBody();
cn.hutool.json.JSONObject body = restTemplate.postForEntity("http://43.137.43.203:8001/sms/api/sendMessageOne", requestEntity, cn.hutool.json.JSONObject.class).getBody(); System.out.println("结果:" + JSONUtil.toJsonStr(body));
System.out.println(JSONUtil.toJsonStr(body));
} }
......
...@@ -57,6 +57,21 @@ public class SmsLog extends BaseEntity ...@@ -57,6 +57,21 @@ public class SmsLog extends BaseEntity
@Excel(name = "返回内容") @Excel(name = "返回内容")
private String resultParam; private String resultParam;
/** 短信下行结果(短信平台发送用户是否成功) */
@Excel(name = "短信下行结果")
private String downResult;
/** 短信下行结果描述 */
@Excel(name = "短信下行结果描述")
private String downDesc;
/** 短信下行回执参数 */
@Excel(name = "短信下行回执参数")
private String downParam;
/** 短信平台消息ID */
@Excel(name = "短信平台消息ID")
private String msgId;
@Override @Override
public String toString() { public String toString() {
......
package share.system.domain.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @className: share.system.domain.vo.SmsDownResult
* @description: 短信发送下行回执推送参数
* @author: lwj
* @create: 2024-06-04 16:15
*/
@Data
public class SmsDownResultVo implements Serializable {
private String msgId; // 消息ID
private String mobile; // 手机号
private String reportTime; // 回复时间
private String code; // 状态代码
private String msg; // 状态代码描述
private String extend; // 自定义信息
private Integer pkTotal; // 短信长度
private Integer pkNumber; // 短信回执序号,从1开始
private String username; // 用户名
}
...@@ -59,4 +59,6 @@ public interface SmsLogMapper extends BaseMapper<SmsLog> ...@@ -59,4 +59,6 @@ public interface SmsLogMapper extends BaseMapper<SmsLog>
* @return 结果 * @return 结果
*/ */
public int deleteSmsLogByIds(Long[] ids); public int deleteSmsLogByIds(Long[] ids);
int updateSmsLogByMsgId(SmsLog smsLog);
} }
...@@ -59,4 +59,6 @@ public interface SmsLogService extends IService<SmsLog> ...@@ -59,4 +59,6 @@ public interface SmsLogService extends IService<SmsLog>
* @return 结果 * @return 结果
*/ */
public int deleteSmsLogById(Long id); public int deleteSmsLogById(Long id);
int updateSmsLogByMsgId(SmsLog smsLog);
} }
...@@ -3,6 +3,7 @@ package share.system.service; ...@@ -3,6 +3,7 @@ package share.system.service;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import share.system.domain.*; import share.system.domain.*;
import share.system.domain.vo.SmsDownResultVo;
import java.util.List; import java.util.List;
...@@ -76,5 +77,13 @@ public interface SmsService { ...@@ -76,5 +77,13 @@ public interface SmsService {
*/ */
boolean sendSmsOrderPredetermine(List<String> phones, SOrder order, SStore store, SRoom room); boolean sendSmsOrderPredetermine(List<String> phones, SOrder order, SStore store, SRoom room);
/**
* 短信发送下行回执推送
* @param tKey 东八区当前时间戳,精确到秒
* @param password 接口密码采用32位小写MD5二次加密
* @param data 参数
* @return SUCCESS
*/
String updateDownResult(String tKey, String password, List<SmsDownResultVo> data);
} }
...@@ -94,4 +94,10 @@ public class SmsLogServiceImpl extends ServiceImpl<SmsLogMapper, SmsLog> impleme ...@@ -94,4 +94,10 @@ public class SmsLogServiceImpl extends ServiceImpl<SmsLogMapper, SmsLog> impleme
{ {
return smsLogMapper.deleteSmsLogById(id); return smsLogMapper.deleteSmsLogById(id);
} }
@Override
public int updateSmsLogByMsgId(SmsLog smsLog) {
smsLog.setUpdateTime(DateUtils.getNowDate());
return smsLogMapper.updateSmsLogByMsgId(smsLog);
}
} }
...@@ -20,10 +20,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -20,10 +20,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<result property="result" column="result" /> <result property="result" column="result" />
<result property="resultParam" column="result_param" /> <result property="resultParam" column="result_param" />
<result property="msgId" column="msg_id" />
<result property="downResult" column="down_result" />
<result property="downDesc" column="down_desc" />
<result property="downParam" column="down_param" />
</resultMap> </resultMap>
<sql id="selectSmsLogVo"> <sql id="selectSmsLogVo">
select id, store_id, room_id, phone, template_id, signature, content, sms_type, create_by, create_time, update_by, update_time, remark, result, result_param from s_sms_log select id, store_id, room_id, phone, template_id, signature, content, sms_type, create_by, create_time,
update_by, update_time, remark, result, result_param, down_result, down_desc,down_param,msg_id
from s_sms_log
</sql> </sql>
<select id="selectSmsLogList" parameterType="SmsLog" resultMap="SmsLogResult"> <select id="selectSmsLogList" parameterType="SmsLog" resultMap="SmsLogResult">
...@@ -64,6 +71,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -64,6 +71,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
<if test="result != null">result,</if> <if test="result != null">result,</if>
<if test="resultParam != null">result_param,</if> <if test="resultParam != null">result_param,</if>
<if test="msgId != null">msg_id,</if>
<if test="downResult != null">down_result,</if>
<if test="downDesc != null">down_desc,</if>
<if test="downParam != null">down_param,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="storeId != null">#{storeId},</if> <if test="storeId != null">#{storeId},</if>
...@@ -80,6 +91,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -80,6 +91,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
<if test="result != null">#{result},</if> <if test="result != null">#{result},</if>
<if test="resultParam != null">#{resultParam},</if> <if test="resultParam != null">#{resultParam},</if>
<if test="msgId != null">#{msgId},</if>
<if test="downResult != null">#{downResult},</if>
<if test="downDesc != null">#{downDesc},</if>
<if test="downParam != null">#{downParam},</if>
</trim> </trim>
</insert> </insert>
...@@ -100,6 +115,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -100,6 +115,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="result != null">result = #{result},</if> <if test="result != null">result = #{result},</if>
<if test="resultParam != null">result_param = #{resultParam},</if> <if test="resultParam != null">result_param = #{resultParam},</if>
<if test="msgId != null">msg_id = #{msgId},</if>
<if test="downResult != null">down_result = #{downResult},</if>
<if test="downDesc != null">down_desc = #{downDesc},</if>
<if test="downParam != null">down_param = #{downParam},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
...@@ -114,4 +133,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -114,4 +133,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id} #{id}
</foreach> </foreach>
</delete> </delete>
<update id="updateSmsLogByMsgId" parameterType="SmsLog">
update s_sms_log
<trim prefix="SET" suffixOverrides=",">
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="downResult != null">down_result = #{downResult},</if>
<if test="downDesc != null">down_desc = #{downDesc},</if>
<if test="downParam != null">down_param = #{downParam},</if>
</trim>
where msg_id = #{msgId}
</update>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment