| @@ -1,13 +1,12 @@ | |||||
| package com.iformall.schedule; | package com.iformall.schedule; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxCUser; | |||||
| import com.iformall.domain.po.WxMsg; | import com.iformall.domain.po.WxMsg; | ||||
| import com.iformall.domain.po.WxMsgConfig; | import com.iformall.domain.po.WxMsgConfig; | ||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.WxMsgConfigMapper; | import com.iformall.mapper.WxMsgConfigMapper; | ||||
| import com.iformall.mapper.WxMsgMapper; | import com.iformall.mapper.WxMsgMapper; | ||||
| import com.iformall.service.PushLimitService; | |||||
| import com.iformall.utils.*; | import com.iformall.utils.*; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -28,6 +27,9 @@ public class MsgSendingSchedule { | |||||
| @Autowired | @Autowired | ||||
| private WxMsgConfigMapper wxMsgConfigMapper; | private WxMsgConfigMapper wxMsgConfigMapper; | ||||
| @Autowired | |||||
| private PushLimitService pushLimitService; | |||||
| @Scheduled(cron = "0 1 * * * ?") // 每小时第一分钟执行 | @Scheduled(cron = "0 1 * * * ?") // 每小时第一分钟执行 | ||||
| public void sendmsgschedule() { | public void sendmsgschedule() { | ||||
| @@ -41,7 +43,15 @@ public class MsgSendingSchedule { | |||||
| List<WxMsg> list = wxMsgMapper.findList(wxMsg); | List<WxMsg> list = wxMsgMapper.findList(wxMsg); | ||||
| for(WxMsg msg:list){ | for(WxMsg msg:list){ | ||||
| sendmsg(msg); | |||||
| boolean checkTime = false; | |||||
| try { | |||||
| checkTime = pushLimitService.checkSendTime(wxMsg.getTenantId()); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| if (checkTime) { | |||||
| sendmsg(msg); | |||||
| } | |||||
| } | } | ||||
| logger.info("sendmsg定时任务结束"); | logger.info("sendmsg定时任务结束"); | ||||
| @@ -77,40 +87,7 @@ public class MsgSendingSchedule { | |||||
| String signature = wxMsg.getSignature(); | String signature = wxMsg.getSignature(); | ||||
| String msg = wxMsg.getMsg(); | String msg = wxMsg.getMsg(); | ||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | String notifyUrl = wxMsgConfig.getNotifyurl(); | ||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("phone", phone); | |||||
| message.put("signature", signature); | |||||
| message.put("msg", msg); | |||||
| message.put("notify_url", notifyUrl); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), publickey); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| String requestUrl = "https://webapp.wiwide.com/apisms/send"; | |||||
| String result = HttpUtil.doPost(requestUrl, params); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| @@ -16,10 +16,7 @@ import com.iformall.mapper.WxMsgConfigMapper; | |||||
| import com.iformall.mapper.WxMsgValidationcodeMapper; | import com.iformall.mapper.WxMsgValidationcodeMapper; | ||||
| import com.iformall.mapper.WxMsgValidationcodeModelMapper; | import com.iformall.mapper.WxMsgValidationcodeModelMapper; | ||||
| import com.iformall.service.WxMallApplyService; | import com.iformall.service.WxMallApplyService; | ||||
| import com.iformall.utils.AesUtil; | |||||
| import com.iformall.utils.HMACSHA256; | |||||
| import com.iformall.utils.HttpUtil; | |||||
| import com.iformall.utils.RsaUtil; | |||||
| import com.iformall.utils.*; | |||||
| 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; | ||||
| @@ -121,41 +118,7 @@ public class WxMallApplyServiceImpl implements WxMallApplyService { | |||||
| wxMsgValidationcode.setMsg(msg); | wxMsgValidationcode.setMsg(msg); | ||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | String notifyUrl = wxMsgConfig.getNotifyurl(); | ||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("phone", phone); | |||||
| message.put("signature", signature); | |||||
| message.put("msg", msg); | |||||
| message.put("notify_url", notifyUrl); | |||||
| message.put("verifysms","1"); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), publickey); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| throw new RuntimeException("发送失败"); | |||||
| } | |||||
| String requestUrl = "https://webapp.wiwide.com/apisms/send"; | |||||
| String result = HttpUtil.doPost(requestUrl, params); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| @@ -10,14 +10,10 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxMsgConfig; | import com.iformall.domain.po.WxMsgConfig; | ||||
| import com.iformall.domain.po.WxMsgModel; | import com.iformall.domain.po.WxMsgModel; | ||||
| import com.iformall.enums.EnumMsgModelStatus; | import com.iformall.enums.EnumMsgModelStatus; | ||||
| 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; | ||||
| import com.iformall.utils.AesUtil; | |||||
| import com.iformall.utils.HMACSHA256; | |||||
| import com.iformall.utils.HttpUtil; | |||||
| import com.iformall.utils.RsaUtil; | |||||
| import com.iformall.utils.*; | |||||
| 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; | ||||
| @@ -73,40 +69,8 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||||
| } | } | ||||
| } | } | ||||
| //请求api数据排序 | |||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("signature", signature); | |||||
| message.put("content", content); | |||||
| message.put("notify_url", wxMsgConfig.getModelnotifyurl()); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), wxMsgConfig.getPublickey()); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| logger.info("短信AES/RSA解密失败"); | |||||
| throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); | |||||
| } | |||||
| String requestUrl = "https://webapp.wiwide.com/apisms/addtemplate"; | |||||
| String result = HttpUtil.doPost(requestUrl, params); | |||||
| String result = WiwideUtil.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, | |||||
| content, wxMsgConfig.getModelnotifyurl()); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| if (ret.equals(EnumMsgModelStatus.SUCCESS.getCode().toString())) { | if (ret.equals(EnumMsgModelStatus.SUCCESS.getCode().toString())) { | ||||
| @@ -20,6 +20,7 @@ import com.iformall.mapper.WxCUserBasicInfoMapper; | |||||
| import com.iformall.mapper.WxMsgCallbackMapper; | import com.iformall.mapper.WxMsgCallbackMapper; | ||||
| import com.iformall.mapper.WxMsgConfigMapper; | import com.iformall.mapper.WxMsgConfigMapper; | ||||
| import com.iformall.mapper.WxMsgMapper; | import com.iformall.mapper.WxMsgMapper; | ||||
| import com.iformall.service.PushLimitService; | |||||
| import com.iformall.service.WxCUserTagsService; | import com.iformall.service.WxCUserTagsService; | ||||
| import com.iformall.service.WxMsgService; | import com.iformall.service.WxMsgService; | ||||
| import com.iformall.utils.*; | import com.iformall.utils.*; | ||||
| @@ -49,6 +50,9 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| @Autowired | @Autowired | ||||
| WxMsgCallbackMapper wxMsgCallbackMapper; | WxMsgCallbackMapper wxMsgCallbackMapper; | ||||
| @Autowired | |||||
| PushLimitService pushLimitService; | |||||
| @Override | @Override | ||||
| public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { | ||||
| PageHelper.startPage(pageIndex, pageSize); | PageHelper.startPage(pageIndex, pageSize); | ||||
| @@ -132,6 +136,12 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| //是否立即发送 | //是否立即发送 | ||||
| if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | ||||
| wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | ||||
| try { | |||||
| pushLimitService.checkSendTime(wxMsg.getTenantId()); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(),e.getMessage()); | |||||
| } | |||||
| return sendmsg(wxMsg); | return sendmsg(wxMsg); | ||||
| } else { | } else { | ||||
| wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_NOT_SEND.getCode()); | wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_NOT_SEND.getCode()); | ||||
| @@ -181,6 +191,12 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| //是否立即发送 | //是否立即发送 | ||||
| if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | ||||
| wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | ||||
| try { | |||||
| pushLimitService.checkSendTime(wxMsg.getTenantId()); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(),e.getMessage()); | |||||
| } | |||||
| return sendmsg(wxMsg); | return sendmsg(wxMsg); | ||||
| } else { | } else { | ||||
| //定时 | //定时 | ||||
| @@ -245,41 +261,7 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| String signature = wxMsg.getSignature(); | String signature = wxMsg.getSignature(); | ||||
| String msg = wxMsg.getMsg(); | String msg = wxMsg.getMsg(); | ||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | String notifyUrl = wxMsgConfig.getNotifyurl(); | ||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("phone", phone); | |||||
| message.put("signature", signature); | |||||
| message.put("msg", msg); | |||||
| message.put("notify_url", notifyUrl); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), publickey); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| logger.info("短信AES/RSA解密失败"); | |||||
| throw new MallinkException(ErrorCode.MSG_SEND_ERROR); | |||||
| } | |||||
| String requestUrl = "https://webapp.wiwide.com/apisms/send"; | |||||
| String result = HttpUtil.doPost(requestUrl, params); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl); | |||||
| 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(); | ||||
| @@ -311,7 +293,6 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| } | } | ||||
| public void addMsgCallback(WxMsg wxmsg, String batchNo){ | public void addMsgCallback(WxMsg wxmsg, String batchNo){ | ||||
| logger.info("营销短信发送时主动添加回调记录开始..."); | logger.info("营销短信发送时主动添加回调记录开始..."); | ||||
| String phones = wxmsg.getPhones(); | String phones = wxmsg.getPhones(); | ||||
| @@ -10,14 +10,10 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxMsgConfig; | import com.iformall.domain.po.WxMsgConfig; | ||||
| import com.iformall.domain.po.WxMsgValidationcodeModel; | import com.iformall.domain.po.WxMsgValidationcodeModel; | ||||
| import com.iformall.enums.EnumMsgModelStatus; | import com.iformall.enums.EnumMsgModelStatus; | ||||
| import com.iformall.exception.MallinkException; | |||||
| 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.utils.AesUtil; | |||||
| import com.iformall.utils.HMACSHA256; | |||||
| import com.iformall.utils.HttpUtil; | |||||
| import com.iformall.utils.RsaUtil; | |||||
| import com.iformall.utils.*; | |||||
| 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; | ||||
| @@ -75,42 +71,8 @@ public class WxMsgValidationcodeModelServiceImpl implements WxMsgValidationcodeM | |||||
| } | } | ||||
| } | } | ||||
| String result = WiwideUtil.addTemplate(secret, bid, wxMsgConfig.getPublickey(), signature, content, wxMsgConfig.getModelnotifyurl()); | |||||
| //请求api数据排序 | |||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("signature", signature); | |||||
| message.put("content", content); | |||||
| message.put("notify_url",wxMsgConfig.getModelnotifyurl()); | |||||
| message.put("verifysms","1"); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), wxMsgConfig.getPublickey()); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| logger.info("短信AES/RSA解密失败"); | |||||
| throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); | |||||
| } | |||||
| String requestUrl = "https://webapp.wiwide.com/apisms/addtemplate"; | |||||
| String result = HttpUtil.doPost(requestUrl, params); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||
| if (ret.equals(EnumMsgModelStatus.SUCCESS.getCode().toString())) { | if (ret.equals(EnumMsgModelStatus.SUCCESS.getCode().toString())) { | ||||
| @@ -9,13 +9,9 @@ import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumMsgSendStatus; | import com.iformall.enums.EnumMsgSendStatus; | ||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.WxMsgValidationcodeService; | import com.iformall.service.WxMsgValidationcodeService; | ||||
| import com.iformall.utils.AesUtil; | |||||
| import com.iformall.utils.HMACSHA256; | |||||
| import com.iformall.utils.HttpUtil; | |||||
| import com.iformall.utils.RsaUtil; | |||||
| import com.iformall.utils.*; | |||||
| 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; | ||||
| @@ -124,42 +120,7 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
| wxMsgValidationcode.setMsg(msg); | wxMsgValidationcode.setMsg(msg); | ||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | String notifyUrl = wxMsgConfig.getNotifyurl(); | ||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("phone", phone); | |||||
| message.put("signature", signature); | |||||
| message.put("msg", msg); | |||||
| message.put("notify_url", notifyUrl); | |||||
| message.put("verifysms","1"); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), publickey); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| logger.info("短信AES/RSA解密失败"); | |||||
| throw new MallinkException(ErrorCode.MSG_SEND_ERROR); | |||||
| } | |||||
| String requestUrl = "https://webapp.wiwide.com/apisms/send"; | |||||
| String result = HttpUtil.doPost(requestUrl, params); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl); | |||||
| 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(); | ||||
| @@ -0,0 +1,96 @@ | |||||
| package com.iformall.utils; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| import java.util.Set; | |||||
| import java.util.TreeMap; | |||||
| public class WiwideUtil { | |||||
| private static final Logger logger = LoggerFactory.getLogger(ETCPUtil.class); | |||||
| private static final String addTemplateUrl = "https://webapp.wiwide.com/apisms/addtemplate"; | |||||
| private static final String smsSendUrl = "https://webapp.wiwide.com/apisms/send"; | |||||
| public static String addTemplate(String secret, String bid, String publickey, String signature, String content, String notifyUrl) { | |||||
| //请求api数据排序 | |||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("signature", signature); | |||||
| message.put("content", content); | |||||
| message.put("notify_url",notifyUrl); | |||||
| message.put("verifysms","1"); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), publickey); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| logger.info("短信AES/RSA解密失败"); | |||||
| throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); | |||||
| } | |||||
| String requestUrl = addTemplateUrl; | |||||
| return HttpUtil.doPost(requestUrl, params); | |||||
| } | |||||
| public static String sendMsg(String secret, String bid, String publickey, | |||||
| String phone, String signature, String msg, String notifyUrl) { | |||||
| TreeMap<String, String> message = new TreeMap<>(); | |||||
| message.put("bid", bid); | |||||
| message.put("phone", phone); | |||||
| message.put("signature", signature); | |||||
| message.put("msg", msg); | |||||
| message.put("notify_url", notifyUrl); | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||||
| for (Map.Entry<String, String> entry : entries) { | |||||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||||
| } | |||||
| sb.append("&secret=").append(secret); | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||||
| message.put("sign", sign.toUpperCase()); | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | |||||
| params.put("iv", iv); | |||||
| params.put("bid", bid); | |||||
| try { | |||||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), publickey); | |||||
| params.put("data", data); | |||||
| params.put("sc", sc); | |||||
| } catch (Exception e) { | |||||
| logger.info("短信AES/RSA解密失败"); | |||||
| throw new MallinkException(ErrorCode.MSG_SEND_ERROR); | |||||
| } | |||||
| String requestUrl = smsSendUrl; | |||||
| return HttpUtil.doPost(requestUrl, params); | |||||
| } | |||||
| } | |||||