|
@@ -1,5 +1,8 @@
|
|
|
package com.diagbot.service.impl;
|
|
|
|
|
|
+import com.aliyuncs.IAcsClient;
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|
|
import com.diagbot.entity.SwsVerInfo;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.exception.ErrorCode;
|
|
@@ -8,9 +11,6 @@ import com.diagbot.util.DateUtil;
|
|
|
import com.diagbot.util.GsonUtil;
|
|
|
import com.diagbot.util.SmsCodeUtil;
|
|
|
import com.diagbot.util.StringUtil;
|
|
|
-import com.taobao.api.TaobaoClient;
|
|
|
-import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
|
|
|
-import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@@ -37,7 +37,7 @@ public class SmsVerServiceImpl implements SmsVerService {
|
|
|
private RedisTemplate redisForSms;
|
|
|
|
|
|
@Autowired
|
|
|
- private TaobaoClient taobaoClient;
|
|
|
+ private IAcsClient acsClient;
|
|
|
|
|
|
private byte[] serializeKey(Object o) {
|
|
|
return redisForSms.getKeySerializer().serialize(o);
|
|
@@ -51,7 +51,7 @@ public class SmsVerServiceImpl implements SmsVerService {
|
|
|
return redisForSms.getValueSerializer().deserialize(b);
|
|
|
}
|
|
|
|
|
|
- private byte[] getUserSmsKey(int userId) {
|
|
|
+ private byte[] getUserSmsKey(Long userId) {
|
|
|
String userSmsFormat = "user_sms_%d";
|
|
|
return serializeKey(String.format(userSmsFormat, userId));
|
|
|
}
|
|
@@ -61,23 +61,36 @@ public class SmsVerServiceImpl implements SmsVerService {
|
|
|
throw new CommonException(ErrorCode.PARAM_IS_NULL,
|
|
|
"电话号码不能为空!");
|
|
|
}
|
|
|
- AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
|
|
|
- req.setSmsType( "normal" );
|
|
|
- req.setSmsFreeSignName( "朗通云平台" );
|
|
|
+
|
|
|
+ //组装请求对象-具体描述见控制台-文档部分内容
|
|
|
+ SendSmsRequest request = new SendSmsRequest();
|
|
|
+ //必填:待发送手机号
|
|
|
+ request.setPhoneNumbers(mobile);
|
|
|
+ //必填:短信签名-可在短信控制台中找到
|
|
|
+ request.setSignName("朗通云平台");
|
|
|
+ //必填:短信模板-可在短信控制台中找到
|
|
|
+ request.setTemplateCode(smsTemplateCode);
|
|
|
String code = SmsCodeUtil.getVerCode();
|
|
|
String json="{\"code\":\""
|
|
|
+ code
|
|
|
- + "\",\"product\":\"【朗通云平台】\"}";
|
|
|
- req.setSmsParamString(json);
|
|
|
- req.setRecNum(mobile);
|
|
|
- req.setSmsTemplateCode(smsTemplateCode);
|
|
|
+ + "\",\"name\":\"hhh\"}";
|
|
|
+ //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
|
|
|
+ request.setTemplateParam(json);
|
|
|
+
|
|
|
+ //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
|
|
|
+ //request.setSmsUpExtendCode("90997");
|
|
|
+ //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
|
|
|
+ //request.setOutId("yourOutId");
|
|
|
+
|
|
|
try {
|
|
|
- AlibabaAliqinFcSmsNumSendResponse rsp = taobaoClient.execute(req);
|
|
|
+ //此处可能会抛出异常,注意catch
|
|
|
+ SendSmsResponse rsp = acsClient.getAcsResponse(request);
|
|
|
System.out.println(GsonUtil.toJson(rsp));
|
|
|
- if (null == rsp || !rsp.isSuccess()){
|
|
|
+ if ((null == rsp) || !(rsp.getCode().equals("OK"))){
|
|
|
throw new CommonException(ErrorCode.SMS_SEND_ERROR);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
throw new CommonException(ErrorCode.SMS_SEND_ERROR);
|
|
|
}
|
|
|
return code;
|
|
@@ -193,7 +206,7 @@ public class SmsVerServiceImpl implements SmsVerService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public SwsVerInfo getSmsVerification(Integer userId){
|
|
|
+ public SwsVerInfo getSmsVerification(Long userId){
|
|
|
return (SwsVerInfo) redisForSms.execute(new RedisCallback<Object>() {
|
|
|
@Override
|
|
|
public Object doInRedis(RedisConnection connection) throws DataAccessException {
|
|
@@ -211,7 +224,7 @@ public class SmsVerServiceImpl implements SmsVerService {
|
|
|
* 删除用户短信验证码信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public Boolean deleteSmsVerification(Integer userId){
|
|
|
+ public Boolean deleteSmsVerification(Long userId){
|
|
|
final byte[] redis_key = getUserSmsKey(userId);
|
|
|
Long l = (Long) redisForSms.execute(new RedisCallback<Long>() {
|
|
|
@Override
|