| @@ -1,19 +1,19 @@ | |||
| package com.simple.controller; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.util.Assert; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMsg; | |||
| import com.simple.service.WxMsgService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("wxMsg") | |||
| @@ -65,7 +65,31 @@ public class WxMsgController extends BaseController | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxMsgService.getById(id)); | |||
| } | |||
| @ApiOperation("短信接口回调") | |||
| @RequestMapping("/receivemsg/{bid}") | |||
| public void receivemsg(@PathVariable String bid,@RequestParam Map<String,String> param) { | |||
| //解析param数据插入数据库中 | |||
| } | |||
| @RequestMapping("/sendmsgbyexcel") | |||
| public ResultData sendmsgbyexcel(@RequestParam("file") MultipartFile file,@RequestBody WxMsg wxMsg) throws Exception { | |||
| if (file.isEmpty()) { | |||
| return new ResultData(Result.SUCCESS,"上传文件不能为空"); | |||
| } | |||
| return wxMsgService.sendmsgbyexcel(file,wxMsg); | |||
| } | |||
| @RequestMapping("/sendmsgbylabel") | |||
| public ResultData sendmsgbylabel(@RequestBody WxMsg wxMsg) throws Exception { | |||
| return wxMsgService.sendmsgbylabel(wxMsg); | |||
| } | |||
| } | |||
| @@ -1,19 +1,16 @@ | |||
| package com.simple.controller; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.util.Assert; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMsgModel; | |||
| import com.simple.service.WxMsgModelService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| @RestController | |||
| @RequestMapping("wxMsgModel") | |||
| @@ -40,15 +37,13 @@ public class WxMsgModelController extends BaseController | |||
| public ResultData add(@RequestBody WxMsgModel wxMsgModel) { | |||
| //Assert.notNull(wxMsgModel.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| wxMsgModelService.saveOrUpdate(wxMsgModel); | |||
| return new ResultData(); | |||
| return wxMsgModelService.saveOrUpdate(wxMsgModel); | |||
| } | |||
| @ApiOperation("根据id更新接口") | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxMsgModel wxMsgModel) { | |||
| wxMsgModelService.saveOrUpdate(wxMsgModel); | |||
| return new ResultData(); | |||
| return wxMsgModelService.saveOrUpdate(wxMsgModel); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @@ -65,7 +60,7 @@ public class WxMsgModelController extends BaseController | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxMsgModelService.getById(id)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,102 @@ | |||
| package com.simple.utils; | |||
| import org.bouncycastle.jce.provider.BouncyCastleProvider; | |||
| import org.bouncycastle.util.encoders.Base64; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import javax.crypto.Cipher; | |||
| import javax.crypto.spec.IvParameterSpec; | |||
| import javax.crypto.spec.SecretKeySpec; | |||
| import java.security.Key; | |||
| import java.security.Security; | |||
| import java.util.Arrays; | |||
| public class AesUtil { | |||
| private static final Logger logger = LoggerFactory.getLogger(AesUtil.class); | |||
| /** | |||
| * 加密 | |||
| * 模式:AES/CBC/PKCS7Padding | |||
| * | |||
| * @param encodeRules 秘钥 | |||
| * @param content 加密串 | |||
| * @return | |||
| */ | |||
| public static String AESEncode(String encodeRules, String content, String ivParameter) throws Exception { | |||
| int base = 16; | |||
| byte[] keybyte = encodeRules.getBytes("UTF-8"); | |||
| if (keybyte.length % base != 0) { | |||
| int groups = keybyte.length / base + (keybyte.length % base != 0 ? 1 : 0); | |||
| byte[] temp = new byte[groups * base]; | |||
| Arrays.fill(temp, (byte) 0); | |||
| System.arraycopy(keybyte, 0, temp, 0, keybyte.length); | |||
| keybyte = temp; | |||
| } | |||
| // 初始化 | |||
| Security.addProvider(new BouncyCastleProvider()); | |||
| // 转化成JAVA的密钥格式 | |||
| Key key = new SecretKeySpec(keybyte, "AES"); | |||
| try | |||
| { | |||
| // 初始化cipher | |||
| Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); | |||
| cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(ivParameter.getBytes())); | |||
| byte[] encryptedText = cipher.doFinal(content.getBytes()); | |||
| return new String(new Base64().encode(encryptedText)).replaceAll("\r\n", ""); | |||
| } catch ( | |||
| Exception e) | |||
| { | |||
| logger.info("AESEncode error", e); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 解密 | |||
| * | |||
| * @param encodeRules 秘钥 | |||
| * @param content 解密串 | |||
| * @return | |||
| */ | |||
| public static String AESDecode(String encodeRules, String content, String ivParameter) throws Exception { | |||
| try { | |||
| // 判断Key是否正确 | |||
| if (encodeRules == null) { | |||
| logger.info("Key为空null"); | |||
| return null; | |||
| } | |||
| // 判断Key是否为16位 | |||
| if (encodeRules.length() != 16) { | |||
| logger.info("Key长度不是16位"); | |||
| return null; | |||
| } | |||
| byte[] raw = encodeRules.getBytes("UTF-8"); | |||
| Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); | |||
| SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); | |||
| Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); | |||
| IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes()); | |||
| cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); | |||
| try { | |||
| byte[] encrypted1 = new Base64().decode(content);//先用base64解密 | |||
| byte[] original = cipher.doFinal(encrypted1); | |||
| String originalString = new String(original); | |||
| return originalString; | |||
| } catch (Exception e) { | |||
| logger.info(e.toString()); | |||
| return null; | |||
| } | |||
| } catch (Exception ex) { | |||
| logger.info(ex.toString()); | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,36 @@ | |||
| package com.simple.utils; | |||
| import javax.crypto.Mac; | |||
| import javax.crypto.spec.SecretKeySpec; | |||
| public class HMACSHA256 { | |||
| public static String byteArrayToHexString(byte[] b) { | |||
| StringBuilder hs = new StringBuilder(); | |||
| String stmp; | |||
| for (int n = 0; b != null && n < b.length; n++) { | |||
| stmp = Integer.toHexString(b[n] & 0XFF); | |||
| if (stmp.length() == 1) | |||
| hs.append('0'); | |||
| hs.append(stmp); | |||
| } | |||
| return hs.toString().toLowerCase(); | |||
| } | |||
| public static String sha256_HMAC(String message, String secret) { | |||
| String hash = ""; | |||
| try { | |||
| Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); | |||
| SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256"); | |||
| sha256_HMAC.init(secret_key); | |||
| byte[] bytes = sha256_HMAC.doFinal(message.getBytes()); | |||
| hash = byteArrayToHexString(bytes); | |||
| System.out.println(hash); | |||
| } catch (Exception e) { | |||
| System.out.println("Error HmacSHA256 ===========" + e.getMessage()); | |||
| } | |||
| return hash; | |||
| } | |||
| } | |||
| @@ -0,0 +1,167 @@ | |||
| package com.simple.utils; | |||
| import org.apache.http.*; | |||
| import org.apache.http.client.HttpClient; | |||
| import org.apache.http.client.entity.UrlEncodedFormEntity; | |||
| import org.apache.http.client.methods.CloseableHttpResponse; | |||
| import org.apache.http.client.methods.HttpGet; | |||
| import org.apache.http.client.methods.HttpPost; | |||
| import org.apache.http.entity.StringEntity; | |||
| import org.apache.http.impl.client.CloseableHttpClient; | |||
| import org.apache.http.impl.client.DefaultHttpClient; | |||
| import org.apache.http.impl.client.HttpClients; | |||
| import org.apache.http.message.BasicNameValuePair; | |||
| import org.apache.http.protocol.HTTP; | |||
| import org.apache.http.util.EntityUtils; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStreamReader; | |||
| import java.net.URI; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.logging.Logger; | |||
| /** | |||
| * @author | |||
| * @date | |||
| * HttpClient工具类 | |||
| */ | |||
| public class HttpUtil { | |||
| private static Logger logger = Logger.getLogger(String.valueOf(HttpUtil.class)); | |||
| /** | |||
| * get请求 | |||
| * @return | |||
| */ | |||
| public static String doGet(String url) { | |||
| try { | |||
| HttpClient client = new DefaultHttpClient(); | |||
| //发送get请求 | |||
| HttpGet request = new HttpGet(url); | |||
| HttpResponse response = client.execute(request); | |||
| /**请求发送成功,并得到响应**/ | |||
| if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { | |||
| /**读取服务器返回过来的json字符串数据**/ | |||
| String strResult = EntityUtils.toString(response.getEntity()); | |||
| return strResult; | |||
| } | |||
| } | |||
| catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * post请求(用于key-value格式的参数) | |||
| * @param url | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String doPost(String url, Map params){ | |||
| BufferedReader in = null; | |||
| try { | |||
| // 定义HttpClient | |||
| HttpClient client = new DefaultHttpClient(); | |||
| // 实例化HTTP方法 | |||
| HttpPost request = new HttpPost(); | |||
| request.setURI(new URI(url)); | |||
| //设置参数 | |||
| List<NameValuePair> nvps = new ArrayList<NameValuePair>(); | |||
| for (Iterator iter = params.keySet().iterator(); iter.hasNext();) { | |||
| String name = (String) iter.next(); | |||
| String value = String.valueOf(params.get(name)); | |||
| nvps.add(new BasicNameValuePair(name, value)); | |||
| //System.out.println(name +"-"+value); | |||
| } | |||
| request.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8)); | |||
| HttpResponse response = client.execute(request); | |||
| int code = response.getStatusLine().getStatusCode(); | |||
| if(code == 200){ //请求成功 | |||
| in = new BufferedReader(new InputStreamReader(response.getEntity() | |||
| .getContent(),"utf-8")); | |||
| StringBuffer sb = new StringBuffer(""); | |||
| String line = ""; | |||
| String NL = System.getProperty("line.separator"); | |||
| while ((line = in.readLine()) != null) { | |||
| sb.append(line + NL); | |||
| } | |||
| in.close(); | |||
| return sb.toString(); | |||
| } | |||
| else{ // | |||
| System.out.println("状态码:" + code); | |||
| return null; | |||
| } | |||
| } | |||
| catch(Exception e){ | |||
| e.printStackTrace(); | |||
| return null; | |||
| } | |||
| } | |||
| /** | |||
| * post请求(用于请求json格式的参数) | |||
| * @param url | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String doPost(String url, String params) throws Exception { | |||
| CloseableHttpClient httpclient = HttpClients.createDefault(); | |||
| HttpPost httpPost = new HttpPost(url);// 创建httpPost | |||
| httpPost.setHeader("Accept", "application/json"); | |||
| httpPost.setHeader("Content-Type", "application/json"); | |||
| String charSet = "UTF-8"; | |||
| StringEntity entity = new StringEntity(params, charSet); | |||
| httpPost.setEntity(entity); | |||
| CloseableHttpResponse response = null; | |||
| try { | |||
| response = httpclient.execute(httpPost); | |||
| StatusLine status = response.getStatusLine(); | |||
| int state = status.getStatusCode(); | |||
| if (state == HttpStatus.SC_OK) { | |||
| HttpEntity responseEntity = response.getEntity(); | |||
| String jsonString = EntityUtils.toString(responseEntity); | |||
| return jsonString; | |||
| } | |||
| else{ | |||
| logger.info("请求返回:"+state+"("+url+")"); | |||
| } | |||
| } | |||
| finally { | |||
| if (response != null) { | |||
| try { | |||
| response.close(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| try { | |||
| httpclient.close(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,63 @@ | |||
| package com.simple.utils; | |||
| import org.apache.commons.codec.binary.Base64; | |||
| import javax.crypto.Cipher; | |||
| import java.io.ByteArrayOutputStream; | |||
| import java.security.Key; | |||
| import java.security.KeyFactory; | |||
| import java.security.spec.X509EncodedKeySpec; | |||
| public class RsaUtil { | |||
| public static final String KEY_ALGORITHM = "RSA"; | |||
| public static final String PUBLIC_KEY = //"-----BEGIN PUBLIC KEY-----" + | |||
| "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvh8j/zagfxQdnSh5OIic" + | |||
| "MzN+MuRuWQJPjgu4Gza4+gX3j5Ln2xNDBOTjpwyuLBjh/JcBd1cGO3lAaKCwcaix" + | |||
| "smhTq56wVXXUMgDiAChu4ud8FSvRc8G8tdZAirKVAIi3NW+/pYgpWBs/0wnF8hz4" + | |||
| "8no4pyJHl9Jc1LH3VNIMz8vqzKUPc4ack4pFUXlcNj6C+sBlaurmI4/vwLqNxBGs" + | |||
| "7/zyM7dv6oy3DSU/Y1qBArM1YPjfL2dNun8rmtPgJvlPwXqA7uoHPwQ2Ym3aUn59" + | |||
| "pkS7QI6IE8uuqNkfSte8BXLd2nIqPLFxLYLDmdll7eoyRblHcHqAYSj8stK6StC7" + | |||
| "DNryNKEjTEwbgf9trUI0uvF1pfgTy2gpclnY69FtD/m0+FvLyorMq+nmBqYMjka5" + | |||
| "K0txDQJPOa7gsi//uXd/cJW2SAXY9MSO1AfMi8Xq/YKRQzN9FW5iapskXFHca7uX" + | |||
| "g5NhH7flr6DW+QInFlpoN6WIEAuDF1aj4O49Ikm3WxwhTqnvEkdSCfivpYQkp9Sh" + | |||
| "4kQ/SQdxuT7VX+Nz6k+uMx2z4cySk33bHi0KoHbA9QFGg/54Qd0+eU4qZnd4mrgh" + | |||
| "hH7/QQhL7Z9eF1U5UPrsHq2Vq3rEnN+tYQ26AuKeU8vzTxBrC/SxC6C/SMFt3f/Y" + | |||
| "nuFh1UnNJZleZwyQt+ZdGO0CAwEAAQ=="; | |||
| //"-----END PUBLIC KEY-----"; | |||
| private static final int MAX_ENCRYPT_BLOCK = 117; | |||
| public static String RSAEncode(byte[] data, String publickey) | |||
| throws Exception { | |||
| byte[] keyBytes = Base64.decodeBase64(publickey); | |||
| X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); | |||
| KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); | |||
| Key publicK = keyFactory.generatePublic(x509KeySpec); | |||
| // 对数据加密 | |||
| Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); | |||
| cipher.init(Cipher.ENCRYPT_MODE, publicK); | |||
| int inputLen = data.length; | |||
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | |||
| int offSet = 0; | |||
| byte[] cache; | |||
| int i = 0; | |||
| // 对数据分段加密 | |||
| while (inputLen - offSet > 0) { | |||
| if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { | |||
| cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); | |||
| } else { | |||
| cache = cipher.doFinal(data, offSet, inputLen - offSet); | |||
| } | |||
| out.write(cache, 0, cache.length); | |||
| i++; | |||
| offSet = i * MAX_ENCRYPT_BLOCK; | |||
| } | |||
| byte[] encryptedData = out.toByteArray(); | |||
| out.close(); | |||
| return Base64.encodeBase64String(encryptedData); | |||
| } | |||
| } | |||
| @@ -1,12 +1,11 @@ | |||
| package com.simple.domain.po; | |||
| import javax.persistence.*; | |||
| import java.util.*; | |||
| import java.math.*; | |||
| import javax.persistence.Transient; | |||
| import java.util.List; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Table(name = "wx_msg") | |||
| public class WxMsg implements Serializable { | |||
| @@ -69,8 +68,24 @@ public class WxMsg implements Serializable { | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="returnResult") | |||
| private String returnResult; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="phones") | |||
| @io.swagger.annotations.ApiModelProperty(value="手机号",name="phones") | |||
| private String phones; | |||
| @io.swagger.annotations.ApiModelProperty(value="签名",name="signature") | |||
| private String signature; | |||
| @io.swagger.annotations.ApiModelProperty(value="短信名称",name="name") | |||
| private String name; | |||
| @io.swagger.annotations.ApiModelProperty(value="是否立即发送",name="isright") | |||
| private Integer isright; | |||
| @io.swagger.annotations.ApiModelProperty(value="标签人群",name="label") | |||
| private String label; | |||
| @io.swagger.annotations.ApiModelProperty(value="发送状态",name="sendstatus") | |||
| private Integer sendstatus; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| @@ -132,7 +147,45 @@ public class WxMsg implements Serializable { | |||
| phones = _phones; | |||
| } | |||
| public String getSignature() { | |||
| return signature; | |||
| } | |||
| public void setSignature(String signature) { | |||
| this.signature = signature; | |||
| } | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| public void setName(String name) { | |||
| this.name = name; | |||
| } | |||
| public Integer getIsright() { | |||
| return isright; | |||
| } | |||
| public void setIsright(Integer isright) { | |||
| this.isright = isright; | |||
| } | |||
| public String getLabel() { | |||
| return label; | |||
| } | |||
| public void setLabel(String label) { | |||
| this.label = label; | |||
| } | |||
| public Integer getSendstatus() { | |||
| return sendstatus; | |||
| } | |||
| public void setSendstatus(Integer sendstatus) { | |||
| this.sendstatus = sendstatus; | |||
| } | |||
| public static enum Field | |||
| { | |||
| @@ -0,0 +1,189 @@ | |||
| package com.simple.domain.po; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Table(name = "wx_msg_callback") | |||
| public class WxMsgCallback implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected String id; | |||
| @Transient | |||
| protected List<String> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| public String getId() { | |||
| return id; | |||
| } | |||
| public void setId(String id) { | |||
| this.id = id; | |||
| } | |||
| public String getSortColumns() { | |||
| return sortColumns; | |||
| } | |||
| public List<String> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| this.ids = ids; | |||
| } | |||
| /*租户id**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户id",name="tenantId") | |||
| private String tenantId; | |||
| /*批次号**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="批次号",name="batchNo") | |||
| private String batchNo; | |||
| /*手机号**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="手机号",name="phone") | |||
| private String phone; | |||
| /*发送时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="发送时间",name="begintime") | |||
| private Integer begintime; | |||
| /*结束时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="结束时间",name="endtime") | |||
| private Integer endtime; | |||
| /*发送状态**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="发送状态",name="status") | |||
| private Integer status; | |||
| /*发送状态信息**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="发送状态信息",name="statusMsg") | |||
| private String statusMsg; | |||
| /*签名**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="签名",name="sign") | |||
| private String sign; | |||
| /*创建时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createtime") | |||
| private Date createtime; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String _tenantId) { | |||
| tenantId = _tenantId; | |||
| } | |||
| public String getBatchNo() { | |||
| return batchNo; | |||
| } | |||
| public void setBatchNo(String _batchNo) { | |||
| batchNo = _batchNo; | |||
| } | |||
| public String getPhone() { | |||
| return phone; | |||
| } | |||
| public void setPhone(String _phone) { | |||
| phone = _phone; | |||
| } | |||
| public Integer getBegintime() { | |||
| return begintime; | |||
| } | |||
| public void setBegintime(Integer _begintime) { | |||
| begintime = _begintime; | |||
| } | |||
| public Integer getEndtime() { | |||
| return endtime; | |||
| } | |||
| public void setEndtime(Integer _endtime) { | |||
| endtime = _endtime; | |||
| } | |||
| public Integer getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(Integer _status) { | |||
| status = _status; | |||
| } | |||
| public String getStatusMsg() { | |||
| return statusMsg; | |||
| } | |||
| public void setStatusMsg(String _statusMsg) { | |||
| statusMsg = _statusMsg; | |||
| } | |||
| public String getSign() { | |||
| return sign; | |||
| } | |||
| public void setSign(String _sign) { | |||
| sign = _sign; | |||
| } | |||
| public Date getCreatetime() { | |||
| return createtime; | |||
| } | |||
| public void setCreatetime(Date _createtime) { | |||
| createtime = _createtime; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | |||
| ,BatchNo_ASC("`batchNo` ASC"),BatchNo_DESC("`batchNo` DESC") | |||
| ,Phone_ASC("`phone` ASC"),Phone_DESC("`phone` DESC") | |||
| ,Begintime_ASC("`begintime` ASC"),Begintime_DESC("`begintime` DESC") | |||
| ,Endtime_ASC("`endtime` ASC"),Endtime_DESC("`endtime` DESC") | |||
| ,Status_ASC("`status` ASC"),Status_DESC("`status` DESC") | |||
| ,StatusMsg_ASC("`statusMsg` ASC"),StatusMsg_DESC("`statusMsg` DESC") | |||
| ,Sign_ASC("`sign` ASC"),Sign_DESC("`sign` DESC") | |||
| ,Createtime_ASC("`createtime` ASC"),Createtime_DESC("`createtime` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| this.value = value; | |||
| } | |||
| public String getValue() { | |||
| return value; | |||
| } | |||
| public void setCol(String value) { | |||
| this.value = value; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return this.getValue(); | |||
| } | |||
| } | |||
| public void setSortColumns(Field... fields) | |||
| { | |||
| if (fields == null || fields.length == 0) { | |||
| return; | |||
| } | |||
| for (int k = 0; k < fields.length; k++) { | |||
| if (fields[k] == null) { | |||
| return; | |||
| } | |||
| } | |||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||
| for (int k = 1; k < fields.length; k++) { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| return; | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| List<Field> fList = new ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(Field.valueOf(cols[k])); | |||
| } | |||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||
| } else { | |||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,102 @@ | |||
| package com.simple.utils; | |||
| import org.bouncycastle.jce.provider.BouncyCastleProvider; | |||
| import org.bouncycastle.util.encoders.Base64; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import javax.crypto.Cipher; | |||
| import javax.crypto.spec.IvParameterSpec; | |||
| import javax.crypto.spec.SecretKeySpec; | |||
| import java.security.Key; | |||
| import java.security.Security; | |||
| import java.util.Arrays; | |||
| public class AesUtil { | |||
| private static final Logger logger = LoggerFactory.getLogger(AesUtil.class); | |||
| /** | |||
| * 加密 | |||
| * 模式:AES/CBC/PKCS7Padding | |||
| * | |||
| * @param encodeRules 秘钥 | |||
| * @param content 加密串 | |||
| * @return | |||
| */ | |||
| public static String AESEncode(String encodeRules, String content, String ivParameter) throws Exception { | |||
| int base = 16; | |||
| byte[] keybyte = encodeRules.getBytes("UTF-8"); | |||
| if (keybyte.length % base != 0) { | |||
| int groups = keybyte.length / base + (keybyte.length % base != 0 ? 1 : 0); | |||
| byte[] temp = new byte[groups * base]; | |||
| Arrays.fill(temp, (byte) 0); | |||
| System.arraycopy(keybyte, 0, temp, 0, keybyte.length); | |||
| keybyte = temp; | |||
| } | |||
| // 初始化 | |||
| Security.addProvider(new BouncyCastleProvider()); | |||
| // 转化成JAVA的密钥格式 | |||
| Key key = new SecretKeySpec(keybyte, "AES"); | |||
| try | |||
| { | |||
| // 初始化cipher | |||
| Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); | |||
| cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(ivParameter.getBytes())); | |||
| byte[] encryptedText = cipher.doFinal(content.getBytes()); | |||
| return new String(new Base64().encode(encryptedText)).replaceAll("\r\n", ""); | |||
| } catch ( | |||
| Exception e) | |||
| { | |||
| logger.info("AESEncode error", e); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 解密 | |||
| * | |||
| * @param encodeRules 秘钥 | |||
| * @param content 解密串 | |||
| * @return | |||
| */ | |||
| public static String AESDecode(String encodeRules, String content, String ivParameter) throws Exception { | |||
| try { | |||
| // 判断Key是否正确 | |||
| if (encodeRules == null) { | |||
| logger.info("Key为空null"); | |||
| return null; | |||
| } | |||
| // 判断Key是否为16位 | |||
| if (encodeRules.length() != 16) { | |||
| logger.info("Key长度不是16位"); | |||
| return null; | |||
| } | |||
| byte[] raw = encodeRules.getBytes("UTF-8"); | |||
| Security.addProvider(new BouncyCastleProvider()); | |||
| SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); | |||
| Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); | |||
| IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes()); | |||
| cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); | |||
| try { | |||
| byte[] encrypted1 = new Base64().decode(content);//先用base64解密 | |||
| byte[] original = cipher.doFinal(encrypted1); | |||
| String originalString = new String(original); | |||
| return originalString; | |||
| } catch (Exception e) { | |||
| logger.info(e.toString()); | |||
| return null; | |||
| } | |||
| } catch (Exception ex) { | |||
| logger.info(ex.toString()); | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,36 @@ | |||
| package com.simple.utils; | |||
| import javax.crypto.Mac; | |||
| import javax.crypto.spec.SecretKeySpec; | |||
| public class HMACSHA256 { | |||
| public static String byteArrayToHexString(byte[] b) { | |||
| StringBuilder hs = new StringBuilder(); | |||
| String stmp; | |||
| for (int n = 0; b != null && n < b.length; n++) { | |||
| stmp = Integer.toHexString(b[n] & 0XFF); | |||
| if (stmp.length() == 1) | |||
| hs.append('0'); | |||
| hs.append(stmp); | |||
| } | |||
| return hs.toString().toLowerCase(); | |||
| } | |||
| public static String sha256_HMAC(String message, String secret) { | |||
| String hash = ""; | |||
| try { | |||
| Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); | |||
| SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256"); | |||
| sha256_HMAC.init(secret_key); | |||
| byte[] bytes = sha256_HMAC.doFinal(message.getBytes()); | |||
| hash = byteArrayToHexString(bytes); | |||
| System.out.println(hash); | |||
| } catch (Exception e) { | |||
| System.out.println("Error HmacSHA256 ===========" + e.getMessage()); | |||
| } | |||
| return hash; | |||
| } | |||
| } | |||
| @@ -0,0 +1,167 @@ | |||
| package com.simple.utils; | |||
| import org.apache.http.*; | |||
| import org.apache.http.client.HttpClient; | |||
| import org.apache.http.client.entity.UrlEncodedFormEntity; | |||
| import org.apache.http.client.methods.CloseableHttpResponse; | |||
| import org.apache.http.client.methods.HttpGet; | |||
| import org.apache.http.client.methods.HttpPost; | |||
| import org.apache.http.entity.StringEntity; | |||
| import org.apache.http.impl.client.CloseableHttpClient; | |||
| import org.apache.http.impl.client.DefaultHttpClient; | |||
| import org.apache.http.impl.client.HttpClients; | |||
| import org.apache.http.message.BasicNameValuePair; | |||
| import org.apache.http.protocol.HTTP; | |||
| import org.apache.http.util.EntityUtils; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStreamReader; | |||
| import java.net.URI; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.logging.Logger; | |||
| /** | |||
| * @author | |||
| * @date | |||
| * HttpClient工具类 | |||
| */ | |||
| public class HttpUtil { | |||
| private static Logger logger = Logger.getLogger(String.valueOf(HttpUtil.class)); | |||
| /** | |||
| * get请求 | |||
| * @return | |||
| */ | |||
| public static String doGet(String url) { | |||
| try { | |||
| HttpClient client = new DefaultHttpClient(); | |||
| //发送get请求 | |||
| HttpGet request = new HttpGet(url); | |||
| HttpResponse response = client.execute(request); | |||
| /**请求发送成功,并得到响应**/ | |||
| if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { | |||
| /**读取服务器返回过来的json字符串数据**/ | |||
| String strResult = EntityUtils.toString(response.getEntity()); | |||
| return strResult; | |||
| } | |||
| } | |||
| catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * post请求(用于key-value格式的参数) | |||
| * @param url | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String doPost(String url, Map params){ | |||
| BufferedReader in = null; | |||
| try { | |||
| // 定义HttpClient | |||
| HttpClient client = new DefaultHttpClient(); | |||
| // 实例化HTTP方法 | |||
| HttpPost request = new HttpPost(); | |||
| request.setURI(new URI(url)); | |||
| //设置参数 | |||
| List<NameValuePair> nvps = new ArrayList<NameValuePair>(); | |||
| for (Iterator iter = params.keySet().iterator(); iter.hasNext();) { | |||
| String name = (String) iter.next(); | |||
| String value = String.valueOf(params.get(name)); | |||
| nvps.add(new BasicNameValuePair(name, value)); | |||
| //System.out.println(name +"-"+value); | |||
| } | |||
| request.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8)); | |||
| HttpResponse response = client.execute(request); | |||
| int code = response.getStatusLine().getStatusCode(); | |||
| if(code == 200){ //请求成功 | |||
| in = new BufferedReader(new InputStreamReader(response.getEntity() | |||
| .getContent(),"utf-8")); | |||
| StringBuffer sb = new StringBuffer(""); | |||
| String line = ""; | |||
| String NL = System.getProperty("line.separator"); | |||
| while ((line = in.readLine()) != null) { | |||
| sb.append(line + NL); | |||
| } | |||
| in.close(); | |||
| return sb.toString(); | |||
| } | |||
| else{ // | |||
| System.out.println("状态码:" + code); | |||
| return null; | |||
| } | |||
| } | |||
| catch(Exception e){ | |||
| e.printStackTrace(); | |||
| return null; | |||
| } | |||
| } | |||
| /** | |||
| * post请求(用于请求json格式的参数) | |||
| * @param url | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String doPost(String url, String params) throws Exception { | |||
| CloseableHttpClient httpclient = HttpClients.createDefault(); | |||
| HttpPost httpPost = new HttpPost(url);// 创建httpPost | |||
| httpPost.setHeader("Accept", "application/json"); | |||
| httpPost.setHeader("Content-Type", "application/json"); | |||
| String charSet = "UTF-8"; | |||
| StringEntity entity = new StringEntity(params, charSet); | |||
| httpPost.setEntity(entity); | |||
| CloseableHttpResponse response = null; | |||
| try { | |||
| response = httpclient.execute(httpPost); | |||
| StatusLine status = response.getStatusLine(); | |||
| int state = status.getStatusCode(); | |||
| if (state == HttpStatus.SC_OK) { | |||
| HttpEntity responseEntity = response.getEntity(); | |||
| String jsonString = EntityUtils.toString(responseEntity); | |||
| return jsonString; | |||
| } | |||
| else{ | |||
| logger.info("请求返回:"+state+"("+url+")"); | |||
| } | |||
| } | |||
| finally { | |||
| if (response != null) { | |||
| try { | |||
| response.close(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| try { | |||
| httpclient.close(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,63 @@ | |||
| package com.simple.utils; | |||
| import org.apache.commons.codec.binary.Base64; | |||
| import javax.crypto.Cipher; | |||
| import java.io.ByteArrayOutputStream; | |||
| import java.security.Key; | |||
| import java.security.KeyFactory; | |||
| import java.security.spec.X509EncodedKeySpec; | |||
| public class RsaUtil { | |||
| public static final String KEY_ALGORITHM = "RSA"; | |||
| public static final String PUBLIC_KEY = //"-----BEGIN PUBLIC KEY-----" + | |||
| "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvh8j/zagfxQdnSh5OIic" + | |||
| "MzN+MuRuWQJPjgu4Gza4+gX3j5Ln2xNDBOTjpwyuLBjh/JcBd1cGO3lAaKCwcaix" + | |||
| "smhTq56wVXXUMgDiAChu4ud8FSvRc8G8tdZAirKVAIi3NW+/pYgpWBs/0wnF8hz4" + | |||
| "8no4pyJHl9Jc1LH3VNIMz8vqzKUPc4ack4pFUXlcNj6C+sBlaurmI4/vwLqNxBGs" + | |||
| "7/zyM7dv6oy3DSU/Y1qBArM1YPjfL2dNun8rmtPgJvlPwXqA7uoHPwQ2Ym3aUn59" + | |||
| "pkS7QI6IE8uuqNkfSte8BXLd2nIqPLFxLYLDmdll7eoyRblHcHqAYSj8stK6StC7" + | |||
| "DNryNKEjTEwbgf9trUI0uvF1pfgTy2gpclnY69FtD/m0+FvLyorMq+nmBqYMjka5" + | |||
| "K0txDQJPOa7gsi//uXd/cJW2SAXY9MSO1AfMi8Xq/YKRQzN9FW5iapskXFHca7uX" + | |||
| "g5NhH7flr6DW+QInFlpoN6WIEAuDF1aj4O49Ikm3WxwhTqnvEkdSCfivpYQkp9Sh" + | |||
| "4kQ/SQdxuT7VX+Nz6k+uMx2z4cySk33bHi0KoHbA9QFGg/54Qd0+eU4qZnd4mrgh" + | |||
| "hH7/QQhL7Z9eF1U5UPrsHq2Vq3rEnN+tYQ26AuKeU8vzTxBrC/SxC6C/SMFt3f/Y" + | |||
| "nuFh1UnNJZleZwyQt+ZdGO0CAwEAAQ=="; | |||
| //"-----END PUBLIC KEY-----"; | |||
| private static final int MAX_ENCRYPT_BLOCK = 117; | |||
| public static String RSAEncode(byte[] data, String publickey) | |||
| throws Exception { | |||
| byte[] keyBytes = Base64.decodeBase64(publickey); | |||
| X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); | |||
| KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); | |||
| Key publicK = keyFactory.generatePublic(x509KeySpec); | |||
| // 对数据加密 | |||
| Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); | |||
| cipher.init(Cipher.ENCRYPT_MODE, publicK); | |||
| int inputLen = data.length; | |||
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | |||
| int offSet = 0; | |||
| byte[] cache; | |||
| int i = 0; | |||
| // 对数据分段加密 | |||
| while (inputLen - offSet > 0) { | |||
| if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { | |||
| cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); | |||
| } else { | |||
| cache = cipher.doFinal(data, offSet, inputLen - offSet); | |||
| } | |||
| out.write(cache, 0, cache.length); | |||
| i++; | |||
| offSet = i * MAX_ENCRYPT_BLOCK; | |||
| } | |||
| byte[] encryptedData = out.toByteArray(); | |||
| out.close(); | |||
| return Base64.encodeBase64String(encryptedData); | |||
| } | |||
| } | |||
| @@ -0,0 +1,52 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.simple.mapper.WxMsgCallbackMapper"> | |||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxMsgCallback"> | |||
| <id column="id" jdbcType="INTEGER" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="batch_no" jdbcType="VARCHAR" property="batchNo" /> | |||
| <result column="phone" jdbcType="VARCHAR" property="phone" /> | |||
| <result column="begintime" jdbcType="INTEGER" property="begintime" /> | |||
| <result column="endtime" jdbcType="INTEGER" property="endtime" /> | |||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||
| <result column="status_msg" jdbcType="VARCHAR" property="statusMsg" /> | |||
| <result column="sign" jdbcType="VARCHAR" property="sign" /> | |||
| <result column="createtime" jdbcType="TIMESTAMP" property="createtime" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`batch_no`,`phone`,`begintime`,`endtime`,`status`,`status_msg`,`sign`,`createtime` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> and `id` = #{id} </if> | |||
| <if test=" null != tenantId "> and `tenant_id` = #{tenantId} </if> | |||
| <if test=" null != batchNo "> and `batch_no` = #{batchNo} </if> | |||
| <if test=" null != phone "> and `phone` = #{phone} </if> | |||
| <if test=" null != begintime "> and `begintime` = #{begintime} </if> | |||
| <if test=" null != endtime "> and `endtime` = #{endtime} </if> | |||
| <if test=" null != status "> and `status` = #{status} </if> | |||
| <if test=" null != statusMsg "> and `status_msg` = #{statusMsg} </if> | |||
| <if test=" null != sign "> and `sign` = #{sign} </if> | |||
| <if test=" null != createtime "> and `createtime` = #{createtime} </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.simple.domain.po.WxMsgCallback" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_msg_callback | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||
| @@ -13,10 +13,15 @@ | |||
| <result column="error_number" jdbcType="VARCHAR" property="errorNumber" /> | |||
| <result column="return_result" jdbcType="VARCHAR" property="returnResult" /> | |||
| <result column="phones" jdbcType="VARCHAR" property="phones" /> | |||
| <result column="signature" jdbcType="VARCHAR" property="signature" /> | |||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||
| <result column="isright" jdbcType="SMALLINT" property="isright" /> | |||
| <result column="sendstatus" jdbcType="SMALLINT" property="sendstatus" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`model_id`,`msg`,`sendtime`,`createtime`,`expect_send_number`,`success_number`,`error_number`,`return_result`,`phones` | |||
| `id`,`tenant_id`,`model_id`,`msg`,`sendtime`,`createtime`,`expect_send_number`,`success_number`,`error_number`,`return_result`,`phones`,`signature`,`name`,`isright`,`sendstatus` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -75,7 +80,22 @@ | |||
| <if test=" null != phones "> | |||
| and `phones` like concat('%', #{phones},'%') | |||
| </if> | |||
| </if> | |||
| <if test=" null != signature "> | |||
| and `signature`=#{signature} | |||
| </if> | |||
| <if test=" null != name "> | |||
| and `name`=#{name} | |||
| </if> | |||
| <if test=" null != isright "> | |||
| and `isright`=#{isright} | |||
| </if> | |||
| <if test=" null != sendstatus "> | |||
| and `sendstatus`=#{sendstatus} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||