| @@ -18,6 +18,8 @@ import com.iformall.mapper.WxMsgModelMapper; | |||||
| import com.iformall.service.WxMsgModelService; | import com.iformall.service.WxMsgModelService; | ||||
| import com.iformall.sms.EnumSMSChannel; | import com.iformall.sms.EnumSMSChannel; | ||||
| import com.iformall.sms.SMSFactory; | import com.iformall.sms.SMSFactory; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -67,15 +69,30 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||||
| if (wxMsgModel.getId() == null && wxMsgModels.size() == 1) { | if (wxMsgModel.getId() == null && wxMsgModels.size() == 1) { | ||||
| return new ResultData(ErrorCode.MSG_TEMPLATE_REPEAT.getCode(), "您添加的短信模板已存在"); | return new ResultData(ErrorCode.MSG_TEMPLATE_REPEAT.getCode(), "您添加的短信模板已存在"); | ||||
| } | } | ||||
| String templateCode = ""; | |||||
| if (wxMsgModel.getId() != null && wxMsgModels.size() == 1) { | if (wxMsgModel.getId() != null && wxMsgModels.size() == 1) { | ||||
| WxMsgModel wxmsgmodel = wxMsgModels.get(0); | WxMsgModel wxmsgmodel = wxMsgModels.get(0); | ||||
| templateCode = wxmsgmodel.getModelCode(); | |||||
| if (wxmsgmodel.getContent().equals(wxMsgModel.getContent()) && wxmsgmodel.getSignature().equals(wxMsgModel.getSignature())) { | if (wxmsgmodel.getContent().equals(wxMsgModel.getContent()) && wxmsgmodel.getSignature().equals(wxMsgModel.getSignature())) { | ||||
| return new ResultData(ResultData.SUCCESS, "修改成功"); | return new ResultData(ResultData.SUCCESS, "修改成功"); | ||||
| } | } | ||||
| } | } | ||||
| String result = SMSFactory.addTemplate(wxMsgConfig, signature,content, EnumVerifyCode.NO.getCode().toString(), | |||||
| String result = ""; | |||||
| if (wxMsgModel.getId() == null) { | |||||
| result = SMSFactory.addTemplate(wxMsgConfig, signature,content, EnumVerifyCode.NO.getCode().toString(), | |||||
| wxMsgModel.getName(),wxMsgModel.getTemplateType(),wxMsgModel.getName()); | wxMsgModel.getName(),wxMsgModel.getTemplateType(),wxMsgModel.getName()); | ||||
| }else { | |||||
| if (StringUtils.isNotBlank(templateCode)) { | |||||
| result = SMSFactory.updateTemplate(wxMsgConfig,templateCode, signature,content, EnumVerifyCode.NO.getCode().toString(), | |||||
| wxMsgModel.getName(),wxMsgModel.getTemplateType(),wxMsgModel.getName()); | |||||
| }else { | |||||
| result = SMSFactory.addTemplate(wxMsgConfig, signature,content, EnumVerifyCode.NO.getCode().toString(), | |||||
| wxMsgModel.getName(),wxMsgModel.getTemplateType(),wxMsgModel.getName()); | |||||
| } | |||||
| } | |||||
| if (StringUtils.isBlank(result)) { | |||||
| return new ResultData(ErrorCode.MSG_TEMPLATE_CREATE_ERROR.getCode(), "创建模板失败,无接口结果"); | |||||
| } | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| logger.info(">>>>>"+result); | logger.info(">>>>>"+result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| @@ -13,6 +13,10 @@ public interface SMSExcutor { | |||||
| String addTemplate(String secret, String bid, String publickey, String signature, String content, | String addTemplate(String secret, String bid, String publickey, String signature, String content, | ||||
| String notifyUrl, String verifysms,String templateName,Integer templateType, | String notifyUrl, String verifysms,String templateName,Integer templateType, | ||||
| String remark); | String remark); | ||||
| String updateTemplate(String secret, String bid, String publickey, String templateCode,String signature, String content, | |||||
| String notifyUrl, String verifysms,String templateName,Integer templateType, | |||||
| String remark); | |||||
| String querySmsTemplate(String templateCode); | String querySmsTemplate(String templateCode); | ||||
| @@ -79,6 +79,14 @@ public class SMSFactory { | |||||
| verifysms,templateName,templateType,remark); | verifysms,templateName,templateType,remark); | ||||
| } | } | ||||
| public static String updateTemplate(WxMsgConfig wxMsgConfig, String templateCode,String signature, String content, | |||||
| String verifysms,String templateName,Integer templateType, | |||||
| String remark) { | |||||
| return getSendExcutor(wxMsgConfig).addTemplate(wxMsgConfig.getSecret(), wxMsgConfig.getBid(), wxMsgConfig.getPublickey(), | |||||
| signature, content, wxMsgConfig.getModelnotifyurl(), | |||||
| verifysms,templateName,templateType,remark); | |||||
| } | |||||
| public static String querySmsTemplate(WxMsgConfig wxMsgConfig, String templateCode) { | public static String querySmsTemplate(WxMsgConfig wxMsgConfig, String templateCode) { | ||||
| return getSendExcutor(wxMsgConfig).querySmsTemplate(templateCode); | return getSendExcutor(wxMsgConfig).querySmsTemplate(templateCode); | ||||
| } | } | ||||
| @@ -137,6 +137,62 @@ public class AliyunSMS implements SMSExcutor { | |||||
| } | } | ||||
| return JSON.toJSONString(SMSResult); | return JSON.toJSONString(SMSResult); | ||||
| } | } | ||||
| @Override | |||||
| public String updateTemplate(String secret, String bid, String publickey, String templateCode, String signature, | |||||
| String content, String notifyUrl, String verifysms, String templateName, Integer templateType, | |||||
| String remark) { | |||||
| SMSResult SMSResult = new SMSResult(); | |||||
| com.aliyun.dysmsapi20170525.Client client; | |||||
| try { | |||||
| client = this.createClient(); | |||||
| } catch (Exception e) { | |||||
| log.error("addTemplate error",e); | |||||
| return JSON.toJSONString(SMSResult); | |||||
| } | |||||
| com.aliyun.dysmsapi20170525.models.UpdateSmsTemplateRequest updateSmsTemplateRequest = new com.aliyun.dysmsapi20170525.models.UpdateSmsTemplateRequest(); | |||||
| updateSmsTemplateRequest.setTemplateCode(templateCode); | |||||
| updateSmsTemplateRequest.setTemplateName(templateName); | |||||
| updateSmsTemplateRequest.setTemplateContent(content); | |||||
| updateSmsTemplateRequest.setTemplateType(templateType); | |||||
| updateSmsTemplateRequest.setRemark(remark); | |||||
| updateSmsTemplateRequest.setRelatedSignName(signature); | |||||
| com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); | |||||
| try { | |||||
| com.aliyun.dysmsapi20170525.models.UpdateSmsTemplateResponse resp = client.updateSmsTemplateWithOptions(updateSmsTemplateRequest, runtime); | |||||
| log.info(">>>"+JSON.toJSONString(resp)); | |||||
| JSONObject respo = JSON.parseObject(JSON.toJSONString(resp)); | |||||
| JSONObject body = respo.getJSONObject("body"); | |||||
| if (null != body) { | |||||
| String code = body.getString("code"); | |||||
| if (StringUtils.isNotBlank(code) && code.equalsIgnoreCase("ok")) { | |||||
| SMSResult.setRet(EnumMsgModelStatus.SUCCESS.getCode().toString()); | |||||
| SMSResult.setAliyunModelCode(body.getString("templateCode")); | |||||
| } | |||||
| } | |||||
| } catch (TeaException error) { | |||||
| // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 | |||||
| // 错误 message | |||||
| //System.out.println(error.getMessage()); | |||||
| // 诊断地址 | |||||
| //System.out.println(error.getData().get("Recommend")); | |||||
| log.error("addTemplate error:"+error.getMessage()+"|recommend:"+error.getData().get("Recommend"),error); | |||||
| SMSResult.setRet(EnumMsgModelStatus.FAIL.getCode().toString()); | |||||
| } catch (Exception _error) { | |||||
| TeaException error = new TeaException(_error.getMessage(), _error); | |||||
| // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 | |||||
| // 错误 message | |||||
| //System.out.println(error.getMessage()); | |||||
| // 诊断地址 | |||||
| //System.out.println(error.getData().get("Recommend")); | |||||
| log.error("addTemplate error:"+error.getMessage()+"|recommend:"+error.getData().get("Recommend"),error); | |||||
| SMSResult.setRet(EnumMsgModelStatus.FAIL.getCode().toString()); | |||||
| } | |||||
| return JSON.toJSONString(SMSResult); | |||||
| } | |||||
| @Override | @Override | ||||
| public String querySmsTemplate(String templateCode) { | public String querySmsTemplate(String templateCode) { | ||||
| @@ -192,7 +248,7 @@ public class AliyunSMS implements SMSExcutor { | |||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public String querySendDetail(String phone, String bizId, Date sendDate) { | public String querySendDetail(String phone, String bizId, Date sendDate) { | ||||
| Query query = new Query(); | Query query = new Query(); | ||||
| @@ -539,4 +595,6 @@ public class AliyunSMS implements SMSExcutor { | |||||
| } | } | ||||
| } | } | ||||
| @@ -33,6 +33,13 @@ public class WiwideUtil implements SMSExcutor { | |||||
| public String addTemplate(String secret, String bid, String publickey, String signature, String content, String notifyUrl, String verifysms, String templateName, Integer templateType, String remark) { | public String addTemplate(String secret, String bid, String publickey, String signature, String content, String notifyUrl, String verifysms, String templateName, Integer templateType, String remark) { | ||||
| return addTemplate(secret, bid, publickey, signature, content, notifyUrl,verifysms); | return addTemplate(secret, bid, publickey, signature, content, notifyUrl,verifysms); | ||||
| } | } | ||||
| @Override | |||||
| public String updateTemplate(String secret, String bid, String publickey, String templateCode, String signature, | |||||
| String content, String notifyUrl, String verifysms, String templateName, Integer templateType, | |||||
| String remark) { | |||||
| return addTemplate(secret, bid, publickey, signature, content, notifyUrl,verifysms); | |||||
| } | |||||
| @Override | @Override | ||||
| public String querySmsTemplate(String templateCode) { | public String querySmsTemplate(String templateCode) { | ||||
| @@ -282,4 +289,5 @@ public class WiwideUtil implements SMSExcutor { | |||||
| } | } | ||||
| } | } | ||||