Просмотр исходного кода

feat:修改短信模板新建接口

release_toaliyun_real
xmzhao71 2 лет назад
Родитель
Сommit
86e13a8a14
6 измененных файлов: 47 добавлений и 4 удалений
  1. +1
    -0
      mallinkService/src/main/java/com/iformall/common/ErrorCode.java
  2. +6
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxMsgModelServiceImpl.java
  3. +9
    -0
      mallinkService/src/main/java/com/iformall/sms/SMSExcutor.java
  4. +14
    -0
      mallinkService/src/main/java/com/iformall/sms/SMSFactory.java
  5. +12
    -0
      mallinkService/src/main/java/com/iformall/sms/aliyun/AliyunSMS.java
  6. +5
    -0
      mallinkService/src/main/java/com/iformall/sms/wiwide/WiwideUtil.java

+ 1
- 0
mallinkService/src/main/java/com/iformall/common/ErrorCode.java Просмотреть файл

@@ -435,6 +435,7 @@ public enum ErrorCode{
MSG_SUM_INSUFFICENT(12112,"短信数量不足"), MSG_SUM_INSUFFICENT(12112,"短信数量不足"),
MSG_NO_VALID_PHONE(12113,"没有可以发送的用户"), MSG_NO_VALID_PHONE(12113,"没有可以发送的用户"),
MSG_SEND_INTERFACE_ERROR(12114,"短信运营商返回错误"), MSG_SEND_INTERFACE_ERROR(12114,"短信运营商返回错误"),
MSG_WORD_COUNT_OVERLONG_ERROR(12115,"短信字数超限"),


/** /**
* 会员 * 会员


+ 6
- 4
mallinkService/src/main/java/com/iformall/service/impl/WxMsgModelServiceImpl.java Просмотреть файл

@@ -12,6 +12,8 @@ import com.iformall.domain.po.WxMsgModel;
import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.po.base.TenantEntity;
import com.iformall.enums.EnumMsgModelStatus; import com.iformall.enums.EnumMsgModelStatus;
import com.iformall.enums.EnumVerifyCode; import com.iformall.enums.EnumVerifyCode;
import com.iformall.exception.BizMessageException;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxMsgConfigMapper; import com.iformall.mapper.WxMsgConfigMapper;
import com.iformall.mapper.WxMsgModelMapper; import com.iformall.mapper.WxMsgModelMapper;
import com.iformall.service.WxMsgModelService; import com.iformall.service.WxMsgModelService;
@@ -46,7 +48,6 @@ public class WxMsgModelServiceImpl implements WxMsgModelService {


@Override @Override
public ResultData saveOrUpdate(WxMsgModel wxMsgModel) { public ResultData saveOrUpdate(WxMsgModel wxMsgModel) {

//从短信配置中查询密钥 bid 等信息 //从短信配置中查询密钥 bid 等信息
WxMsgConfig wxMsgConfig = new WxMsgConfig(); WxMsgConfig wxMsgConfig = new WxMsgConfig();
wxMsgConfig.updateTenantInfo(wxMsgModel); wxMsgConfig.updateTenantInfo(wxMsgModel);
@@ -55,11 +56,12 @@ public class WxMsgModelServiceImpl implements WxMsgModelService {
return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND.getCode(), "您还未接入短信运营商,请联系平台管理员"); return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND.getCode(), "您还未接入短信运营商,请联系平台管理员");
wxMsgConfig = wxMsgConfigs.get(0); wxMsgConfig = wxMsgConfigs.get(0);


String secret = wxMsgConfig.getSecret();
String bid = wxMsgConfig.getBid();

String signature = wxMsgModel.getSignature(); String signature = wxMsgModel.getSignature();
String content = wxMsgModel.getContent(); String content = wxMsgModel.getContent();

// 校验短信字数,超过规定字数会额外收费
SMSFactory.checkMessage(wxMsgConfig.getSmsChannel(), signature, content);

//查看用户最新数据是否存在 //查看用户最新数据是否存在
List<WxMsgModel> wxMsgModels = wxMsgModelMapper.findList(wxMsgModel); List<WxMsgModel> wxMsgModels = wxMsgModelMapper.findList(wxMsgModel);
if (wxMsgModel.getId() == null && wxMsgModels.size() == 1) { if (wxMsgModel.getId() == null && wxMsgModels.size() == 1) {


+ 9
- 0
mallinkService/src/main/java/com/iformall/sms/SMSExcutor.java Просмотреть файл

@@ -1,5 +1,7 @@
package com.iformall.sms; package com.iformall.sms;


import com.iformall.domain.po.WxMsgConfig;

import java.util.Date; import java.util.Date;


public interface SMSExcutor { public interface SMSExcutor {
@@ -16,4 +18,11 @@ public interface SMSExcutor {
String querySmsTemplate(String templateCode); String querySmsTemplate(String templateCode);


String querySendDetail(String phone, String bizId, Date sendDate); String querySendDetail(String phone, String bizId, Date sendDate);

/**
* 检查消息字数
* @param signature
* @param content
*/
void checkMsgWordCount(String signature, String content);
} }

