//发送方 public static void main(String[] args) { String mobiles = "15810022404"; String content = "发送远程API测试短信。。。"; boolean needReport = true; String xcode="01201112";//01为各平台短信子号,201112为流水号(000000-999999) String uname = "tudou"; content = EncryptUtils.encodeBufferBase64(content.getBytes());// base64编码,防止乱码 String sendtime = DateUtils.getNowTime(); uname = EncryptUtils.encodeBufferBase64(uname.getBytes()); Map<String, Object> map=new HashMap<String, Object>();//使用Map集合 map.put("uname", uname); Send s=new Send(); s.setContent(content); s.setStarttime(DateUtils.parseDate(sendtime)); s.setMobile(mobiles); s.setNeedReport(needReport); s.setXcode(xcode); map.put("data", s);//将对象放入Map String md5 = MD5Utils.getInstance().getMD5ofStr(JSON.toJSONString(s)+MD5Utils.k1); map.put("md5", md5); new SmsSendTest().testSendSms(JSON.toJSONString(map));//直接将Map转换成JSON传递 }接收方:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String json = request.getParameter("json").toString(); JSONObject jo = JSON.parseObject(json); String md5 = jo.getString("md5"); String data = jo.getString("data"); System.out.println(data); Send send = JSON.parseObject(data, Send.class); String content = new String(EncryptUtils.decodeBufferBase64(send .getContent())); String uname = jo.getString("uname"); String upwd = jo.getString("upwd"); uname = new String(EncryptUtils.decodeBufferBase64(uname)); boolean needReport = send.isNeedReport();
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String json = request.getParameter("json").toString(); JSONObject jo = JSON.parseObject(json); String md5 = jo.getString("md5"); String data = jo.getString("data"); System.out.println(data); Send send = JSON.parseObject(data, Send.class); String content = new String(EncryptUtils.decodeBufferBase64(send .getContent())); String uname = jo.getString("uname"); String upwd = jo.getString("upwd"); uname = new String(EncryptUtils.decodeBufferBase64(uname)); boolean needReport = send.isNeedReport();