50 changed files with 1224 additions and 244 deletions
@ -0,0 +1,68 @@
|
||||
package com.biutag.lan.controller; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import cn.hutool.crypto.digest.MD5; |
||||
import cn.hutool.http.HttpUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.biutag.config.Minio; |
||||
import com.biutag.core.AjaxResult; |
||||
import com.biutag.exception.AuthException; |
||||
import com.biutag.exception.BusinessException; |
||||
import com.biutag.lan.domain.MailSource; |
||||
import com.biutag.lan.domain.bo.MailApiV1Req; |
||||
import com.biutag.lan.service.MailSourceService; |
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import jakarta.validation.Valid; |
||||
import jakarta.validation.constraints.NotNull; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.simpleframework.xml.core.Validate; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
|
||||
@RequiredArgsConstructor |
||||
@Validate |
||||
@RequestMapping("/v1/") |
||||
@RestController |
||||
public class ApiV1Controller { |
||||
|
||||
private final MailSourceService mailSourceService; |
||||
|
||||
private final Minio minio; |
||||
|
||||
private final String key = "mailbox"; |
||||
|
||||
@PostMapping("mail") |
||||
public AjaxResult<Void> addMail(@RequestBody @Valid MailApiV1Req mail, HttpServletRequest request) { |
||||
validAuth(request); |
||||
if (mailSourceService.exists(new LambdaQueryWrapper<MailSource>().eq(MailSource::getId, mail.getId()))) { |
||||
return AjaxResult.success(); |
||||
} |
||||
if (StrUtil.isNotBlank(mail.getAttachments())) { |
||||
List<JSONObject> attachments = JSON.parseArray(mail.getAttachments()).toList(JSONObject.class); |
||||
for (JSONObject attachment : attachments) { |
||||
//minio.upload(IOUtil.base64ToStream(attachment.getString("base64")), attachment.getString("filepath"), true);
|
||||
attachment.remove("base64"); |
||||
} |
||||
mail.setAttachments(JSON.toJSONString(attachments)); |
||||
} |
||||
mailSourceService.saveBatch(Collections.singletonList(mail.toMailOuter())); |
||||
return AjaxResult.success(); |
||||
} |
||||
|
||||
private void validAuth(HttpServletRequest request) { |
||||
String authorization = request.getHeader("Authorization"); |
||||
String timestamp = request.getHeader("timestamp"); |
||||
if (StrUtil.isBlank(authorization) || StrUtil.isBlank(timestamp)) { |
||||
throw new AuthException(); |
||||
} |
||||
if (!authorization.equals(MD5.create().digestHex(key + timestamp))) { |
||||
throw new AuthException(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,18 @@
|
||||
package com.biutag.lan.controller; |
||||
|
||||
import com.biutag.lan.service.MailAppealService; |
||||
import jakarta.annotation.Resource; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
@RequestMapping("api/appeal") |
||||
@RestController |
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
public class MailAppealController { |
||||
private final MailAppealService mailAppealService; |
||||
|
||||
|
||||
} |
||||
@ -1,82 +0,0 @@
|
||||
package com.biutag.lan.crontab; |
||||
|
||||
import cn.hutool.core.date.DatePattern; |
||||
import cn.hutool.http.HttpResponse; |
||||
import cn.hutool.http.HttpUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.biutag.constants.AppConstants; |
||||
import com.biutag.lan.domain.MailSourceEtl; |
||||
import com.biutag.lan.domain.bo.MailOuter; |
||||
import com.biutag.lan.service.MailSourceEtlService; |
||||
import com.biutag.lan.service.MailSourceService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
@RequiredArgsConstructor |
||||
@Component |
||||
public class MailSourceJob { |
||||
|
||||
private final MailSourceEtlService mailSourceEtlService; |
||||
|
||||
private final MailSourceService mailSourceService; |
||||
|
||||
// @Scheduled(fixedRate = 60000)
|
||||
@Transactional(rollbackFor = Exception.class) |
||||
public void extractMailSource() { |
||||
System.out.println("extractMailSource------------"); |
||||
MailSourceEtl latestEtl = mailSourceEtlService.getLatestSuccess(); |
||||
LocalDateTime beginTime = Optional.ofNullable(latestEtl).map(MailSourceEtl::getEtlTime).orElse(LocalDateTime.of(1970, 1, 1, 0, 0, 0)); |
||||
LocalDateTime now = LocalDateTime.now(); |
||||
int current = 1; |
||||
int size = 10; |
||||
Page<MailOuter> mailOuterPage = pageMailOuterByCreateTime(current, size, |
||||
beginTime.format(DatePattern.NORM_DATETIME_FORMAT.getDateTimeFormatter()), |
||||
now.format(DatePattern.NORM_DATETIME_FORMAT.getDateTimeFormatter()), |
||||
new ArrayList<>()); |
||||
// 保存记录
|
||||
if (mailOuterPage.getTotal() > 0) { |
||||
mailSourceService.saveBatch(mailOuterPage.getRecords()); |
||||
mailSourceEtlService.save(new MailSourceEtl().setEtlTime(now).setSuccess(AppConstants.YES).setTotal(mailOuterPage.getTotal())); |
||||
} |
||||
} |
||||
|
||||
public Page<MailOuter> pageMailOuterByCreateTime(int current, int size, String beginTime, String endTime, List<MailOuter> records) { |
||||
String url = String.format("https://mailbox.biutag.com/api/api/mail?current=%s&size=%s&beginTime=%s&endTime=%s", current, size, beginTime, endTime); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.auth("chuangke") |
||||
.execute(); |
||||
if (!httpResponse.isOk()) { |
||||
|
||||
} |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
Long total = data.getLong("total"); |
||||
records.addAll(data.getList("records", MailOuter.class)); |
||||
if (total <= records.size()) { |
||||
return new Page<MailOuter>().setTotal(total).setRecords(records); |
||||
} |
||||
return pageMailOuterByCreateTime(++current, size, beginTime, endTime, records, total); |
||||
} |
||||
|
||||
public Page<MailOuter> pageMailOuterByCreateTime(int current, int size, String beginTime, String endTime, List<MailOuter> records, long total) { |
||||
String url = String.format("https://mailbox.biutag.com/api/api/mail?current=%s&size=%s&beginTime=%s&endTime=%s", current, size, beginTime, endTime); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.auth("chuangke") |
||||
.execute(); |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
records.addAll(data.getList("records", MailOuter.class)); |
||||
if (total <= records.size()) { |
||||
return new Page<MailOuter>().setTotal(total).setRecords(records); |
||||
} |
||||
return pageMailOuterByCreateTime(++current, size, beginTime, endTime, records); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,44 @@
|
||||
package com.biutag.lan.domain; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
@Accessors(chain = true) |
||||
@Setter |
||||
@Getter |
||||
public class MailAppeal { |
||||
private Integer id; |
||||
/** |
||||
* 邮件id |
||||
*/ |
||||
private String mailId; |
||||
/** |
||||
* 三级机构id |
||||
*/ |
||||
private String threeDept; |
||||
/** |
||||
* 二级机构id |
||||
*/ |
||||
private String secondDept; |
||||
/** |
||||
* 一级机构id |
||||
*/ |
||||
private String firstDept; |
||||
/** |
||||
* 申诉理由 |
||||
*/ |
||||
private String appealReason; |
||||
/** |
||||
* 驳回理由 |
||||
*/ |
||||
private String overruleReason; |
||||
/** |
||||
* 附件 |
||||
*/ |
||||
private String attachments; |
||||
/** |
||||
* 申诉状态 |
||||
*/ |
||||
private String appealStatus; |
||||
} |
||||
@ -0,0 +1,92 @@
|
||||
package com.biutag.lan.domain.bo; |
||||
|
||||
import com.biutag.lan.domain.MailSource; |
||||
import com.biutag.validator.annotation.IdCard; |
||||
import com.biutag.validator.annotation.Phone; |
||||
import jakarta.validation.constraints.NotBlank; |
||||
import jakarta.validation.constraints.NotNull; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import org.hibernate.validator.constraints.Length; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class MailApiV1Req { |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@NotBlank |
||||
private String id; |
||||
|
||||
/** |
||||
* 联系人姓名 |
||||
*/ |
||||
@NotBlank(message = "请输入联系人姓名") |
||||
private String contactName; |
||||
|
||||
/** |
||||
* 联系人性别 M / F |
||||
*/ |
||||
private String contactSex; |
||||
|
||||
/** |
||||
* 联系人身份证号 |
||||
*/ |
||||
@IdCard |
||||
private String contactIdCard; |
||||
|
||||
/** |
||||
* 联系人手机号 |
||||
*/ |
||||
@Phone |
||||
private String contactPhone; |
||||
|
||||
/** |
||||
* 案件编号 |
||||
*/ |
||||
private String caseNumber; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
@Length(min= 10, max = 300, message = "信件内容不符合规范(不少于10字,不多于300字)") |
||||
@NotBlank(message = "请输入信件内容") |
||||
private String content; |
||||
|
||||
/** |
||||
* 附件 |
||||
*/ |
||||
private String attachments; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@NotNull |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* 涉及单位ID |
||||
*/ |
||||
private Integer involvedDeptId; |
||||
|
||||
/** |
||||
* 涉及单位名称 |
||||
*/ |
||||
private String involvedDeptName; |
||||
|
||||
|
||||
private String source = MailSource.Source.MAILBOX.getValue(); |
||||
|
||||
public MailOuter toMailOuter() { |
||||
MailOuter mailOuter = new MailOuter(); |
||||
BeanUtils.copyProperties(this, mailOuter); |
||||
return mailOuter; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,8 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.MailAppeal; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
public interface MailAppealMapper extends BaseMapper<MailAppeal> { |
||||
} |
||||
@ -0,0 +1,45 @@
|
||||
package com.biutag.lan.service; |
||||
|
||||
import com.biutag.core.AjaxResult; |
||||
import com.biutag.lan.domain.MailAppeal; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class MailAppealService { |
||||
/** |
||||
* 发起申请 |
||||
* @param appeal |
||||
* @return |
||||
*/ |
||||
public AjaxResult<Void> launchAppeal(MailAppeal appeal) { |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 获取申请详情 |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
public AjaxResult<MailAppeal> getAppeal(String id) { |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 驳回申请 |
||||
* @param id |
||||
* @param overruleReason |
||||
* @return |
||||
*/ |
||||
public AjaxResult<Void> overruleAppeal(String id, String overruleReason) { |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 通过申请 |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
public AjaxResult<Void> approved(String id) { |
||||
return null; |
||||
} |
||||
} |
||||
@ -1,22 +0,0 @@
|
||||
package com.biutag.lan; |
||||
|
||||
import com.biutag.lan.crontab.MailSourceJob; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
||||
@Slf4j |
||||
@SpringBootTest |
||||
public class MailSourceJobTest { |
||||
|
||||
@Autowired |
||||
MailSourceJob mailSourceJob; |
||||
|
||||
@Test |
||||
public void testExtractMailSource() { |
||||
log.info("testExtractMailSource"); |
||||
mailSourceJob.extractMailSource(); |
||||
System.out.println("end-----------------------------------------"); |
||||
} |
||||
} |
||||
@ -0,0 +1,27 @@
|
||||
package com.biutag.outer.domain; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
@Accessors(chain = true) |
||||
@Setter |
||||
@Getter |
||||
public class MailEtl { |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
private String mailId; |
||||
|
||||
private Boolean success; |
||||
|
||||
private LocalDateTime createTime; |
||||
|
||||
private String errMsg; |
||||
|
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class ReqImsApi { |
||||
private String userName;//用户名
|
||||
private String signStr;//签名字符
|
||||
private String signTime;//提交时间
|
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.balance; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonQueryBalance { |
||||
private int state = -999;//0 正常 -1通用异常 -999程序EXCEPTION -998非JSON字符
|
||||
private String message = "服务器忙,响应超时 "; |
||||
private int balance; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.mo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonMo { |
||||
private int state = -1; |
||||
private String message = "系统超时"; |
||||
private List<SmsMo> object; |
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.mo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class ReqMo { |
||||
private String userName; |
||||
private String signStr; |
||||
private String signTime; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.mo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class SmsMo { |
||||
private String moId;//上行ID
|
||||
private String mobileNo;//上行电话号码
|
||||
private String spCode;//子码
|
||||
private String moStr;//上行内容
|
||||
private String moTime;//上行时
|
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.mt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonSmsSend { |
||||
private int state=-1; |
||||
private String message="系统超时"; |
||||
private String smsId; |
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.mt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
@Accessors(chain = true) |
||||
@Getter |
||||
@Setter |
||||
public class Mobile { |
||||
private String mobile;//接收单个手机号码
|
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
package com.biutag.outer.domain.vo.mt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.List; |
||||
@Getter |
||||
@Setter |
||||
public class SendSms { |
||||
private String userName;//用户名
|
||||
private String signStr;//签名字符
|
||||
private String signTime;//提交时间
|
||||
private String smsStr;//短信内容转BASE64
|
||||
private List<Mobile> mobileList;//发送号码列表 最多2000个
|
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.rpt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonRpt { |
||||
private int state=-1; |
||||
private String message="系统超时"; |
||||
private List<SmsRpt> object; |
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.rpt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class ReqRpt { |
||||
private String userName; |
||||
private String signStr; |
||||
private String signTime; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.rpt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class SmsRpt { |
||||
private String smsId;//任务ID
|
||||
private String mobileNo;//号码
|
||||
private int rptState;//发送状态
|
||||
private String rptNote;//回执备注
|
||||
private String rptTime;//回执时间
|
||||
} |
||||
@ -0,0 +1,82 @@
|
||||
package com.biutag.outer.job; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import cn.hutool.crypto.digest.MD5; |
||||
import cn.hutool.http.HttpResponse; |
||||
import cn.hutool.http.HttpUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.biutag.config.Minio; |
||||
import com.biutag.outer.domain.Mail; |
||||
import com.biutag.outer.domain.MailEtl; |
||||
import com.biutag.outer.mapper.MailEtlMapper; |
||||
import com.biutag.outer.mapper.MailMapper; |
||||
import lombok.Data; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
@Component |
||||
public class MailJob { |
||||
|
||||
private final MailEtlMapper mailEtlMapper; |
||||
|
||||
private final MailMapper mailMapper; |
||||
|
||||
private final Minio minio; |
||||
|
||||
@Value("${mailbox.url}") |
||||
private String mailboxUrl; |
||||
|
||||
private final String key = "mailbox"; |
||||
|
||||
// 1分钟
|
||||
@Scheduled(fixedRate = 60000) |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public void pushMailData() { |
||||
System.out.println(LocalDateTime.now()); |
||||
List<Mail> mails = mailMapper.listByMailEtl(); |
||||
for (Mail mail : mails) { |
||||
try { |
||||
if (StrUtil.isNotBlank(mail.getAttachments())) { |
||||
List<JSONObject> attachments = JSON.parseArray(mail.getAttachments()).toList(JSONObject.class); |
||||
for (JSONObject attachment : attachments) { |
||||
attachment.put("base64", minio.getBase64(attachment.getString("filepath"))); |
||||
} |
||||
mail.setAttachments(JSON.toJSONString(attachments)); |
||||
} |
||||
long timestamp = new Date().getTime(); |
||||
HttpResponse httpResponse = HttpUtil.createPost(mailboxUrl + "mail") |
||||
.header("timestamp", String.valueOf(timestamp)) |
||||
.auth(MD5.create().digestHex(key + timestamp)) |
||||
.body(JSON.toJSONString(mail)) |
||||
.execute(); |
||||
if (!httpResponse.isOk()) { |
||||
throw new RuntimeException(String.format("httpCode: %s", httpResponse.getStatus())); |
||||
} |
||||
log.info(httpResponse.body()); |
||||
JSONObject response = JSONObject.parseObject(httpResponse.body()); |
||||
if (response.getInteger("code") != 200) { |
||||
throw new RuntimeException(response.getString("msg")); |
||||
} |
||||
MailEtl mailEtl = new MailEtl().setMailId(mail.getId()).setSuccess(true).setCreateTime(LocalDateTime.now()); |
||||
mailEtlMapper.insert(mailEtl); |
||||
} catch (RuntimeException e) { |
||||
log.error("推送信件[{}]异常: {}", mail.getId(), e.getMessage(), e); |
||||
MailEtl mailEtl = new MailEtl().setMailId(mail.getId()).setSuccess(false).setCreateTime(LocalDateTime.now()).setErrMsg(e.getMessage()); |
||||
mailEtlMapper.insert(mailEtl); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outer.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outer.domain.MailEtl; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface MailEtlMapper extends BaseMapper<MailEtl> { |
||||
} |
||||
@ -1,55 +0,0 @@
|
||||
package com.biutag.outer.util; |
||||
import com.google.gson.*; |
||||
|
||||
import java.lang.reflect.Type; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class JsonUtil { |
||||
public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); |
||||
|
||||
public static String toJson(Object msg) { |
||||
return gson.toJson(msg); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json,Class<T> clazz){ |
||||
return gson.fromJson(json, clazz); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json, Type type){ |
||||
return gson.fromJson(json, type); |
||||
} |
||||
|
||||
//验证是不是JSON字符串
|
||||
public static boolean isJsonStr(String jsonInString) { |
||||
try { |
||||
if (jsonInString!=null && !jsonInString.isEmpty()){ |
||||
gson.fromJson(jsonInString, Object.class); |
||||
return true; |
||||
}else { |
||||
return false; |
||||
} |
||||
} catch(JsonSyntaxException ex) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static <T> List<T> toList(String string,Class<T> clz){ |
||||
if(string == null || string.length() < 1){ |
||||
return null; |
||||
}else { |
||||
List<T> list = new ArrayList<>(); |
||||
if(!string.startsWith("[")){ |
||||
string = "[" + string +"]"; |
||||
} |
||||
JsonArray array = new JsonParser().parse(string).getAsJsonArray(); |
||||
for(final JsonElement elem : array){ |
||||
if(elem != null){ |
||||
String mo = elem.toString().replace("\"{","{").replace("}\"","}").replace("\\", ""); |
||||
list.add(gson.fromJson(mo, clz)); |
||||
} |
||||
} |
||||
return list; |
||||
} |
||||
} |
||||
} |
||||
@ -1,30 +0,0 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import java.security.MessageDigest; |
||||
|
||||
public class Md5Util { |
||||
public static final String strToMD5(String s) { |
||||
char[] hexDigits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', |
||||
'f' }; |
||||
try { |
||||
byte[] btInput = s.getBytes("UTF-8"); |
||||
MessageDigest mdInst = MessageDigest.getInstance("MD5"); |
||||
mdInst.update(btInput); |
||||
byte[] md = mdInst.digest(); |
||||
int j = md.length; |
||||
char[] str = new char[j * 2]; |
||||
int k = 0; |
||||
|
||||
for (int i = 0; i < j; ++i) { |
||||
byte byte0 = md[i]; |
||||
str[k++] = hexDigits[byte0 >>> 4 & 15]; |
||||
str[k++] = hexDigits[byte0 & 15]; |
||||
} |
||||
|
||||
return new String(str); |
||||
} catch (Exception var10) { |
||||
var10.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import com.biutag.outer.domain.vo.mo.JsonMo; |
||||
import com.biutag.outer.domain.vo.mo.ReqMo; |
||||
import com.biutag.outer.util.sms.JsonUtil; |
||||
import com.biutag.outer.util.sms.Md5Util; |
||||
import com.biutag.outer.util.sms.SmsConf; |
||||
import com.biutag.outer.util.sms.SmsHttp; |
||||
|
||||
public class MoSync { |
||||
//拿取上行
|
||||
public static void main(String args[]) { |
||||
System.out.println("取上行启动成功"); |
||||
try { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqMo reqMo = new ReqMo(); |
||||
reqMo.setSignStr(signStr); |
||||
reqMo.setSignTime(signTime); |
||||
reqMo.setUserName(userName); |
||||
String reqJsonStr = JsonUtil.toJson(reqMo); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsMoUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
JsonMo jsonMo = JsonUtil.returnObj(resultJsonStr, JsonMo.class); |
||||
if(jsonMo!=null){ |
||||
//进入数据处理流程
|
||||
//saveMo(jsonRpt);
|
||||
} |
||||
} else { |
||||
System.out.println("取回执:"+resultJsonStr); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import com.biutag.outer.domain.vo.rpt.JsonRpt; |
||||
import com.biutag.outer.domain.vo.rpt.ReqRpt; |
||||
import com.biutag.outer.util.sms.JsonUtil; |
||||
import com.biutag.outer.util.sms.Md5Util; |
||||
import com.biutag.outer.util.sms.SmsConf; |
||||
import com.biutag.outer.util.sms.SmsHttp; |
||||
|
||||
public class RptSync { |
||||
//拿取回执
|
||||
public static void main(String args[]) { |
||||
System.out.println("取回执启动成功"); |
||||
try { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqRpt reqRpt = new ReqRpt(); |
||||
reqRpt.setSignStr(signStr); |
||||
reqRpt.setSignTime(signTime); |
||||
reqRpt.setUserName(userName); |
||||
String reqJsonStr = JsonUtil.toJson(reqRpt); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsRptUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
JsonRpt jsonRpt = JsonUtil.returnObj(resultJsonStr, JsonRpt.class); |
||||
if(jsonRpt!=null){ |
||||
//进入数据处理流程
|
||||
//saveRpt(jsonRpt);
|
||||
} |
||||
} else { |
||||
System.out.println("取回执:"+resultJsonStr); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,49 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.io.UnsupportedEncodingException; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.util.Arrays; |
||||
import java.util.Base64; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class Base64Util { |
||||
public static String encodeData(String str) { |
||||
//L.p("str-->"+str);
|
||||
byte[] b = null; |
||||
String s = null; |
||||
if (str != null && !str.trim().isEmpty()) { |
||||
b = str.getBytes(StandardCharsets.UTF_8); |
||||
if (b != null) { |
||||
s = Base64.getMimeEncoder().encodeToString(b); |
||||
} |
||||
} |
||||
return replaceBlank(s); |
||||
} |
||||
|
||||
// 解密
|
||||
public static String decodeData(String s) { |
||||
byte[] b = null; |
||||
String result = null; |
||||
if (s != null) { |
||||
try { |
||||
b = Base64.getMimeDecoder().decode(s); |
||||
result = new String(b, StandardCharsets.UTF_8); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
//去掉换行符
|
||||
public static String replaceBlank(String str) { |
||||
String dest = ""; |
||||
if (str != null) { |
||||
Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
||||
Matcher m = p.matcher(str); |
||||
dest = m.replaceAll(""); |
||||
} |
||||
return dest; |
||||
} |
||||
} |
||||
@ -0,0 +1,56 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import com.google.gson.*; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.lang.reflect.Type; |
||||
|
||||
public class JsonUtil { |
||||
public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); |
||||
|
||||
public static String toJson(Object msg) { |
||||
return gson.toJson(msg); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json, Class<T> clazz) { |
||||
return gson.fromJson(json, clazz); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json, Type type) { |
||||
return gson.fromJson(json, type); |
||||
} |
||||
|
||||
//验证是不是JSON字符串
|
||||
public static boolean isJsonStr(String jsonInString) { |
||||
try { |
||||
if (jsonInString != null && !jsonInString.isEmpty()) { |
||||
gson.fromJson(jsonInString, Object.class); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} catch (JsonSyntaxException ex) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static <T> List<T> toList(String string, Class<T> clz) { |
||||
if (string == null || string.length() < 1) { |
||||
return null; |
||||
} else { |
||||
List<T> list = new ArrayList<>(); |
||||
if (!string.startsWith("[")) { |
||||
string = "[" + string + "]"; |
||||
} |
||||
JsonArray array = new JsonParser().parse(string).getAsJsonArray(); |
||||
for (final JsonElement elem : array) { |
||||
if (elem != null) { |
||||
String mo = elem.toString().replace("\"{", "{").replace("}\"", "}").replace("\\", ""); |
||||
list.add(gson.fromJson(mo, clz)); |
||||
} |
||||
} |
||||
return list; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,30 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.security.MessageDigest; |
||||
|
||||
public class Md5Util { |
||||
public static final String strToMD5(String s) { |
||||
char[] hexDigits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', |
||||
'f' }; |
||||
try { |
||||
byte[] btInput = s.getBytes("UTF-8"); |
||||
MessageDigest mdInst = MessageDigest.getInstance("MD5"); |
||||
mdInst.update(btInput); |
||||
byte[] md = mdInst.digest(); |
||||
int j = md.length; |
||||
char[] str = new char[j * 2]; |
||||
int k = 0; |
||||
|
||||
for (int i = 0; i < j; ++i) { |
||||
byte byte0 = md[i]; |
||||
str[k++] = hexDigits[byte0 >>> 4 & 15]; |
||||
str[k++] = hexDigits[byte0 & 15]; |
||||
} |
||||
|
||||
return new String(str); |
||||
} catch (Exception var10) { |
||||
var10.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,188 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import com.biutag.outer.domain.vo.balance.JsonQueryBalance; |
||||
import com.biutag.outer.domain.vo.mo.JsonMo; |
||||
import com.biutag.outer.domain.vo.mt.JsonSmsSend; |
||||
import com.biutag.outer.domain.vo.mt.Mobile; |
||||
import com.biutag.outer.domain.vo.mt.SendSms; |
||||
import com.biutag.outer.domain.vo.rpt.JsonRpt; |
||||
import com.biutag.outer.util.ReqImsApi; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
public class PostSms { |
||||
//查询发送
|
||||
public static int queryBalanceNum() { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
int balanceNum = 0; |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqImsApi reqImsApi = new ReqImsApi(); |
||||
reqImsApi.setUserName(userName); |
||||
reqImsApi.setSignStr(signStr); |
||||
reqImsApi.setSignTime(signTime); |
||||
String reqJsonStr = JsonUtil.toJson(reqImsApi); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.queyrbalanceUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
JsonQueryBalance jonQueryBalance = JsonUtil.returnObj(resultJsonStr, JsonQueryBalance.class); |
||||
if (jonQueryBalance != null) { |
||||
balanceNum = jonQueryBalance.getBalance(); |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return balanceNum; |
||||
} |
||||
|
||||
//提交短信
|
||||
public static JsonSmsSend sendSms(List<Mobile> mobileList, String smsStr) { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
JsonSmsSend jsonSmsSend = new JsonSmsSend(); |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
if (smsStr != null && !smsStr.isEmpty()) { |
||||
if (mobileList != null && !mobileList.isEmpty()) { |
||||
if (PostSms.queryBalanceNum() >= mobileList.size()) { |
||||
SendSms sendSms = new SendSms(); |
||||
sendSms.setUserName(userName); |
||||
sendSms.setSignStr(signStr); |
||||
sendSms.setSignTime(signTime); |
||||
sendSms.setSignStr(signStr); |
||||
sendSms.setSmsStr(Base64Util.encodeData(smsStr)); |
||||
sendSms.setMobileList(mobileList); |
||||
String reqJsonStr = JsonUtil.toJson(sendSms); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsSendUrl, reqJsonStr); |
||||
log.info("smsStr: " + smsStr); |
||||
log.info("smsStr: " + sendSms.getSmsStr()); |
||||
log.info("decodeStr: " + Base64Util.decodeData(sendSms.getSmsStr())); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
jsonSmsSend = JsonUtil.returnObj(resultJsonStr, JsonSmsSend.class); |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage(resultJsonStr); |
||||
} |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage("账户余额不够"); |
||||
} |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage("发送号码不能空"); |
||||
} |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage("发送内容不能空"); |
||||
} |
||||
} catch (Exception e) { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage(e.toString()); |
||||
e.printStackTrace(); |
||||
} |
||||
return jsonSmsSend; |
||||
} |
||||
|
||||
//接收短信状态回执
|
||||
public static JsonRpt getSmsRpt() { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
JsonRpt jsonRpt = new JsonRpt(); |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqImsApi reqImsApi = new ReqImsApi(); |
||||
reqImsApi.setUserName(userName); |
||||
reqImsApi.setSignStr(signStr); |
||||
reqImsApi.setSignTime(signTime); |
||||
String reqJsonStr = JsonUtil.toJson(reqImsApi); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsRptUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
jsonRpt = JsonUtil.returnObj(resultJsonStr, JsonRpt.class); |
||||
} else { |
||||
jsonRpt.setState(-1); |
||||
jsonRpt.setMessage(resultJsonStr); |
||||
} |
||||
} catch (Exception e) { |
||||
jsonRpt.setMessage(e.toString()); |
||||
e.printStackTrace(); |
||||
} |
||||
return jsonRpt; |
||||
} |
||||
|
||||
//接收短信上行
|
||||
public static JsonMo getSmsMo() { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
String balanceUrl = SmsConf.smsMoUrl; |
||||
JsonMo jsonMo = new JsonMo(); |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqImsApi reqImsApi = new ReqImsApi(); |
||||
reqImsApi.setUserName(userName); |
||||
reqImsApi.setSignStr(signStr); |
||||
reqImsApi.setSignTime(signTime); |
||||
String reqJsonStr = JsonUtil.toJson(reqImsApi); |
||||
String resultJsonStr = SmsHttp.postJson(balanceUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
jsonMo = JsonUtil.returnObj(resultJsonStr, JsonMo.class); |
||||
} else { |
||||
jsonMo.setState(-1); |
||||
jsonMo.setMessage(resultJsonStr); |
||||
} |
||||
} catch (Exception e) { |
||||
jsonMo.setMessage(e.toString()); |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
return jsonMo; |
||||
} |
||||
|
||||
public static void main(String arg[]) throws Exception { |
||||
//测试取余额
|
||||
//L.p(""+PostSms.queryBalanceNum());
|
||||
//测试发送
|
||||
|
||||
List<Mobile> mobileList = new ArrayList<Mobile>(); |
||||
Mobile mobile = new Mobile(); |
||||
mobile.setMobile("13974908181"); |
||||
mobileList.add(mobile); |
||||
String smsStr = "验证码1234"; |
||||
JsonSmsSend jsonSmsSend = sendSms(mobileList, smsStr); |
||||
// if(jsonSmsSend!=null){
|
||||
// L.p(jsonSmsSend.getSmsId());
|
||||
// }
|
||||
//测试取回执
|
||||
|
||||
// JsonRpt jsonRpt=getSmsRpt();
|
||||
// L.p(""+jsonRpt.getMessage());
|
||||
// List<SmsRpt> rptList=jsonRpt.getObject();
|
||||
// if(rptList!=null && !rptList.isEmpty()){
|
||||
// L.p(rptList.size()+"");
|
||||
// }else{
|
||||
// L.p("123");
|
||||
// }
|
||||
|
||||
//测试取上行
|
||||
|
||||
// JsonMo jsonMo=getSmsMo();
|
||||
// List<SmsMo> moList=jsonMo.getObject();
|
||||
// System.out.println(""+jsonMo.getMessage());
|
||||
// if(moList!=null && !moList.isEmpty()){
|
||||
// System.out.println(""+moList.size());
|
||||
// }else{
|
||||
// System.out.println("123");
|
||||
// }
|
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.util.Calendar; |
||||
|
||||
public class SmsConf { |
||||
//基础地址 请参文档填写
|
||||
public static String smsSendUrl = "http://172.31.253.178:5050/ims/sms/sendSms";//发送地址
|
||||
public static String queyrbalanceUrl = "http://172.31.253.178:5050/ims/sms/queryBalance";//查询发送能力地址
|
||||
public static String smsMoUrl = "http://172.31.253.178:9090/ims/sms/queryMo";//取上行地址
|
||||
public static String smsRptUrl = "http://172.31.253.178:9090/ims/sms/queryRpt";//取回执地址
|
||||
public static String smsUserName="cxxjjjbxt";//账户名
|
||||
public static String smsPasswd="rfrlnK@98";//账号密码
|
||||
|
||||
|
||||
|
||||
public static String getSysTime() { |
||||
Calendar now = Calendar.getInstance(); |
||||
String year = Integer.toString(now.get(Calendar.YEAR)); |
||||
String mon = Integer.toString(now.get(Calendar.MONTH) + 1); |
||||
String day = Integer.toString(now.get(Calendar.DATE)); |
||||
String hour = Integer.toString(now.get(Calendar.HOUR_OF_DAY)); |
||||
String min = Integer.toString(now.get(Calendar.MINUTE)); |
||||
String sec = Integer.toString(now.get(Calendar.SECOND)); |
||||
|
||||
mon = (mon.length() == 1) ? "0" + mon : mon; |
||||
day = (day.length() == 1) ? "0" + day : day; |
||||
hour = (hour.length() == 1) ? "0" + hour : hour; |
||||
min = (min.length() == 1) ? "0" + min : min; |
||||
sec = (sec.length() == 1) ? "0" + sec : sec; |
||||
return (year + mon + day + hour + min + sec); |
||||
} |
||||
} |
||||
@ -0,0 +1,87 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.InputStreamReader; |
||||
import java.io.PrintWriter; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URL; |
||||
|
||||
public class SmsHttp { |
||||
//发送生信
|
||||
public static String postJson(String submitUrl, String json) { |
||||
URL url = null; |
||||
String postResponseStr = null; |
||||
HttpURLConnection httpURLConnection = null; |
||||
BufferedReader getResponseBytes = null; |
||||
PrintWriter printWriter = null; |
||||
StringBuilder sb = null; |
||||
try { |
||||
url = new URL(submitUrl); |
||||
httpURLConnection = (HttpURLConnection) url.openConnection(); |
||||
httpURLConnection.setRequestMethod("POST");// 提交模式
|
||||
httpURLConnection.setConnectTimeout(10000);//连接超时 单位毫秒
|
||||
httpURLConnection.setReadTimeout(60000);//读取超时 单位毫秒
|
||||
// 发送POST请求必须设置如下两行
|
||||
httpURLConnection.setDoOutput(true); |
||||
httpURLConnection.setDoInput(true); |
||||
//httpURLConnection.setRequestProperty("Accept", "application/json");
|
||||
|
||||
|
||||
httpURLConnection.setRequestProperty("Content-Type", "text/plain"); |
||||
httpURLConnection.setRequestProperty("connection", "Keep-Alive"); |
||||
httpURLConnection.setRequestProperty("Charsert", "UTF-8"); |
||||
//httpURLConnection.setRequestProperty("Content-type", "application/json; charset=utf-8");
|
||||
// 获取URLConnection对象对应的输出流
|
||||
printWriter = new PrintWriter(httpURLConnection.getOutputStream()); |
||||
printWriter.write(json); |
||||
printWriter.flush(); |
||||
//printWriter.close();
|
||||
int httpRspCode = httpURLConnection.getResponseCode(); |
||||
if (httpRspCode == HttpURLConnection.HTTP_OK) { |
||||
sb = new StringBuilder(); |
||||
// 开始获取数据
|
||||
getResponseBytes = new BufferedReader( |
||||
new InputStreamReader(httpURLConnection.getInputStream(), "utf-8")); |
||||
String line = null; |
||||
while ((line = getResponseBytes.readLine()) != null) { |
||||
sb.append(line); |
||||
} |
||||
getResponseBytes.close(); |
||||
postResponseStr = sb.toString(); |
||||
} else { |
||||
postResponseStr = "ERR:" + httpRspCode; |
||||
} |
||||
} catch (Exception e) { |
||||
postResponseStr = "ERR:" + e.getMessage(); |
||||
e.printStackTrace(); |
||||
} finally { |
||||
if (httpURLConnection != null) { |
||||
try { |
||||
httpURLConnection.disconnect(); |
||||
} catch (Exception eee) { |
||||
} |
||||
} |
||||
if (getResponseBytes != null) { |
||||
try { |
||||
getResponseBytes.close(); |
||||
} catch (Exception ee) { |
||||
} |
||||
} |
||||
if (printWriter != null) { |
||||
try { |
||||
printWriter.close(); |
||||
} catch (Exception eeee) { |
||||
} |
||||
} |
||||
if (sb != null) { |
||||
try { |
||||
sb = null; |
||||
} catch (Exception eeeee) { |
||||
} |
||||
} |
||||
} |
||||
System.out.print("sms sends post-->[" + postResponseStr + "] json:" + json); |
||||
return postResponseStr; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,19 @@
|
||||
package com.biutag.outer; |
||||
|
||||
import cn.hutool.crypto.digest.MD5; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.biutag.outer.domain.Mail; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
public class ApiTest { |
||||
|
||||
@Test |
||||
public void testAuth() { |
||||
Mail mail = new Mail(); |
||||
mail.setCreateTime(LocalDateTime.now()); |
||||
System.out.println(JSON.toJSONString(mail)); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue