|
|
@@ -3,8 +3,12 @@ package com.fs.common.service.impl;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.fs.common.config.SmsConfig;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.domain.SendSmsByMY;
|
|
|
+import com.fs.common.domain.SendSmsReturn;
|
|
|
import com.fs.common.param.SmsSendBatchParam;
|
|
|
import com.fs.common.param.SmsSendOrderBatchParam;
|
|
|
import com.fs.common.param.SmsSendParam;
|
|
|
@@ -20,6 +24,9 @@ import com.fs.crm.domain.CrmCustomer;
|
|
|
import com.fs.crm.service.ICrmCustomerService;
|
|
|
import com.fs.store.domain.FsStoreOrder;
|
|
|
import com.fs.store.service.IFsStoreOrderService;
|
|
|
+import com.fs.system.config.FsSmsConfig;
|
|
|
+import com.fs.system.domain.SysConfig;
|
|
|
+import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.tencentcloudapi.common.Credential;
|
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
@@ -28,18 +35,29 @@ import com.tencentcloudapi.sms.v20190711.SmsClient;
|
|
|
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
|
|
|
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
|
|
|
import lombok.Synchronized;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class SmsServiceImpl implements ISmsService
|
|
|
{
|
|
|
@@ -69,6 +87,8 @@ public class SmsServiceImpl implements ISmsService
|
|
|
|
|
|
@Autowired
|
|
|
private ICompanyUserService companyUserService;
|
|
|
+ @Autowired
|
|
|
+ private SysConfigMapper sysConfigMapper;
|
|
|
|
|
|
@Override
|
|
|
public R sendTSms(String mobile, String code) {
|
|
|
@@ -396,6 +416,130 @@ public class SmsServiceImpl implements ISmsService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R sendCaptcha(String phone, String captcha, String code) {
|
|
|
+ log.info(captcha);
|
|
|
+ CompanySmsTemp temp = smsTempService.selectCompanySmsTempByCode(code);
|
|
|
+ if (temp == null) {
|
|
|
+ return R.error("没有模板");
|
|
|
+ }
|
|
|
+ String content = temp.getContent();
|
|
|
+ if (StringUtils.isNotEmpty(captcha)) {
|
|
|
+ content = content.replace("${sms.captcha}", captcha);
|
|
|
+ }
|
|
|
+ String urls = null;
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.sms");
|
|
|
+ FsSmsConfig sms = JSON.parseObject(sysConfig.getConfigValue(), FsSmsConfig.class);
|
|
|
+ if (sms.getType().equals("rf")) {
|
|
|
+ try {
|
|
|
+ content = content.replace("${sms.sign}",sms.getRfSign());
|
|
|
+ urls = sms.getRfUrl1() + "sms?action=send&account=" + sms.getRfAccount1() + "&password=" + sms.getRfPassword1() + "&mobile=" + phone + "&content=" + URLEncoder.encode(content, "UTF-8") + "&extno=" + sms.getRfCode1() + "&rt=json";
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String post = HttpRequest.get(urls)
|
|
|
+ .execute().body();
|
|
|
+ SmsSendVO vo = JSONUtil.toBean(post, SmsSendVO.class);
|
|
|
+ if (vo.getStatus().equals(0)) {
|
|
|
+ for (SmsSendItemVO itemVO : vo.getList()) {
|
|
|
+ if (itemVO.getResult().equals("0")) {
|
|
|
+ CompanySmsLogs logs = new CompanySmsLogs();
|
|
|
+ logs.setContent(content);
|
|
|
+ logs.setTempCode(temp.getTempCode());
|
|
|
+ logs.setTempId(temp.getTempId());
|
|
|
+ logs.setPhone(phone);
|
|
|
+ logs.setSendTime(new Date());
|
|
|
+ logs.setStatus(0);
|
|
|
+ logs.setType(sms.getType());
|
|
|
+ logs.setMid(itemVO.getMid());
|
|
|
+ Integer counts = logs.getContent().length() / 67;
|
|
|
+ if (logs.getContent().length() % 67 > 0) {
|
|
|
+ counts = counts + 1;
|
|
|
+ }
|
|
|
+ if (counts == 0) {
|
|
|
+ counts = 1;
|
|
|
+ }
|
|
|
+ logs.setNumber(counts);
|
|
|
+ smsLogsService.insertCompanySmsLogs(logs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (sms.getType().equals("dh")) {
|
|
|
+ SendSmsReturn sendSmsReturn = null;
|
|
|
+ content = content.replace("${sms.sign}",sms.getDhSign());
|
|
|
+ sendSmsReturn = this.sendSms(sms.getDhAccount1(), sms.getDhPassword1(), content, phone);
|
|
|
+ if (sendSmsReturn != null) {
|
|
|
+ if (sendSmsReturn.getResult() != null && sendSmsReturn.getResult().equals("0")) {
|
|
|
+ CompanySmsLogs logs = new CompanySmsLogs();
|
|
|
+ logs.setContent(content);
|
|
|
+ logs.setTempCode(temp.getTempCode());
|
|
|
+ logs.setTempId(temp.getTempId());
|
|
|
+ logs.setPhone(phone);
|
|
|
+ logs.setSendTime(new Date());
|
|
|
+ logs.setStatus(0);
|
|
|
+ logs.setType(sms.getType());
|
|
|
+ logs.setMid(sendSmsReturn.getMsgid());
|
|
|
+ Integer counts = logs.getContent().length() / 67;
|
|
|
+ if (logs.getContent().length() % 67 > 0) {
|
|
|
+ counts = counts + 1;
|
|
|
+ }
|
|
|
+ if (counts == 0) {
|
|
|
+ counts = 1;
|
|
|
+ }
|
|
|
+ logs.setNumber(counts);
|
|
|
+ smsLogsService.insertCompanySmsLogs(logs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ private SendSmsReturn sendSms(String account, String password, String content, String phone) {
|
|
|
+ SendSmsByMY sendSmsByMY = new SendSmsByMY();
|
|
|
+
|
|
|
+ sendSmsByMY.setAccount(account);
|
|
|
+ sendSmsByMY.setPassword(password);
|
|
|
+ sendSmsByMY.setContent(content);
|
|
|
+ sendSmsByMY.setMobile(phone);
|
|
|
+ sendSmsByMY.setRt("json");
|
|
|
+ sendSmsByMY.setAction("send");
|
|
|
+ sendSmsByMY.setExtno("10690");
|
|
|
+ String sendReturn = sendHttp(SmsConfig.smsSubmit, sendSmsByMY);
|
|
|
+ SendSmsReturn sendSmsReturn = JSON.parseObject(sendReturn, SendSmsReturn.class);
|
|
|
+ log.info("数据:{}", sendSmsReturn);
|
|
|
+ return sendSmsReturn;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String sendHttp(String url,Object o){
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ String responseText="";
|
|
|
+ try {
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ httpPost.addHeader("Content-Type", "application/json");
|
|
|
+
|
|
|
+ String jsonString = JSON.toJSONString(o);
|
|
|
+ StringEntity stringEntity = new StringEntity(jsonString, StandardCharsets.UTF_8);
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
+
|
|
|
+ if (entity != null) {
|
|
|
+ responseText = EntityUtils.toString(entity, "UTF-8");
|
|
|
+ }
|
|
|
+ response.close();
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ httpClient.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return responseText;
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
private IFsStoreOrderService orderService;
|
|
|
|