Commit 65786dce authored by liuyang's avatar liuyang

添加新爱康的短信配置

parent 0517b07e
package com.qkdata.biz.sms.service; package com.qkdata.biz.sms.service;
import com.alipay.api.domain.BizOrderInfo;
import com.qkdata.biz.common.BizConstants;
import com.qkdata.biz.sms.vo.SmsRequest; import com.qkdata.biz.sms.vo.SmsRequest;
import com.qkdata.biz.sms.vo.SmsResponse; import com.qkdata.biz.sms.vo.SmsResponse;
import com.qkdata.biz.sms.vo.SmsV2Condition; import com.qkdata.biz.sms.vo.SmsV2Condition;
import com.qkdata.common.base.exception.BusinessException; import com.qkdata.common.base.exception.BusinessException;
import com.qkdata.common.constants.Constants;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Collections; import java.util.Collections;
@Slf4j @Slf4j
...@@ -18,21 +25,59 @@ public class SmsService { ...@@ -18,21 +25,59 @@ public class SmsService {
@Value("${sms.api.v3}") @Value("${sms.api.v3}")
private String api; private String api;
@Value("${sms.type}")
private String smsType;
/**
* 登录验证码
*/
private String smsContent = "SMS_205630239;xak;%s;2";
/**
* 验证身份
*/
private String validateContent = "SMS_205630240;xak;%s;2";
@Autowired @Autowired
private RestTemplate restTemplate; private RestTemplate restTemplate;
public void sendSmsV3(SmsV2Condition condition) { public void sendSmsV3(SmsV2Condition condition) {
if (smsType.equals("tjxak")) {
try {
String content = "";
if (condition.getCode().equals(BizConstants.SMS_TEMPLATE_CODE)){
content = String.format(smsContent, condition.getParams().get("code"));
}else if (condition.getCode().equals(BizConstants.SMS_CHECK_USER_TEMPLATE_CODE)){
content = String.format(validateContent, condition.getParams().get("code"));
}else {
throw new BusinessException("短信模板编号不正确");
}
SmsRequest smsRequest = new SmsRequest(Collections.singletonList(condition)); content = Base64.getUrlEncoder().encodeToString(content.getBytes("UTF-8"));
SmsResponse smsResponse = restTemplate.postForObject(api, smsRequest, SmsResponse.class); String url = String.format(api, condition.getMobile(), content);
if (smsResponse == null || smsResponse.hasError()) { log.debug("sms req url:" + url);
log.error("短信发送失败:{}", smsResponse, toString()); ResponseEntity<String> resp = restTemplate.getForEntity(url, String.class);
throw new BusinessException("短信发送失败"); if (resp.getStatusCode() != HttpStatus.OK || !resp.getBody().equals("OK")) {
log.error("短信发送失败:{}", resp.getBody());
throw new BusinessException("短信发送失败");
}
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage(), e);
throw new BusinessException("短信发送失败");
} catch (Throwable e) {
log.error(e.getMessage(), e);
throw new BusinessException("短信发送失败");
}
}else {
SmsRequest smsRequest = new SmsRequest(Collections.singletonList(condition));
SmsResponse smsResponse = restTemplate.postForObject(api, smsRequest, SmsResponse.class);
if (smsResponse == null || smsResponse.hasError()) {
log.error("短信发送失败:{}", smsResponse, toString());
throw new BusinessException("短信发送失败");
}
} }
} }
} }
sms:
type: tjxak
api:
v3: http://sms.tjxak.com/smsGateWay/sms?t=%s&c=%s
...@@ -118,6 +118,7 @@ wx: ...@@ -118,6 +118,7 @@ wx:
keyPath: classpath:apiclient_cert.p12 keyPath: classpath:apiclient_cert.p12
sandbox: false sandbox: false
sms: sms:
type: aliyun
api: api:
v3: http://sms-service/sms/api/v3 v3: http://sms-service/sms/api/v3
aliyun: aliyun:
......
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