+ 14
- 0
mallinkService/src/main/java/com/iformall/sms/SMSFactory.java Просмотреть файл

@@ -24,6 +24,10 @@ public class SMSFactory {


private static SMSFactory smsFactory; private static SMSFactory smsFactory;


public static void checkMessage(Integer smsChannel, String signature, String content) {
getSendExcutor(smsChannel).checkMsgWordCount(signature, content);
}



@PostConstruct @PostConstruct
public void init() { public void init() {
@@ -49,6 +53,16 @@ public class SMSFactory {
} }
} }


private static SMSExcutor getSendExcutor(Integer smsChannel) {
if(EnumSMSChannel.ALIYUN.getCode().equals(smsChannel)) {
return smsFactory.aliyunSMS;
}else if(EnumSMSChannel.ALIYUN_ZDY.getCode().equals(smsChannel)){
return smsFactory.aliyunSMS;
}else{
return smsFactory.wiwide;
}
}

public static String sendSms(WxMsgConfig wxMsgConfig,String phone, String signature, String msg, public static String sendSms(WxMsgConfig wxMsgConfig,String phone, String signature, String msg,
String verifysms, String templateParam, String verifysms, String templateParam,
String templateCode, String outId) { String templateCode, String outId) {


+ 12
- 0
mallinkService/src/main/java/com/iformall/sms/aliyun/AliyunSMS.java Просмотреть файл

@@ -8,6 +8,9 @@ import com.aliyuncs.dysmsapi.model.v20170525.*;
import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile; import com.aliyuncs.profile.IClientProfile;
import com.iformall.common.ErrorCode;
import com.iformall.domain.po.WxMsgConfig;
import com.iformall.exception.MallinkException;
import com.iformall.sms.EnumSMSChannel; import com.iformall.sms.EnumSMSChannel;
import com.iformall.sms.SMSExcutor; import com.iformall.sms.SMSExcutor;
import com.iformall.sms.SMSResult; import com.iformall.sms.SMSResult;
@@ -122,6 +125,15 @@ public class AliyunSMS implements SMSExcutor {
return null; return null;
} }


@Override
public void checkMsgWordCount(String signature, String content) {
int limitWord = 70;
String msg = "【" + signature + "】" + content + "回T退订";
if (msg.length() > limitWord) {
throw new MallinkException(ErrorCode.MSG_WORD_COUNT_OVERLONG_ERROR.getCode(), ErrorCode.MSG_WORD_COUNT_OVERLONG_ERROR.getMessage());
}
}



/** /**
* 发送短信 * 发送短信


+ 5
- 0
mallinkService/src/main/java/com/iformall/sms/wiwide/WiwideUtil.java Просмотреть файл

@@ -2,6 +2,7 @@ package com.iformall.sms.wiwide;


import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.iformall.common.ErrorCode; import com.iformall.common.ErrorCode;
import com.iformall.domain.po.WxMsgConfig;
import com.iformall.domain.po.WxWiWideInfo; import com.iformall.domain.po.WxWiWideInfo;
import com.iformall.exception.MallinkException; import com.iformall.exception.MallinkException;
import com.iformall.sms.SMSExcutor; import com.iformall.sms.SMSExcutor;
@@ -43,6 +44,10 @@ public class WiwideUtil implements SMSExcutor {
return null; return null;
} }


@Override
public void checkMsgWordCount(String signature, String content) {
}

public static String addTemplate(String secret, String bid, String publickey, String signature, String content, String notifyUrl, String verifysms) { public static String addTemplate(String secret, String bid, String publickey, String signature, String content, String notifyUrl, String verifysms) {
//请求api数据排序 //请求api数据排序
TreeMap<String, String> message = new TreeMap<>(); TreeMap<String, String> message = new TreeMap<>();


Загрузка…
Отмена
Сохранить