parent
e3be18710e
commit
2a5a90d4bb
@ -1,92 +0,0 @@ |
||||
package com.ruoyi.web.sms; |
||||
|
||||
import cn.hutool.crypto.digest.DigestUtil; |
||||
import cn.hutool.http.HttpUtil; |
||||
import cn.hutool.json.JSONObject; |
||||
import cn.hutool.json.JSONUtil; |
||||
import com.ruoyi.common.utils.StringUtils; |
||||
import com.ruoyi.system.domain.SmsContent; |
||||
import com.ruoyi.system.mapper.SmsContentMapper; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.PostConstruct; |
||||
import java.net.URLEncoder; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @program: feiyi |
||||
* @ClassName YueXinSmsFacade |
||||
* @description: yuexinsms短信接口 |
||||
* @author: 清风煮酒QaQ |
||||
* @create: 2024-07-24 15:21 |
||||
* @Version 1.0 |
||||
**/ |
||||
@Component |
||||
public class YueXinSmsFacade { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(YueXinSmsFacade.class); |
||||
|
||||
private static SmsContentMapper staticSmsContentMapper; |
||||
|
||||
@Autowired |
||||
private SmsContentMapper smsContentMapper; |
||||
|
||||
@PostConstruct |
||||
public void init() { |
||||
staticSmsContentMapper = smsContentMapper; |
||||
} |
||||
|
||||
private static String yueXinUrl = "http://106.14.55.160:9000/HttpSmsMt"; |
||||
private static String yueXinUser = "hbjcy"; |
||||
private static String yueXinPWD = "de0a83a6b2d0d0133cbef7fd3cf722b2"; |
||||
|
||||
public static String sendSms(String phone, String content) throws Exception { |
||||
String res = "false"; |
||||
if (StringUtils.isNotBlank(content) && StringUtils.isNotBlank(phone)) { |
||||
SmsContent sms = new SmsContent(); |
||||
Date date = new Date(); |
||||
String formatTime = new SimpleDateFormat("yyyyMMddhhmmss") |
||||
.format(date); |
||||
sms.setCreateTime(date); |
||||
Map<String, Object> param = null; |
||||
try { |
||||
param = new HashMap<>(); |
||||
// 账号(必选)
|
||||
param.put("name", yueXinUser); |
||||
//密码(必填) DigestUtil.md5Hex(testStr);
|
||||
param.put("pwd", DigestUtil.md5Hex(yueXinPWD + formatTime)); |
||||
// 手机号(必填)
|
||||
param.put("phone", phone); |
||||
// 内容
|
||||
param.put("content", URLEncoder.encode(content, "UTF-8")); |
||||
// 提交时间(必填) yyyyMMddhhmmss 须取当前时间,不能比当前时间早或晚太多
|
||||
param.put("mttime", formatTime); |
||||
// 返回数据类型(必填) 0 xml ,1json
|
||||
param.put("rpttype", 1); |
||||
} catch (Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
throw new Exception("阅信接口创建参数失败"); |
||||
} |
||||
String result = HttpUtil.post(yueXinUrl, param); |
||||
System.out.println(result); |
||||
JSONObject jsonObject = JSONUtil.parseObj(result); |
||||
sms.setMobile(phone); |
||||
sms.setSmscontent(content); |
||||
sms.setMttime(formatTime); |
||||
if (jsonObject != null) { |
||||
sms.setReqcode(jsonObject.get("ReqCode").toString()); |
||||
sms.setReqmsg(jsonObject.get("ReqMsg").toString()); |
||||
sms.setReqid(jsonObject.get("ReqId").toString()); |
||||
} |
||||
staticSmsContentMapper.insertSmsContent(sms); |
||||
res = "success"; |
||||
} |
||||
return res; |
||||
} |
||||
} |
Loading…
Reference in new issue