| @@ -1,5 +1,7 @@ | |||||
| package com.iformall.controller.callback; | package com.iformall.controller.callback; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.service.WxMsgCallbackService; | import com.iformall.service.WxMsgCallbackService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -42,7 +44,39 @@ public class WxMsgCallbackController extends BaseController { | |||||
| logger.info(param.toString()); | logger.info(param.toString()); | ||||
| //解析param数据插入数据库中 | //解析param数据插入数据库中 | ||||
| wxMsgCallbackService.receiveverifymodel(tenantId, param); | wxMsgCallbackService.receiveverifymodel(tenantId, param); | ||||
| } | |||||
| /** | |||||
| * 阿里云模板回调 | |||||
| * @param param | |||||
| */ | |||||
| @PostMapping(value = "/receivemodelAliyun") | |||||
| public Result receiveverifymodel(@RequestParam Map<String, String> param) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMsgCallbackController::receivemodelAliyun"); | |||||
| logger.info(param.toString()); | |||||
| try { | |||||
| //解析param数据插入数据库中 | |||||
| wxMsgCallbackService.receivemodelAliyun(param); | |||||
| }catch(Exception e){ | |||||
| logger.error("aliyun 模板回调ERROR",e); | |||||
| return new Result(ErrorCode.SYS_SERVER_ERROR); | |||||
| } | |||||
| return new Result(); | |||||
| } | |||||
| @PostMapping(value = "/receivemsgAliyun") | |||||
| public Result receivemsg(@RequestParam Map<String, String> param) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMsgCallbackController::receivemsgAliyun"); | |||||
| logger.info(param.toString()); | |||||
| try { | |||||
| //解析param数据插入数据库中 | |||||
| wxMsgCallbackService.receivemsgAliyun(param); | |||||
| }catch(Exception e){ | |||||
| logger.error("aliyun 短信回调ERROR",e); | |||||
| return new Result(ErrorCode.SYS_SERVER_ERROR); | |||||
| } | |||||
| return new Result(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,30 @@ | |||||
| package com.iformall.utils; | |||||
| import com.iformall.common.ErrorCode; | |||||
| /** | |||||
| * @author chenkx | |||||
| * @date 2018-01-05. | |||||
| */ | |||||
| public class ReportResult { | |||||
| public int code; | |||||
| public String msg; | |||||
| public ReportResult() { | |||||
| this.code = 0; | |||||
| this.msg = "接收成功"; | |||||
| } | |||||
| public ReportResult(int code, String msg) { | |||||
| this.code = code; | |||||
| this.msg = msg; | |||||
| } | |||||
| public ReportResult(ErrorCode errorCode) { | |||||
| this.code = errorCode.getCode(); | |||||
| this.msg = errorCode.getMessage(); | |||||
| } | |||||
| } | |||||
| @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject; | |||||
| 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.mapper.WxWiwideInfoMapper; | import com.iformall.mapper.WxWiwideInfoMapper; | ||||
| import com.iformall.utils.WiwideUtil; | |||||
| import com.iformall.sms.wiwide.WiwideUtil; | |||||
| 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; | ||||
| @@ -1,109 +0,0 @@ | |||||
| package com.iformall.aliyunSMS; | |||||
| import com.aliyuncs.DefaultAcsClient; | |||||
| import com.aliyuncs.IAcsClient; | |||||
| import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest; | |||||
| import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse; | |||||
| import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; | |||||
| import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; | |||||
| import com.aliyuncs.exceptions.ClientException; | |||||
| import com.aliyuncs.profile.DefaultProfile; | |||||
| import com.aliyuncs.profile.IClientProfile; | |||||
| import com.iformall.aliyunSMS.bean.AliyunSMSConfig; | |||||
| import com.iformall.aliyunSMS.bean.Query; | |||||
| import com.iformall.aliyunSMS.bean.Result; | |||||
| import com.iformall.aliyunSMS.bean.SMS; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | |||||
| import java.text.SimpleDateFormat; | |||||
| @Component | |||||
| @Slf4j | |||||
| public class SimpleSMSSender { | |||||
| @Autowired | |||||
| private AliyunSMSConfig smsConfig; | |||||
| /** | |||||
| * 发送短信 | |||||
| * @param sms | |||||
| * @return | |||||
| */ | |||||
| public Result sendSms(SMS sms) { | |||||
| IAcsClient acsClient = getClient(); | |||||
| SendSmsRequest request = getRequest(sms); | |||||
| SendSmsResponse sendSmsResponse = null; | |||||
| try { | |||||
| sendSmsResponse = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("发送短信发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")){ | |||||
| log.info(sendSmsResponse.getCode() + "----" + sendSmsResponse.getMessage()); | |||||
| Result result = new Result(); | |||||
| result.setSendSmsResponse(sendSmsResponse); | |||||
| result.setSms(sms); | |||||
| return result; | |||||
| }else{ | |||||
| log.error(sendSmsResponse.getCode() + "----" + sendSmsResponse.getMessage()); | |||||
| return null; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 查询短信发送结果 | |||||
| * @param query | |||||
| * @return | |||||
| */ | |||||
| public QuerySendDetailsResponse querySendDetails(Query query) { | |||||
| IAcsClient acsClient = getClient(); | |||||
| QuerySendDetailsRequest request = new QuerySendDetailsRequest(); | |||||
| request.setPhoneNumber(query.getPhoneNumber()); | |||||
| request.setBizId(query.getBizId()); | |||||
| SimpleDateFormat ft = new SimpleDateFormat(smsConfig.getDateFormat()); | |||||
| request.setSendDate(ft.format(query.getSendDate())); | |||||
| request.setPageSize(query.getPageSize()); | |||||
| request.setCurrentPage(query.getCurrentPage()); | |||||
| QuerySendDetailsResponse querySendDetailsResponse = null; | |||||
| try { | |||||
| querySendDetailsResponse = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("AliyunSMS查询短信发送结果异常" + e); | |||||
| } | |||||
| return querySendDetailsResponse; | |||||
| } | |||||
| /** | |||||
| * 获取短信请求 | |||||
| * @param sms | |||||
| * @return | |||||
| */ | |||||
| private SendSmsRequest getRequest(SMS sms) { | |||||
| SendSmsRequest request = new SendSmsRequest(); | |||||
| request.setPhoneNumbers(sms.getPhoneNumbers()); | |||||
| request.setSignName(sms.getSignName()); | |||||
| request.setTemplateCode(sms.getTemplateCode()); | |||||
| request.setTemplateParam(sms.getTemplateParam()); | |||||
| request.setOutId(sms.getOutId()); | |||||
| return request; | |||||
| } | |||||
| /** | |||||
| * 获取短信发送服务机 | |||||
| * @return | |||||
| */ | |||||
| private IAcsClient getClient() { | |||||
| IClientProfile profile = DefaultProfile.getProfile(smsConfig.getRegionId(), smsConfig.getAccessKeyId(), smsConfig.getAccessKeySecret()); | |||||
| try { | |||||
| DefaultProfile.addEndpoint(smsConfig.getEndpointName(), smsConfig.getRegionId(), smsConfig.getProduct(), smsConfig.getDomain()); | |||||
| } catch (ClientException e) { | |||||
| log.error("AliyunSMS获取短信发送服务机异常" + e); | |||||
| } | |||||
| return new DefaultAcsClient(profile); | |||||
| } | |||||
| } | |||||
| @@ -43,5 +43,8 @@ public class WxMsgConfig extends TenantEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="appid",name="appid") | @io.swagger.annotations.ApiModelProperty(value="appid",name="appid") | ||||
| private String appid; | private String appid; | ||||
| @io.swagger.annotations.ApiModelProperty(value="是否阿里云发短信1:是;0:否",name="isAliyunSMS") | |||||
| private Integer isAliyunSMS; | |||||
| } | } | ||||
| @@ -30,6 +30,8 @@ public class WxMsgModel extends TenantEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="modelid",name="modelId") | @io.swagger.annotations.ApiModelProperty(value="modelid",name="modelId") | ||||
| private Integer modelId; | private Integer modelId; | ||||
| @io.swagger.annotations.ApiModelProperty(value="aliyun模板code",name="modelCode") | |||||
| private String modelCode; | |||||
| } | } | ||||
| @@ -20,4 +20,10 @@ public class WxMsgSignature extends TenantEntity { | |||||
| private String name; | private String name; | ||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createtime") | @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createtime") | ||||
| private Date createtime; | private Date createtime; | ||||
| @io.swagger.annotations.ApiModelProperty(value="短信签名申请说明",name="remark") | |||||
| private String remark; | |||||
| @io.swagger.annotations.ApiModelProperty(value="签名审核状态",name="signStatus") | |||||
| private Integer signStatus; | |||||
| @io.swagger.annotations.ApiModelProperty(value="审核失败原因",name="name") | |||||
| private String reason; | |||||
| } | } | ||||
| @@ -15,4 +15,5 @@ public interface WxMsgCallbackMapper extends CommonMapper<WxMsgCallback, String> | |||||
| int queryMsgSendTotal(Map<String,String> params); | int queryMsgSendTotal(Map<String,String> params); | ||||
| void updateByBatchNo(WxMsgCallback wxMsgCallback); | |||||
| } | } | ||||
| @@ -10,7 +10,7 @@ public interface WxMsgModelMapper extends CommonMapper<WxMsgModel, String> { | |||||
| WxMsgModel findOneByModelId(WxMsgModel wxMsgModel); | WxMsgModel findOneByModelId(WxMsgModel wxMsgModel); | ||||
| void updateByCode(WxMsgModel wxMsgModel); | |||||
| } | } | ||||
| @@ -9,5 +9,6 @@ public interface WxMsgValidationcodeModelMapper extends CommonMapper<WxMsgValida | |||||
| void wxMsgValidationcodeModelInit(String initSql); | void wxMsgValidationcodeModelInit(String initSql); | ||||
| List<WxMsgValidationcodeModel> findList(WxMsgValidationcodeModel wxMsgValidationcodeModel); | List<WxMsgValidationcodeModel> findList(WxMsgValidationcodeModel wxMsgValidationcodeModel); | ||||
| void updateByCode(WxMsgValidationcodeModel wxMsgValidationcodeModel); | |||||
| } | } | ||||
| @@ -45,4 +45,7 @@ public interface WxMsgCallbackService { | |||||
| void receiveverifymodel(String bid, Map<String,String> param); | void receiveverifymodel(String bid, Map<String,String> param); | ||||
| void receivemodelAliyun(Map<String, String> param); | |||||
| void receivemsgAliyun(Map<String, String> param); | |||||
| } | } | ||||
| @@ -43,5 +43,6 @@ public interface WxMsgValidationcodeService { | |||||
| void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo, String id); | void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo, String id); | ||||
| } | } | ||||
| @@ -12,8 +12,8 @@ import com.iformall.enums.*; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.DataTowerService; | import com.iformall.service.DataTowerService; | ||||
| import com.iformall.sms.wiwide.WiwideUtil; | |||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import com.iformall.utils.WiwideUtil; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -10,6 +10,7 @@ import com.iformall.enums.EnumMsgSendStatus; | |||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.WxMsgCallbackService; | import com.iformall.service.WxMsgCallbackService; | ||||
| import com.iformall.utils.HMACSHA256; | import com.iformall.utils.HMACSHA256; | ||||
| import jodd.util.StringUtil; | |||||
| 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; | ||||
| @@ -153,6 +154,56 @@ public class WxMsgCallbackServiceImpl implements WxMsgCallbackService { | |||||
| } | |||||
| @Override | |||||
| public void receivemodelAliyun(Map<String, String> param) { | |||||
| logger.info(param.get("template_code")+"---"+param.get("template_status")+"---"+param.get("reason")); | |||||
| WxMsgModel wxMsgModel = new WxMsgModel(); | |||||
| wxMsgModel.setModelCode(param.get("template_code")); | |||||
| // 模板审核状态: | |||||
| //approving:审核中 | |||||
| //approved:审核通过 | |||||
| //rejected:审核未通过 | |||||
| String templateStatus = param.get("template_status"); | |||||
| if("approving".equals(templateStatus)){ | |||||
| wxMsgModel.setStatus(2); | |||||
| }else if("approved".equals(templateStatus)){ | |||||
| wxMsgModel.setStatus(1); | |||||
| }else if("rejected".equals(templateStatus)){ | |||||
| wxMsgModel.setStatus(0); | |||||
| }else{ | |||||
| wxMsgModel.setStatus(-1); | |||||
| } | |||||
| wxMsgModelMapper.updateByCode(wxMsgModel); | |||||
| WxMsgValidationcodeModel wxMsgValidationcodeModel = new WxMsgValidationcodeModel(); | |||||
| wxMsgValidationcodeModel.setModelCode(wxMsgModel.getModelCode()); | |||||
| wxMsgValidationcodeModel.setStatus(wxMsgModel.getStatus()); | |||||
| wxMsgValidationcodeModelMapper.updateByCode(wxMsgValidationcodeModel); | |||||
| } | |||||
| @Override | |||||
| public void receivemsgAliyun(Map<String, String> param) { | |||||
| String success = param.get("success"); | |||||
| WxMsgCallback wxMsgCallback = new WxMsgCallback(); | |||||
| wxMsgCallback.setBatchNo(param.get("biz_id")); | |||||
| if("true".equals(success)){ | |||||
| wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SEND_SUCCESS.getCode()); | |||||
| if(StringUtil.isNotBlank(param.get("out_id"))){ | |||||
| WxCouponPassword couponPassword = new WxCouponPassword(); | |||||
| couponPassword.setId(Long.valueOf(param.get("out_id"))); | |||||
| couponPassword.setStatus(EnumCouponPasswordStatus.MSG_SENDED.getCode()); | |||||
| couponPassword.setUpdateDate(new Date()); | |||||
| wxCouponPasswordMapper.updateById(couponPassword); | |||||
| } | |||||
| }else{ | |||||
| wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SEND_FAIL.getCode()); | |||||
| } | |||||
| wxMsgCallback.setStatusMsg(param.get("err_msg")); | |||||
| wxMsgCallbackMapper.updateByBatchNo(wxMsgCallback); | |||||
| } | } | ||||
| public boolean checksign(String tenantId,Map<String, String> param){ | public boolean checksign(String tenantId,Map<String, String> param){ | ||||
| @@ -15,6 +15,7 @@ import com.iformall.enums.EnumVerifyCode; | |||||
| 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; | ||||
| import com.iformall.sms.SMSFactory; | |||||
| import com.iformall.utils.*; | import com.iformall.utils.*; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -71,8 +72,9 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||||
| } | } | ||||
| } | } | ||||
| String result = WiwideUtil.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, | |||||
| content, wxMsgConfig.getModelnotifyurl(),EnumVerifyCode.NO.getCode().toString()); | |||||
| String result = SMSFactory.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, | |||||
| content, wxMsgConfig.getModelnotifyurl(),EnumVerifyCode.NO.getCode().toString(), | |||||
| wxMsgModel.getName(),2,wxMsgModel.getName(),wxMsgConfig.getIsAliyunSMS()); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| logger.info("短信模板创建结果:" + result); | logger.info("短信模板创建结果:" + result); | ||||
| @@ -83,12 +85,14 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||||
| wxMsgModel.setTenantId(wxMsgModel.getTenantId()); | wxMsgModel.setTenantId(wxMsgModel.getTenantId()); | ||||
| String data = jsonObjectResult.get("data").toString(); | String data = jsonObjectResult.get("data").toString(); | ||||
| wxMsgModel.setModelId(Integer.valueOf(data)); | wxMsgModel.setModelId(Integer.valueOf(data)); | ||||
| wxMsgModel.setModelCode(jsonObjectResult.get("aliyunModelCode").toString()); | |||||
| wxMsgModel.setCreatetime(new Date()); | wxMsgModel.setCreatetime(new Date()); | ||||
| wxMsgModel.setStatus(2);//审核中 | wxMsgModel.setStatus(2);//审核中 | ||||
| wxMsgModelMapper.insert(wxMsgModel); | wxMsgModelMapper.insert(wxMsgModel); | ||||
| } else { | } else { | ||||
| String data = jsonObjectResult.get("data").toString(); | String data = jsonObjectResult.get("data").toString(); | ||||
| wxMsgModel.setModelId(Integer.valueOf(data)); | wxMsgModel.setModelId(Integer.valueOf(data)); | ||||
| wxMsgModel.setModelCode(jsonObjectResult.get("aliyunModelCode").toString()); | |||||
| wxMsgModel.setStatus(2);//审核中 | wxMsgModel.setStatus(2);//审核中 | ||||
| wxMsgModelMapper.updateById(wxMsgModel); | wxMsgModelMapper.updateById(wxMsgModel); | ||||
| } | } | ||||
| @@ -15,6 +15,7 @@ import com.iformall.enums.EnumVerifyCode; | |||||
| import com.iformall.mapper.WxMsgConfigMapper; | import com.iformall.mapper.WxMsgConfigMapper; | ||||
| import com.iformall.mapper.WxMsgValidationcodeModelMapper; | import com.iformall.mapper.WxMsgValidationcodeModelMapper; | ||||
| import com.iformall.service.WxMsgValidationcodeModelService; | import com.iformall.service.WxMsgValidationcodeModelService; | ||||
| import com.iformall.sms.SMSFactory; | |||||
| import com.iformall.utils.*; | import com.iformall.utils.*; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -119,9 +120,11 @@ public class WxMsgValidationcodeModelServiceImpl implements WxMsgValidationcodeM | |||||
| 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(Result.SUCCESS, "修改成功"); | return new ResultData(Result.SUCCESS, "修改成功"); | ||||
| } | } | ||||
| } | } | ||||
| String result = WiwideUtil.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, content, wxMsgConfig.getVerifynotifyurl(),EnumVerifyCode.YES.getCode().toString()); | |||||
| String result = SMSFactory.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, content, | |||||
| wxMsgConfig.getVerifynotifyurl(),EnumVerifyCode.YES.getCode().toString(), | |||||
| wxMsgModel.getName(),1,wxMsgModel.getName(),wxMsgConfig.getIsAliyunSMS()); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| @@ -132,6 +135,7 @@ public class WxMsgValidationcodeModelServiceImpl implements WxMsgValidationcodeM | |||||
| wxMsgModel.setTenantId(wxMsgModel.getTenantId()); | wxMsgModel.setTenantId(wxMsgModel.getTenantId()); | ||||
| String data = jsonObjectResult.get("data").toString(); | String data = jsonObjectResult.get("data").toString(); | ||||
| wxMsgModel.setModelId(Integer.valueOf(data)); | wxMsgModel.setModelId(Integer.valueOf(data)); | ||||
| wxMsgModel.setModelCode(jsonObjectResult.get("aliyunModelCode").toString()); | |||||
| wxMsgModel.setCreatetime(new Date()); | wxMsgModel.setCreatetime(new Date()); | ||||
| wxMsgModel.setStatus(2);//审核中 | wxMsgModel.setStatus(2);//审核中 | ||||
| wxMsgValidationcodeModelMapper.insert(wxMsgModel); | wxMsgValidationcodeModelMapper.insert(wxMsgModel); | ||||
| @@ -127,7 +127,7 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
| wxMsgCallback.setTenantId(wxmsg.getTenantId()); | wxMsgCallback.setTenantId(wxmsg.getTenantId()); | ||||
| wxMsgCallback.setBatchNo(batchNo); | wxMsgCallback.setBatchNo(batchNo); | ||||
| wxMsgCallback.setMsgId(wxmsg.getId()); | wxMsgCallback.setMsgId(wxmsg.getId()); | ||||
| wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SEND_FAIL.getCode()); | |||||
| wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SENDING.getCode()); | |||||
| wxMsgCallback.setCreatetime(new Date()); | wxMsgCallback.setCreatetime(new Date()); | ||||
| if (StringUtils.isNotEmpty(id)) { | if (StringUtils.isNotEmpty(id)) { | ||||
| wxMsgCallback.setBusinessId(Long.parseLong(id)); | wxMsgCallback.setBusinessId(Long.parseLong(id)); | ||||
| @@ -16,8 +16,8 @@ import com.iformall.service.WxMsgLimitService; | |||||
| import com.iformall.service.msg.MsgSendService; | import com.iformall.service.msg.MsgSendService; | ||||
| import com.iformall.service.WxMsgService; | import com.iformall.service.WxMsgService; | ||||
| import com.iformall.service.WxMsgValidationcodeService; | import com.iformall.service.WxMsgValidationcodeService; | ||||
| import com.iformall.sms.SMSFactory; | |||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import com.iformall.utils.WiwideUtil; | |||||
| 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; | ||||
| @@ -101,8 +101,12 @@ public class SendCallBackSmsServiceImpl implements MsgSendService { | |||||
| return; | return; | ||||
| } | } | ||||
| */ | */ | ||||
| String result = SMSFactory.sendSms(secret, bid, publickey, phone, signature, msg, notifyUrl, | |||||
| EnumVerifyCode.NO.getCode().toString(), modelId, | |||||
| null,wxMsgModel.getModelCode(),Long.toString(record.getId()),wxMsgConfig.getIsAliyunSMS()); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.NO.getCode().toString(), modelId); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| String batchNo = jsonObjectResult.get("data").toString(); | String batchNo = jsonObjectResult.get("data").toString(); | ||||
| @@ -3,10 +3,6 @@ package com.iformall.service.msg.impl; | |||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.iformall.aliyunSMS.SimpleSMSSender; | |||||
| import com.iformall.aliyunSMS.bean.AliyunSMSConfig; | |||||
| import com.iformall.aliyunSMS.bean.Result; | |||||
| import com.iformall.aliyunSMS.bean.SMS; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| @@ -21,7 +17,7 @@ import com.iformall.mapper.WxMsgValidationcodeMapper; | |||||
| import com.iformall.mapper.WxMsgValidationcodeModelMapper; | import com.iformall.mapper.WxMsgValidationcodeModelMapper; | ||||
| import com.iformall.service.msg.MsgSendService; | import com.iformall.service.msg.MsgSendService; | ||||
| import com.iformall.service.WxMsgValidationcodeService; | import com.iformall.service.WxMsgValidationcodeService; | ||||
| import com.iformall.utils.WiwideUtil; | |||||
| import com.iformall.sms.SMSFactory; | |||||
| import org.apache.commons.collections.CollectionUtils; | import org.apache.commons.collections.CollectionUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -39,9 +35,6 @@ import java.util.Map; | |||||
| public class SendSmsServiceImpl implements MsgSendService { | public class SendSmsServiceImpl implements MsgSendService { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private SimpleSMSSender simpleSMSSender; | |||||
| @Autowired | @Autowired | ||||
| private WxMsgConfigMapper wxMsgConfigMapper; | private WxMsgConfigMapper wxMsgConfigMapper; | ||||
| @Autowired | @Autowired | ||||
| @@ -56,6 +49,8 @@ public class SendSmsServiceImpl implements MsgSendService { | |||||
| WxMsgRecord record = (WxMsgRecord)baseMsg; | WxMsgRecord record = (WxMsgRecord)baseMsg; | ||||
| TenantEntity tenantEntity = record.getTenantInfo(); | TenantEntity tenantEntity = record.getTenantInfo(); | ||||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | ||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| wxMsgValidationcode.setId(idWorker.nextId()); | |||||
| wxMsgValidationcode.setPhone(record.getReceiver()); | wxMsgValidationcode.setPhone(record.getReceiver()); | ||||
| wxMsgValidationcode.updateTenantInfo(tenantEntity); | wxMsgValidationcode.updateTenantInfo(tenantEntity); | ||||
| wxMsgValidationcode.setType(record.getModelType()); | wxMsgValidationcode.setType(record.getModelType()); | ||||
| @@ -94,42 +89,26 @@ public class SendSmsServiceImpl implements MsgSendService { | |||||
| if (wxMsgConfig.getRemains() <= 0L) { | if (wxMsgConfig.getRemains() <= 0L) { | ||||
| throw new MallinkException(ErrorCode.MSG_CONFIG_ACCOUNT); | throw new MallinkException(ErrorCode.MSG_CONFIG_ACCOUNT); | ||||
| } | } | ||||
| String ret = "",batchNo = ""; | |||||
| if(wxMsgValidationcodeModel.getMsgType().equals(11)){ | |||||
| //阿里云发短信 | |||||
| SMS sms = new SMS(); | |||||
| sms.setPhoneNumbers(record.getReceiver()); | |||||
| sms.setTemplateParam(JSON.toJSONString(record.getDynamicContentMap())); | |||||
| sms.setTemplateCode(wxMsgValidationcodeModel.getModelCode()); | |||||
| sms.setOutId(wxMsgValidationcodeModel.getId().toString()); | |||||
| sms.setSignName(wxMsgValidationcodeModel.getSignature()); | |||||
| Result result = simpleSMSSender.sendSms(sms); | |||||
| if(result != null){ | |||||
| ret = "1"; | |||||
| batchNo = result.getSendSmsResponse().getBizId(); | |||||
| } | |||||
| }else{ | |||||
| //迈外迪发短信 | |||||
| String secret = wxMsgConfig.getSecret(); | |||||
| String bid = wxMsgConfig.getBid(); | |||||
| String publickey = wxMsgConfig.getPublickey(); | |||||
| String phone = record.getReceiver(); | |||||
| String signature = wxMsgValidationcodeModel.getSignature(); | |||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||||
| Integer modelId = wxMsgValidationcodeModel.getModelId(); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.YES.getCode().toString(), modelId); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||||
| ret = jsonObjectResult.get("ret").toString(); | |||||
| batchNo = jsonObjectResult.get("data").toString(); | |||||
| } | |||||
| String secret = wxMsgConfig.getSecret(); | |||||
| String bid = wxMsgConfig.getBid(); | |||||
| String publickey = wxMsgConfig.getPublickey(); | |||||
| String phone = record.getReceiver(); | |||||
| String signature = wxMsgValidationcodeModel.getSignature(); | |||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||||
| Integer modelId = wxMsgValidationcodeModel.getModelId(); | |||||
| String id = record.getDynamicContentMap().get("id"); | |||||
| String result = SMSFactory.sendSms(secret, bid, publickey, phone, signature, msg, notifyUrl, | |||||
| EnumVerifyCode.YES.getCode().toString(), modelId, | |||||
| JSON.toJSONString(record.getDynamicContentMap()),wxMsgValidationcodeModel.getModelCode(), | |||||
| id,wxMsgConfig.getIsAliyunSMS()); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||||
| String ret = jsonObjectResult.get("ret").toString(); | |||||
| String batchNo = jsonObjectResult.get("data").toString(); | |||||
| if (ret.equals("1")) { | if (ret.equals("1")) { | ||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| wxMsgValidationcode.setId(idWorker.nextId()); | |||||
| long currentTime = System.currentTimeMillis(); | long currentTime = System.currentTimeMillis(); | ||||
| Date createtime=new Date(currentTime); | Date createtime=new Date(currentTime); | ||||
| wxMsgValidationcode.setCreatetime(createtime); | wxMsgValidationcode.setCreatetime(createtime); | ||||
| @@ -140,7 +119,6 @@ public class SendSmsServiceImpl implements MsgSendService { | |||||
| wxMsgValidationcode.setExpiretime(expiredate); | wxMsgValidationcode.setExpiretime(expiredate); | ||||
| } | } | ||||
| wxMsgValidationcodeMapper.insert(wxMsgValidationcode); | wxMsgValidationcodeMapper.insert(wxMsgValidationcode); | ||||
| String id = record.getDynamicContentMap().get("id"); | |||||
| wxMsgValidationcodeService.addMsgCallback(wxMsgValidationcode, batchNo, id); | wxMsgValidationcodeService.addMsgCallback(wxMsgValidationcode, batchNo, id); | ||||
| //扣减剩余条数 | //扣减剩余条数 | ||||
| wxMsgConfig.setRemains(1L); | wxMsgConfig.setRemains(1L); | ||||
| @@ -0,0 +1,36 @@ | |||||
| package com.iformall.sms; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| public enum EnumSMSChannel { | |||||
| ALIYUN(11, "ALIYUN"), | |||||
| WIWIDE(1,"WIWIDE"); | |||||
| public static EnumSMSChannel getEnum(Integer code) { | |||||
| for (EnumSMSChannel value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumSMSChannel(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,15 @@ | |||||
| package com.iformall.sms; | |||||
| public interface SMSExcutor { | |||||
| String sendMsg(String secret, String bid, String publickey,String phone, String signature, | |||||
| String msg, String notifyUrl, String verifysms, Integer modelId,String templateParam, | |||||
| String templateCode, String outId); | |||||
| String addTemplate(String secret, String bid, String publickey, String signature, String content, | |||||
| String notifyUrl, String verifysms,String templateName,Integer templateType, | |||||
| String remark); | |||||
| } | |||||
| @@ -0,0 +1,48 @@ | |||||
| package com.iformall.sms; | |||||
| import com.iformall.sms.aliyun.AliyunSMS; | |||||
| import com.iformall.sms.wiwide.WiwideUtil; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | |||||
| import javax.annotation.PostConstruct; | |||||
| @Component | |||||
| public class SMSFactory { | |||||
| @Autowired | |||||
| private AliyunSMS aliyunSMS; | |||||
| @Autowired | |||||
| private WiwideUtil wiwide; | |||||
| private static SMSFactory smsFactory; | |||||
| @PostConstruct | |||||
| public void init() { | |||||
| smsFactory = this; | |||||
| } | |||||
| private static SMSExcutor getSendExcutor(Integer channel) { | |||||
| if(EnumSMSChannel.ALIYUN.getCode().equals(channel)) { | |||||
| return smsFactory.aliyunSMS; | |||||
| }else{ | |||||
| return smsFactory.wiwide; | |||||
| } | |||||
| } | |||||
| public static String sendSms(String secret, String bid, String publickey,String phone, String signature, | |||||
| String msg, String notifyUrl, String verifysms, Integer modelId,String templateParam, | |||||
| String templateCode, String outId,Integer channel) { | |||||
| return getSendExcutor(channel).sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, | |||||
| verifysms, modelId,templateParam,templateCode,outId); | |||||
| } | |||||
| public static String addTemplate(String secret, String bid, String publickey, String signature, String content, | |||||
| String notifyUrl, String verifysms,String templateName,Integer templateType, | |||||
| String remark,Integer channel) { | |||||
| return getSendExcutor(channel).addTemplate(secret, bid, publickey, signature, content, notifyUrl,verifysms, | |||||
| templateName,templateType,remark); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package com.iformall.sms; | |||||
| import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; | |||||
| import com.iformall.sms.aliyun.bean.SMS; | |||||
| import lombok.Data; | |||||
| @Data | |||||
| public class SMSResult { | |||||
| private String ret; | |||||
| private String data; | |||||
| private String aliyunModelCode; | |||||
| } | |||||
| @@ -0,0 +1,292 @@ | |||||
| package com.iformall.sms.aliyun; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.aliyuncs.DefaultAcsClient; | |||||
| import com.aliyuncs.IAcsClient; | |||||
| import com.aliyuncs.dysmsapi.model.v20170525.*; | |||||
| import com.aliyuncs.exceptions.ClientException; | |||||
| import com.aliyuncs.profile.DefaultProfile; | |||||
| import com.aliyuncs.profile.IClientProfile; | |||||
| import com.iformall.sms.SMSExcutor; | |||||
| import com.iformall.sms.SMSResult; | |||||
| import com.iformall.sms.aliyun.bean.*; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | |||||
| import java.text.SimpleDateFormat; | |||||
| @Component | |||||
| @Slf4j | |||||
| public class AliyunSMS implements SMSExcutor { | |||||
| @Autowired | |||||
| private AliyunSMSConfig smsConfig; | |||||
| @Override | |||||
| public String sendMsg(String secret, String bid, String publickey, String phone, String signature, String msg, String notifyUrl, String verifysms, Integer modelId, String templateParam, String templateCode, String outId) { | |||||
| SMSResult SMSResult = new SMSResult(); | |||||
| SMS sms = new SMS(); | |||||
| sms.setPhoneNumbers(phone); | |||||
| sms.setTemplateParam(templateParam); | |||||
| sms.setTemplateCode(templateCode); | |||||
| sms.setOutId(outId); | |||||
| sms.setSignName(signature); | |||||
| Result result = this.sendSms(sms); | |||||
| if(result.getSendSmsResponse().getCode() != null | |||||
| && result.getSendSmsResponse().getCode().equals("ok")){ | |||||
| SMSResult.setRet("1"); | |||||
| SMSResult.setData(result.getSendSmsResponse().getBizId()); | |||||
| } | |||||
| return JSON.toJSONString(SMSResult); | |||||
| } | |||||
| @Override | |||||
| public String addTemplate(String secret, String bid, String publickey, String signature, String content, String notifyUrl, String verifysms, String templateName, Integer templateType, String remark) { | |||||
| SMSResult SMSResult = new SMSResult(); | |||||
| SMSTemplate smsTemplate = new SMSTemplate(); | |||||
| smsTemplate.setTemplateName(templateName); | |||||
| smsTemplate.setTemplateContent(content); | |||||
| smsTemplate.setTemplateType(templateType); | |||||
| smsTemplate.setRemark(remark); | |||||
| AddSmsTemplateResponse addSmsTemplateResponse = this.addSmsTemplate(smsTemplate); | |||||
| if(addSmsTemplateResponse.getCode() != null && addSmsTemplateResponse.getCode().equals("ok")){ | |||||
| SMSResult.setRet("1"); | |||||
| SMSResult.setAliyunModelCode(addSmsTemplateResponse.getTemplateCode()); | |||||
| } | |||||
| return JSON.toJSONString(SMSResult); | |||||
| } | |||||
| /** | |||||
| * 发送短信 | |||||
| * @param sms | |||||
| * @return | |||||
| */ | |||||
| public Result sendSms(SMS sms) { | |||||
| IAcsClient acsClient = getClient(); | |||||
| SendSmsRequest request = getRequest(sms); | |||||
| SendSmsResponse sendSmsResponse = null; | |||||
| try { | |||||
| sendSmsResponse = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("发送短信发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| log.info("发送短信-----" + sendSmsResponse.getCode() + "----" + sendSmsResponse.getMessage()); | |||||
| Result result = new Result(); | |||||
| result.setSendSmsResponse(sendSmsResponse); | |||||
| result.setSms(sms); | |||||
| return result; | |||||
| } | |||||
| /** | |||||
| * 添加签名 | |||||
| * @param smsSign | |||||
| */ | |||||
| public AddSmsSignResponse addSmsSign(SMSSign smsSign){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| AddSmsSignRequest request = new AddSmsSignRequest(); | |||||
| request.setSignName(smsSign.getSignName()); | |||||
| request.setSignSource(smsSign.getSignSource()); | |||||
| request.setRemark(smsSign.getRemark()); | |||||
| AddSmsSignResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("添加签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 删除签名 | |||||
| * @param smsSign | |||||
| */ | |||||
| public DeleteSmsSignResponse deleteSmsSign(SMSSign smsSign){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| DeleteSmsSignRequest request = new DeleteSmsSignRequest(); | |||||
| request.setSignName(smsSign.getSignName()); | |||||
| DeleteSmsSignResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("删除签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 修改签名 | |||||
| * @param smsSign | |||||
| */ | |||||
| public ModifySmsSignResponse modifySmsSign(SMSSign smsSign){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| ModifySmsSignRequest request = new ModifySmsSignRequest(); | |||||
| request.setSignName(smsSign.getSignName()); | |||||
| request.setSignSource(smsSign.getSignSource()); | |||||
| request.setRemark(smsSign.getRemark()); | |||||
| ModifySmsSignResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("修改签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 查询签名 | |||||
| * @param smsSign | |||||
| */ | |||||
| public QuerySmsSignResponse querySmsSign(SMSSign smsSign){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| QuerySmsSignRequest request = new QuerySmsSignRequest(); | |||||
| request.setSignName(smsSign.getSignName()); | |||||
| QuerySmsSignResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("查询签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 添加模板 | |||||
| * @param smsTemplate | |||||
| */ | |||||
| public AddSmsTemplateResponse addSmsTemplate(SMSTemplate smsTemplate){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| AddSmsTemplateRequest request = new AddSmsTemplateRequest(); | |||||
| request.setTemplateName(smsTemplate.getTemplateName()); | |||||
| request.setTemplateType(smsTemplate.getTemplateType()); | |||||
| request.setTemplateContent(smsTemplate.getTemplateContent()); | |||||
| request.setRemark(smsTemplate.getRemark()); | |||||
| AddSmsTemplateResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("添加签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 删除模板 | |||||
| * @param smsTemplate | |||||
| */ | |||||
| public DeleteSmsTemplateResponse deleteSmsTemplate(SMSTemplate smsTemplate){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| DeleteSmsTemplateRequest request = new DeleteSmsTemplateRequest(); | |||||
| request.setTemplateCode(smsTemplate.getTemplateCode()); | |||||
| DeleteSmsTemplateResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("删除签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 修改模板 | |||||
| * @param smsTemplate | |||||
| */ | |||||
| public ModifySmsTemplateResponse modifySmsTemplate(SMSTemplate smsTemplate){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| ModifySmsTemplateRequest request = new ModifySmsTemplateRequest(); | |||||
| request.setTemplateName(smsTemplate.getTemplateName()); | |||||
| request.setTemplateType(smsTemplate.getTemplateType()); | |||||
| request.setTemplateContent(smsTemplate.getTemplateContent()); | |||||
| request.setRemark(smsTemplate.getRemark()); | |||||
| request.setTemplateCode(smsTemplate.getTemplateCode()); | |||||
| ModifySmsTemplateResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("修改签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 查询模板 | |||||
| * @param smsTemplate | |||||
| */ | |||||
| public QuerySmsTemplateResponse querySmsTemplate(SMSTemplate smsTemplate){ | |||||
| IAcsClient acsClient = getClient(); | |||||
| QuerySmsTemplateRequest request = new QuerySmsTemplateRequest(); | |||||
| request.setTemplateCode(smsTemplate.getTemplateCode()); | |||||
| QuerySmsTemplateResponse response = null; | |||||
| try { | |||||
| response = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("查询签名发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 查询短信发送结果 | |||||
| * @param query | |||||
| * @return | |||||
| */ | |||||
| public QuerySendDetailsResponse querySendDetails(Query query) { | |||||
| IAcsClient acsClient = getClient(); | |||||
| QuerySendDetailsRequest request = new QuerySendDetailsRequest(); | |||||
| request.setPhoneNumber(query.getPhoneNumber()); | |||||
| request.setBizId(query.getBizId()); | |||||
| SimpleDateFormat ft = new SimpleDateFormat(smsConfig.getDateFormat()); | |||||
| request.setSendDate(ft.format(query.getSendDate())); | |||||
| request.setPageSize(query.getPageSize()); | |||||
| request.setCurrentPage(query.getCurrentPage()); | |||||
| QuerySendDetailsResponse querySendDetailsResponse = null; | |||||
| try { | |||||
| querySendDetailsResponse = acsClient.getAcsResponse(request); | |||||
| } catch (ClientException e) { | |||||
| log.error("查询短信发送结果发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return querySendDetailsResponse; | |||||
| } | |||||
| /** | |||||
| * 获取短信请求 | |||||
| * @param sms | |||||
| * @return | |||||
| */ | |||||
| private SendSmsRequest getRequest(SMS sms) { | |||||
| SendSmsRequest request = new SendSmsRequest(); | |||||
| request.setPhoneNumbers(sms.getPhoneNumbers()); | |||||
| request.setSignName(sms.getSignName()); | |||||
| request.setTemplateCode(sms.getTemplateCode()); | |||||
| request.setTemplateParam(sms.getTemplateParam()); | |||||
| request.setOutId(sms.getOutId()); | |||||
| return request; | |||||
| } | |||||
| /** | |||||
| * 获取短信发送服务机 | |||||
| * @return | |||||
| */ | |||||
| private IAcsClient getClient() { | |||||
| IClientProfile profile = DefaultProfile.getProfile(smsConfig.getRegionId(), smsConfig.getAccessKeyId(), smsConfig.getAccessKeySecret()); | |||||
| try { | |||||
| DefaultProfile.addEndpoint(smsConfig.getEndpointName(), smsConfig.getRegionId(), smsConfig.getProduct(), smsConfig.getDomain()); | |||||
| } catch (ClientException e) { | |||||
| log.error("获取短信发送服务机发生错误。错误代码是 [{}],错误消息是 [{}],错误请求ID是 [{}],错误Msg是 [{}],错误类型是 [{}]", | |||||
| e.getErrCode(), e.getMessage(), e.getRequestId(), e.getErrMsg(), e.getErrorType()); | |||||
| } | |||||
| return new DefaultAcsClient(profile); | |||||
| } | |||||
| } | |||||
| @@ -1,4 +1,4 @@ | |||||
| package com.iformall.aliyunSMS.bean; | |||||
| package com.iformall.sms.aliyun.bean; | |||||
| import lombok.Data; | import lombok.Data; | ||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | import org.springframework.boot.context.properties.ConfigurationProperties; | ||||
| @@ -1,4 +1,4 @@ | |||||
| package com.iformall.aliyunSMS.bean; | |||||
| package com.iformall.sms.aliyun.bean; | |||||
| import lombok.Data; | import lombok.Data; | ||||
| @@ -1,4 +1,4 @@ | |||||
| package com.iformall.aliyunSMS.bean; | |||||
| package com.iformall.sms.aliyun.bean; | |||||
| import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; | ||||
| import lombok.Data; | import lombok.Data; | ||||
| @@ -1,4 +1,4 @@ | |||||
| package com.iformall.aliyunSMS.bean; | |||||
| package com.iformall.sms.aliyun.bean; | |||||
| import lombok.Data; | import lombok.Data; | ||||
| @@ -0,0 +1,23 @@ | |||||
| package com.iformall.sms.aliyun.bean; | |||||
| import lombok.Data; | |||||
| @Data | |||||
| public class SMSSign { | |||||
| //签名名称。 | |||||
| private String signName; | |||||
| //签名来源。其中:默认为3 | |||||
| //0:企事业单位的全称或简称。 | |||||
| //1:工信部备案网站的全称或简称。 | |||||
| //2:APP应用的全称或简称。 | |||||
| //3:公众号或小程序的全称或简称。 | |||||
| //4:电商平台店铺名的全称或简称。 | |||||
| //5:商标名的全称或简称 | |||||
| private Integer signSource; | |||||
| //短信签名申请说明。请在申请说明中详细描述您的业务使用场景, | |||||
| // 申请工信部备案网站的全称或简称请在此处填写域名,长度不超过200个字符。 | |||||
| private String remark; | |||||
| } | |||||
| @@ -0,0 +1,24 @@ | |||||
| package com.iformall.sms.aliyun.bean; | |||||
| import lombok.Data; | |||||
| @Data | |||||
| public class SMSTemplate { | |||||
| //模板名称,长度为1~30个字符。 | |||||
| private String templateName; | |||||
| //短信类型。其中:默认为1 | |||||
| //0:验证码。 | |||||
| //1:短信通知。 | |||||
| //2:推广短信。 | |||||
| //3:国际/港澳台消息。 | |||||
| private Integer templateType; | |||||
| //模板内容,长度为1~500个字符。 | |||||
| private String templateContent; | |||||
| //短信模板申请说明。请在申请说明中描述您的业务使用场景,长度为1~100个字符 | |||||
| private String remark; | |||||
| //短信模板CODE。 | |||||
| private String templateCode; | |||||
| } | |||||
| @@ -1,25 +1,41 @@ | |||||
| package com.iformall.utils; | |||||
| 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.WxWiWideInfo; | import com.iformall.domain.po.WxWiWideInfo; | ||||
| import com.iformall.enums.EnumVerifyCode; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.sms.SMSExcutor; | |||||
| import com.iformall.utils.*; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.apache.shiro.codec.Base64; | import org.apache.shiro.codec.Base64; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.stereotype.Component; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.Set; | import java.util.Set; | ||||
| import java.util.TreeMap; | import java.util.TreeMap; | ||||
| public class WiwideUtil { | |||||
| @Component | |||||
| public class WiwideUtil implements SMSExcutor { | |||||
| private static final Logger logger = LoggerFactory.getLogger(WiwideUtil.class); | private static final Logger logger = LoggerFactory.getLogger(WiwideUtil.class); | ||||
| private static final String addTemplateUrl = "https://webapp.wiwide.com/apisms/addtemplate"; | private static final String addTemplateUrl = "https://webapp.wiwide.com/apisms/addtemplate"; | ||||
| private static final String smsSendUrl = "https://webapp.wiwide.com/apisms/send"; | private static final String smsSendUrl = "https://webapp.wiwide.com/apisms/send"; | ||||
| @Override | |||||
| public String sendMsg(String secret, String bid, String publickey, String phone, String signature, String msg, String notifyUrl, String verifysms, Integer modelId, String templateParam, String templateCode, String outId) { | |||||
| return sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, | |||||
| verifysms, modelId); | |||||
| } | |||||
| @Override | |||||
| 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); | |||||
| } | |||||
| 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<>(); | ||||
| @@ -163,4 +179,5 @@ public class WiwideUtil { | |||||
| String data = HttpUtil.doPostWiwide(wiWideInfo.getWiwideUrl() + "/reports/data", token, params); | String data = HttpUtil.doPostWiwide(wiWideInfo.getWiwideUrl() + "/reports/data", token, params); | ||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| @@ -104,7 +104,9 @@ | |||||
| <select id="queryMsgSendTotal" parameterType="hashmap" resultType="int"> | <select id="queryMsgSendTotal" parameterType="hashmap" resultType="int"> | ||||
| select count(*) from wx_msg_callback where msg_id=#{msgId} and status=#{status} | select count(*) from wx_msg_callback where msg_id=#{msgId} and status=#{status} | ||||
| </select> | </select> | ||||
| <update id="updateBybatchNo" parameterType="com.iformall.domain.po.WxMsgCallback"> | |||||
| update wx_msg_callback set status=#{status},status_msg=#{statusMsg} where `batch_no` = #{batchNo} | |||||
| </update> | |||||
| </mapper> | </mapper> | ||||
| @@ -19,12 +19,14 @@ | |||||
| <result column="modelnotifyurl" jdbcType="VARCHAR" property="modelnotifyurl" /> | <result column="modelnotifyurl" jdbcType="VARCHAR" property="modelnotifyurl" /> | ||||
| <result column="verifynotifyurl" jdbcType="VARCHAR" property="verifynotifyurl" /> | <result column="verifynotifyurl" jdbcType="VARCHAR" property="verifynotifyurl" /> | ||||
| <result column="appid" jdbcType="VARCHAR" property="appid" /> | <result column="appid" jdbcType="VARCHAR" property="appid" /> | ||||
| <result column="isAliyunSMS" jdbcType="SMALLINT" property="isAliyunSMS" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`parent_tenant_id`,`secret`,`publickey`,`bid`,`recharge`,`remains`,`total`,`account`,`reminderstatus`,`reminder`,`phone`,`notifyurl`,`modelnotifyurl`,`verifynotifyurl`,`appid` | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`secret`,`publickey`,`bid`,`recharge`,`remains`,`total`,`account`, | |||||
| `reminderstatus`,`reminder`,`phone`,`notifyurl`,`modelnotifyurl`,`verifynotifyurl`,`appid`,`isAliyunSMS` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -102,6 +104,11 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != isAliyunSMS "> | |||||
| and `appid` = #{isAliyunSMS} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -11,11 +11,12 @@ | |||||
| <result column="createtime" jdbcType="TIMESTAMP" property="createtime"/> | <result column="createtime" jdbcType="TIMESTAMP" property="createtime"/> | ||||
| <result column="status" jdbcType="INTEGER" property="status"/> | <result column="status" jdbcType="INTEGER" property="status"/> | ||||
| <result column="model_id" jdbcType="INTEGER" property="modelId"/> | <result column="model_id" jdbcType="INTEGER" property="modelId"/> | ||||
| <result column="model_code" jdbcType="VARCHAR" property="modelCode"/> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`parent_tenant_id`,`name`,`signature`,`content`,`createtime`,`status`,`model_id` | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`name`,`signature`,`content`,`createtime`,`status`,`model_id`,`model_code` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -54,6 +55,9 @@ | |||||
| <if test=" null != modelId"> | <if test=" null != modelId"> | ||||
| and `model_id` = #{modelId} | and `model_id` = #{modelId} | ||||
| </if> | </if> | ||||
| <if test=" null != modelCode"> | |||||
| and `model_code` = #{modelCode} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -84,5 +88,9 @@ | |||||
| limit 1 | limit 1 | ||||
| </select> | </select> | ||||
| <update id="updateByCode" parameterType="com.iformall.domain.po.WxMsgModel"> | |||||
| update wx_msg_model set status=#{status} where `model_code` = #{modelCode} | |||||
| </update> | |||||
| </mapper> | </mapper> | ||||
| @@ -7,10 +7,13 @@ | |||||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | ||||
| <result column="name" jdbcType="VARCHAR" property="name" /> | <result column="name" jdbcType="VARCHAR" property="name" /> | ||||
| <result column="createtime" jdbcType="TIMESTAMP" property="createtime" /> | <result column="createtime" jdbcType="TIMESTAMP" property="createtime" /> | ||||
| <result column="remark" jdbcType="VARCHAR" property="remark" /> | |||||
| <result column="sign_status" jdbcType="INTEGER" property="signStatus" /> | |||||
| <result column="reason" jdbcType="VARCHAR" property="reason" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`parent_tenant_id`,`name`,`createtime` | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`name`,`createtime`,`remark`,`sign_status`,`reason` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -36,7 +39,11 @@ | |||||
| <if test=" null != createtime "> | <if test=" null != createtime "> | ||||
| and `createtime` = #{createtime} | and `createtime` = #{createtime} | ||||
| </if> | |||||
| </if> | |||||
| <if test=" null != signStatus "> | |||||
| and `sign_status` = #{signStatus} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -61,6 +61,10 @@ | |||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <update id="updateByCode" parameterType="com.iformall.domain.po.WxMsgValidationcodeModel"> | |||||
| update wx_msg_validationcode_model set status=#{status} where `model_code` = #{modelCode} | |||||
| </update> | |||||
| <select id="wxMsgValidationcodeModelInit" parameterType="String"> | <select id="wxMsgValidationcodeModelInit" parameterType="String"> | ||||
| ${initSql} | ${initSql} | ||||
| </select> | </select> | ||||
| @@ -379,14 +379,15 @@ | |||||
| <dependency> | <dependency> | ||||
| <groupId>com.aliyun</groupId> | <groupId>com.aliyun</groupId> | ||||
| <artifactId>aliyun-java-sdk-core</artifactId> | <artifactId>aliyun-java-sdk-core</artifactId> | ||||
| <version>3.7.1</version> | |||||
| <version>4.5.2</version> | |||||
| </dependency> | </dependency> | ||||
| <dependency> | <dependency> | ||||
| <groupId>com.aliyun</groupId> | <groupId>com.aliyun</groupId> | ||||
| <artifactId>aliyun-java-sdk-dysmsapi</artifactId> | <artifactId>aliyun-java-sdk-dysmsapi</artifactId> | ||||
| <version>1.1.0</version> | |||||
| <version>2.1.0</version> | |||||
| </dependency> | </dependency> | ||||
| </dependencies> | </dependencies> | ||||
| <!-- | <!-- | ||||