| @@ -0,0 +1,17 @@ | |||
| package com.simple.mapper; | |||
| import com.simple.common.CommonMapper; | |||
| import com.simple.domain.po.WxMsgCallback; | |||
| import java.util.List; | |||
| public interface WxMsgCallbackMapper extends CommonMapper<WxMsgCallback, String> { | |||
| List<WxMsgCallback> findList(WxMsgCallback wxMsgCallback); | |||
| } | |||
| @@ -0,0 +1,48 @@ | |||
| package com.simple.service; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.domain.po.WxMsgCallback; | |||
| public interface WxMsgCallbackService { | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param offset | |||
| * @param limit | |||
| * @return | |||
| */ | |||
| PageInfo<WxMsgCallback> listAsPage(WxMsgCallback record, Integer pageIndex, Integer pageSize); | |||
| /** | |||
| * 根据Id获得实体 | |||
| * | |||
| * @param id | |||
| * @return | |||
| */ | |||
| WxMsgCallback getById(String id); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxMsgCallback record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| * | |||
| * @param id | |||
| */ | |||
| void deleteById(String id); | |||
| } | |||
| @@ -2,6 +2,7 @@ package com.simple.service; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMsgModel; | |||
| public interface WxMsgModelService { | |||
| @@ -29,7 +30,7 @@ public interface WxMsgModelService { | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxMsgModel record); | |||
| ResultData saveOrUpdate(WxMsgModel record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| @@ -2,7 +2,9 @@ package com.simple.service; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMsg; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| public interface WxMsgService { | |||
| @@ -37,12 +39,9 @@ public interface WxMsgService { | |||
| * @param id | |||
| */ | |||
| void deleteById(Long id); | |||
| ResultData sendmsgbyexcel(MultipartFile file, WxMsg wxMsg); | |||
| ResultData sendmsgbylabel(WxMsg wxMsg); | |||
| } | |||
| @@ -0,0 +1,51 @@ | |||
| package com.simple.service.impl; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.domain.po.WxMsgCallback; | |||
| import com.simple.mapper.WxMsgCallbackMapper; | |||
| import com.simple.service.WxMsgCallbackService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @Service | |||
| public class WxMsgCallbackServiceImpl implements WxMsgCallbackService { | |||
| @Autowired | |||
| WxMsgCallbackMapper wxMsgCallbackMapper; | |||
| @Override | |||
| public PageInfo<WxMsgCallback> listAsPage(WxMsgCallback record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxMsgCallbackMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public WxMsgCallback getById(String id) { | |||
| return wxMsgCallbackMapper.selectByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxMsgCallback record) { | |||
| if (record.getId() == null) { | |||
| record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| wxMsgCallbackMapper.insertSelective(record); | |||
| } else { | |||
| wxMsgCallbackMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| } | |||
| @Override | |||
| public void deleteById(String id) { | |||
| wxMsgCallbackMapper.deleteByPrimaryKey(id); | |||
| } | |||
| } | |||
| @@ -1,14 +1,24 @@ | |||
| package com.simple.service.impl; | |||
| import java.util.*; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.IdWorker; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMsgConfig; | |||
| import com.simple.domain.po.WxMsgModel; | |||
| import com.simple.mapper.WxMsgConfigMapper; | |||
| import com.simple.mapper.WxMsgModelMapper; | |||
| import com.simple.service.WxMsgModelService; | |||
| import com.simple.utils.AesUtil; | |||
| import com.simple.utils.HMACSHA256; | |||
| import com.simple.utils.HttpUtil; | |||
| import com.simple.utils.RsaUtil; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.simple.common.IdWorker; | |||
| import java.util.*; | |||
| @Service | |||
| public class WxMsgModelServiceImpl implements WxMsgModelService { | |||
| @@ -16,6 +26,8 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||
| @Autowired | |||
| WxMsgModelMapper wxMsgModelMapper; | |||
| @Autowired | |||
| WxMsgConfigMapper wxMsgConfigMapper; | |||
| @Override | |||
| public PageInfo<WxMsgModel> listAsPage(WxMsgModel record, Integer pageIndex, Integer pageSize) { | |||
| @@ -28,15 +40,78 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxMsgModel record) { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| IdWorker idWorker = new IdWorker(0, 0); | |||
| record.setId(idWorker.nextId()); | |||
| wxMsgModelMapper.insertSelective(record); | |||
| } else { | |||
| wxMsgModelMapper.updateByPrimaryKeySelective(record); | |||
| public ResultData saveOrUpdate(WxMsgModel wxMsgModel) { | |||
| //从短信配置中查询密钥 bid 等信息 | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| wxMsgConfig.setTenantId("1"); | |||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| if(wxMsgConfigs.size()==0)return new ResultData(Result.SUCCESS, "您还未接入短信运营商,请联系平台管理员"); | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| String secret = wxMsgConfig.getSecret(); | |||
| String bid = wxMsgConfig.getBid(); | |||
| String signature = wxMsgModel.getSignature(); | |||
| String content = wxMsgModel.getContent(); | |||
| //查看用户最新数据是否存在 | |||
| List<WxMsgModel> wxMsgModels = wxMsgModelMapper.findList(wxMsgModel); | |||
| if (wxMsgModel.getId() == null && wxMsgModels.size() == 1) { | |||
| return new ResultData(Result.SUCCESS, "您添加的短信模板已存在"); | |||
| } | |||
| if (wxMsgModel.getId() != null && wxMsgModels.size() == 1) { | |||
| WxMsgModel wxmsgmodel = wxMsgModels.get(0); | |||
| if(wxmsgmodel.getContent().equals(wxMsgModel.getContent()) && wxmsgmodel.getSignature().equals(wxMsgModel.getSignature())) { | |||
| return new ResultData(Result.SUCCESS, "您添加的短信模板已存在"); | |||
| } | |||
| } | |||
| //请求api数据排序 | |||
| TreeMap<String, String> message = new TreeMap<>(); | |||
| message.put("bid", bid); | |||
| message.put("signature", signature); | |||
| message.put("content", content); | |||
| 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 = "198b02e8fd704e96198b02e8fd704e96"; | |||
| String iv = "198b02e8fd704e96"; | |||
| 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) { | |||
| e.printStackTrace(); | |||
| } | |||
| String requestUrl = "https://webapp.wiwide.com/apisms/addtemplate"; | |||
| String result = HttpUtil.doPost(requestUrl, params); | |||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||
| String ret = jsonObjectResult.get("ret").toString(); | |||
| if (ret.equals("1") || ret.equals("-6")) { | |||
| if (wxMsgModel.getId() == null) { | |||
| IdWorker idWorker = new IdWorker(0, 0); | |||
| wxMsgModel.setId(idWorker.nextId()); | |||
| wxMsgModel.setCreatetime(new Date()); | |||
| wxMsgModelMapper.insertSelective(wxMsgModel); | |||
| } else { | |||
| wxMsgModelMapper.updateByPrimaryKeySelective(wxMsgModel); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "创建模板成功"); | |||
| }else if (ret == "-4") { | |||
| return new ResultData(Result.SUCCESS, "短信签名或内容错误"); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "创建模板失败"); | |||
| } | |||
| @Override | |||
| @@ -1,14 +1,25 @@ | |||
| package com.simple.service.impl; | |||
| import java.util.*; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.IdWorker; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMsg; | |||
| import com.simple.mapper.WxMsgMapper; | |||
| import com.simple.service.WxMsgService; | |||
| import com.simple.utils.AesUtil; | |||
| import com.simple.utils.HMACSHA256; | |||
| import com.simple.utils.HttpUtil; | |||
| import com.simple.utils.RsaUtil; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.simple.common.IdWorker; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import java.util.Set; | |||
| import java.util.TreeMap; | |||
| @Service | |||
| public class WxMsgServiceImpl implements WxMsgService { | |||
| @@ -29,6 +40,54 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| @Override | |||
| public void saveOrUpdate(WxMsg record) { | |||
| String secret="7305150347587283553aa8898e7dbf20"; | |||
| String bid="465565";//通过短信配置数据查询出来 | |||
| String phone="13810135185"; | |||
| String signature="123"; | |||
| String msg="测试"; | |||
| String notifyUrl="http://07d393ee.ngrok.io/receivemsg/"+bid; | |||
| 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="198b02e8fd704e96198b02e8fd704e96"; | |||
| String iv="198b02e8fd704e96"; | |||
| 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(),""); | |||
| 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); | |||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||
| String ret=jsonObjectResult.get("ret").toString(); | |||
| if(ret.equals("1")){ | |||
| System.out.println("发送成功"); | |||
| }else{ | |||
| System.out.println("发送失败"); | |||
| } | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| IdWorker idWorker = new IdWorker(0, 0); | |||
| @@ -43,12 +102,16 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| public void deleteById(Long id) { | |||
| wxMsgMapper.deleteByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public ResultData sendmsgbyexcel(MultipartFile file, WxMsg wxMsg) { | |||
| return null; | |||
| } | |||
| @Override | |||
| public ResultData sendmsgbylabel(WxMsg wxMsg) { | |||
| return null; | |||
| } | |||
| } | |||