| @@ -0,0 +1,5 @@ | |||||
| ALTER TABLE `wx_msg_config` | |||||
| ADD COLUMN `product` varchar(50) AFTER `sms_channel`, | |||||
| ADD COLUMN `domain` varchar(100) AFTER `product`, | |||||
| ADD COLUMN `region_id` varchar(50) AFTER `domain`, | |||||
| ADD COLUMN `endpoint_name` varchar(50) AFTER `region_id`; | |||||
| @@ -43,5 +43,14 @@ public class WxMsgConfig extends TenantEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="发短信渠道0:wiwidi; 11:aliyun",name="smsChannel") | @io.swagger.annotations.ApiModelProperty(value="发短信渠道0:wiwidi; 11:aliyun",name="smsChannel") | ||||
| private Integer smsChannel; | private Integer smsChannel; | ||||
| // 短信API产品名称(短信产品名固定,无需修改) product = "Dysmsapi" | |||||
| private String product; | |||||
| //短信API产品域名,接口地址固定,无需修改 domain = "dysmsapi.aliyuncs.com" | |||||
| private String domain; | |||||
| //API支持的RegionID,如短信API的值为: cn-hangzhou。 | |||||
| private String regionId; | |||||
| //服务结点: cn-hangzhou | |||||
| private String endpointName; | |||||
| } | } | ||||
| @@ -73,9 +73,8 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||||
| } | } | ||||
| } | } | ||||
| String result = SMSFactory.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, | |||||
| content, wxMsgConfig.getModelnotifyurl(),EnumVerifyCode.NO.getCode().toString(), | |||||
| wxMsgModel.getName(),1,wxMsgModel.getName(),wxMsgConfig.getSmsChannel()); | |||||
| String result = SMSFactory.addTemplate(wxMsgConfig, signature,content, EnumVerifyCode.NO.getCode().toString(), | |||||
| wxMsgModel.getName(),1,wxMsgModel.getName()); | |||||
| 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); | ||||
| @@ -141,9 +141,8 @@ public class WxMsgValidationcodeModelServiceImpl implements WxMsgValidationcodeM | |||||
| } | } | ||||
| } | } | ||||
| String result = SMSFactory.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, content, | |||||
| wxMsgConfig.getVerifynotifyurl(),EnumVerifyCode.YES.getCode().toString(), | |||||
| wxMsgModel.getName(),1,wxMsgModel.getName(),wxMsgConfig.getSmsChannel()); | |||||
| String result = SMSFactory.addTemplate(wxMsgConfig, signature, content,EnumVerifyCode.YES.getCode().toString(), | |||||
| wxMsgModel.getName(),1,wxMsgModel.getName()); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| @@ -106,9 +106,9 @@ public class SendCallBackSmsServiceImpl implements MsgSendService { | |||||
| outId = Long.toString(record.getId()); | outId = Long.toString(record.getId()); | ||||
| }catch(Exception e){} | }catch(Exception e){} | ||||
| String result = SMSFactory.sendSms(secret, bid, publickey, phone, signature, msg, notifyUrl, | |||||
| String result = SMSFactory.sendSms(wxMsgConfig, phone, signature, msg, | |||||
| EnumVerifyCode.NO.getCode().toString(), modelId, | EnumVerifyCode.NO.getCode().toString(), modelId, | ||||
| null,wxMsgModel.getModelCode(),outId,wxMsgConfig.getSmsChannel()); | |||||
| null,wxMsgModel.getModelCode(),outId); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| @@ -99,10 +99,9 @@ public class SendSmsServiceImpl implements MsgSendService { | |||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | String notifyUrl = wxMsgConfig.getNotifyurl(); | ||||
| Integer modelId = wxMsgValidationcodeModel.getModelId(); | Integer modelId = wxMsgValidationcodeModel.getModelId(); | ||||
| String id = record.getDynamicContentMap().get("id"); | 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.getSmsChannel()); | |||||
| String result = SMSFactory.sendSms(wxMsgConfig, phone, signature, msg, | |||||
| EnumVerifyCode.YES.getCode().toString(), modelId,JSON.toJSONString(record.getDynamicContentMap()), | |||||
| wxMsgValidationcodeModel.getModelCode(),id); | |||||
| 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(); | ||||
| @@ -110,7 +109,7 @@ public class SendSmsServiceImpl implements MsgSendService { | |||||
| if (ret.equals("1")) { | if (ret.equals("1")) { | ||||
| long currentTime = System.currentTimeMillis(); | long currentTime = System.currentTimeMillis(); | ||||
| Date createtime=new Date(currentTime); | |||||
| Date createtime = new Date(currentTime); | |||||
| wxMsgValidationcode.setCreatetime(createtime); | wxMsgValidationcode.setCreatetime(createtime); | ||||
| Integer minutes = wxMsgValidationcodeModel.getMinutes(); | Integer minutes = wxMsgValidationcodeModel.getMinutes(); | ||||
| if(minutes >0) { | if(minutes >0) { | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.sms; | package com.iformall.sms; | ||||
| import com.iformall.domain.po.WxMsgConfig; | |||||
| import com.iformall.sms.aliyun.AliyunSMS; | import com.iformall.sms.aliyun.AliyunSMS; | ||||
| import com.iformall.sms.aliyun.bean.AliyunSMSConfig; | import com.iformall.sms.aliyun.bean.AliyunSMSConfig; | ||||
| import com.iformall.sms.wiwide.WiwideUtil; | import com.iformall.sms.wiwide.WiwideUtil; | ||||
| @@ -28,28 +29,39 @@ public class SMSFactory { | |||||
| smsFactory = this; | smsFactory = this; | ||||
| } | } | ||||
| private static SMSExcutor getSendExcutor(Integer channel) { | |||||
| if(EnumSMSChannel.ALIYUN.getCode().equals(channel)) { | |||||
| private static SMSExcutor getSendExcutor(WxMsgConfig wxMsgConfig) { | |||||
| if(EnumSMSChannel.ALIYUN.getCode().equals(wxMsgConfig.getSmsChannel())) { | |||||
| smsFactory.aliyunSMS.setSmsConfig(smsFactory.smsConfig); | smsFactory.aliyunSMS.setSmsConfig(smsFactory.smsConfig); | ||||
| return smsFactory.aliyunSMS; | return smsFactory.aliyunSMS; | ||||
| }else if(EnumSMSChannel.ALIYUN_ZDY.getCode().equals(channel)){ | |||||
| }else if(EnumSMSChannel.ALIYUN_ZDY.getCode().equals(wxMsgConfig.getSmsChannel())){ | |||||
| smsFactory.smsConfig = new AliyunSMSConfig(); | |||||
| smsFactory.smsConfig.setAccessKeyId(wxMsgConfig.getPublickey()); | |||||
| smsFactory.smsConfig.setAccessKeySecret(wxMsgConfig.getSecret()); | |||||
| smsFactory.smsConfig.setProduct(wxMsgConfig.getProduct()); | |||||
| smsFactory.smsConfig.setDomain(wxMsgConfig.getDomain()); | |||||
| smsFactory.smsConfig.setRegionId(wxMsgConfig.getRegionId()); | |||||
| smsFactory.smsConfig.setEndpointName(wxMsgConfig.getEndpointName()); | |||||
| smsFactory.aliyunSMS.setSmsConfig(smsFactory.smsConfig); | |||||
| return smsFactory.aliyunSMS; | return smsFactory.aliyunSMS; | ||||
| }else{ | }else{ | ||||
| return smsFactory.wiwide; | 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, | |||||
| public static String sendSms(WxMsgConfig wxMsgConfig,String phone, String signature, String msg, | |||||
| String verifysms, Integer modelId, String templateParam, | |||||
| String templateCode, String outId) { | |||||
| return getSendExcutor(wxMsgConfig).sendMsg(wxMsgConfig.getSecret(), wxMsgConfig.getBid(), wxMsgConfig.getPublickey(), | |||||
| phone, signature, msg, wxMsgConfig.getNotifyurl(), | |||||
| verifysms, modelId,templateParam,templateCode,outId); | 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); | |||||
| public static String addTemplate(WxMsgConfig wxMsgConfig, 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.getNotifyurl(), | |||||
| verifysms,templateName,templateType,remark); | |||||
| } | } | ||||
| } | } | ||||
| @@ -23,7 +23,7 @@ public class AliyunSMSConfig { | |||||
| //API支持的RegionID,如短信API的值为: cn-hangzhou。 | //API支持的RegionID,如短信API的值为: cn-hangzhou。 | ||||
| private String regionId; | private String regionId; | ||||
| //#发送日期 支持30天内记录查询,格式: yyyyMMdd | //#发送日期 支持30天内记录查询,格式: yyyyMMdd | ||||
| private String dateFormat; | |||||
| private String dateFormat = "yyyyMMdd"; | |||||
| //服务结点: cn-hangzhou | //服务结点: cn-hangzhou | ||||
| private String endpointName; | private String endpointName; | ||||
| @@ -76,7 +76,8 @@ public class WiwideUtil implements SMSExcutor { | |||||
| } | } | ||||
| public static String sendMsg(String secret, String bid, String publickey, | public static String sendMsg(String secret, String bid, String publickey, | ||||
| String phone, String signature, String msg, String notifyUrl, String verifysms, Integer modelId) { | |||||
| String phone, String signature, String msg, String notifyUrl, | |||||
| String verifysms, Integer modelId) { | |||||
| TreeMap<String, Object> message = new TreeMap<>(); | TreeMap<String, Object> message = new TreeMap<>(); | ||||
| message.put("bid", bid); | message.put("bid", bid); | ||||
| message.put("phone", phone); | message.put("phone", phone); | ||||
| @@ -21,11 +21,17 @@ | |||||
| <!-- <result column="appid" jdbcType="VARCHAR" property="appid" />--> | <!-- <result column="appid" jdbcType="VARCHAR" property="appid" />--> | ||||
| <result column="sms_channel" jdbcType="SMALLINT" property="smsChannel" /> | <result column="sms_channel" jdbcType="SMALLINT" property="smsChannel" /> | ||||
| <result column="product" jdbcType="VARCHAR" property="product" /> | |||||
| <result column="domain" jdbcType="VARCHAR" property="domain" /> | |||||
| <result column="region_id" jdbcType="VARCHAR" property="regionId" /> | |||||
| <result column="endpoint_name" jdbcType="VARCHAR" property="endpointName" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`parent_tenant_id`,`secret`,`publickey`,`bid`,`recharge`,`remains`,`total`,`account`, | `id`,`tenant_id`,`parent_tenant_id`,`secret`,`publickey`,`bid`,`recharge`,`remains`,`total`,`account`, | ||||
| `reminderstatus`,`reminder`,`phone`,`notifyurl`,`modelnotifyurl`,`verifynotifyurl`,`sms_channel` | |||||
| `reminderstatus`,`reminder`,`phone`,`notifyurl`,`modelnotifyurl`,`verifynotifyurl`,`sms_channel`, | |||||
| `product`,`domain`,`region_id`,`endpoint_name` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||