|
@@ -0,0 +1,224 @@
|
|
|
+package com.sms.sms;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.OutputStreamWriter;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.DriverManager;
|
|
|
+import java.sql.Statement;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.servlet.ServletException;
|
|
|
+import javax.servlet.http.HttpServlet;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.client.ClientProtocolException;
|
|
|
+import org.apache.http.client.HttpClient;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+public class LsSMS extends HttpServlet{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param args
|
|
|
+ */
|
|
|
+ /*public static void main(String[] args) {
|
|
|
+ SMS s=new SMS();
|
|
|
+ s.Smsending();
|
|
|
+ }*/
|
|
|
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
+ throws ServletException, IOException {
|
|
|
+ this.doPost(request, response);
|
|
|
+ }
|
|
|
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
|
+ throws ServletException, IOException {
|
|
|
+ response.setContentType("text/html;charset=utf-8");
|
|
|
+ request.setCharacterEncoding("utf-8");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String phone=request.getParameter("phone");
|
|
|
+ String content=request.getParameter("content");
|
|
|
+ //接口地址
|
|
|
+ String url = "http://smssh1.253.com/msg/send/json";
|
|
|
+ //下发时间
|
|
|
+ String mttime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
|
|
+ Map<String,String> param = new HashMap<String,String>();
|
|
|
+ param.put("account","N6515600");
|
|
|
+ param.put("password", "wyIYk5oAp41883");
|
|
|
+ try {
|
|
|
+ param.put("msg", "【鼎昱科技】您有一个待办事宜请及时处理!");
|
|
|
+ //param.put("msg", content);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ param.put("phone", phone);
|
|
|
+ //param.put("subid","01");
|
|
|
+ //param.put("mttime", mttime);
|
|
|
+ //param.put("rpttype", "1");
|
|
|
+ String result = sendPost(url,param);
|
|
|
+ //返回值类型{"ReqCode":"00","ReqMsg":"提交成功","ReqId":"180424144746103010100003"}
|
|
|
+ result=result.replaceAll("\\{", "");
|
|
|
+ result=result.replaceAll("\\}", "");
|
|
|
+ result=result.replaceAll("\"", "");
|
|
|
+ String[] resultz= result.split(",");
|
|
|
+ String reqcode=resultz[0].split(":")[1];
|
|
|
+ String reqmsg=resultz[1].split(":")[1];
|
|
|
+ String reqid=resultz[2].split(":")[1];
|
|
|
+
|
|
|
+ System.out.println(result);
|
|
|
+ //this.doPost(request, response);
|
|
|
+ JavaJdbc(phone,content,mttime,reqcode,reqmsg,reqid);
|
|
|
+ }
|
|
|
+ //链接mysql数据库并写入值关闭链接
|
|
|
+ public static void JavaJdbc(String phone,String content,String mttime,String reqcode,String reqmsg,String reqid){
|
|
|
+ String driver = "com.mysql.jdbc.Driver";
|
|
|
+ // URL指向要访问的数据库名scutcs
|
|
|
+ String url = "jdbc:mysql://localhost:3306/sms";
|
|
|
+ // MySQL配置时的用户名
|
|
|
+ String user = "root";
|
|
|
+ // MySQL配置时的密码
|
|
|
+ String password = "root";
|
|
|
+ Date d = new Date();
|
|
|
+ try {
|
|
|
+ // 加载驱动程序
|
|
|
+ Class.forName(driver);
|
|
|
+ // 连续数据库
|
|
|
+ Connection conn = DriverManager.getConnection(url, user, password);
|
|
|
+ if(!conn.isClosed())
|
|
|
+ System.out.println("Succeeded connecting to the Database!");
|
|
|
+ // statement用来执行SQL语句
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ // 要执行的SQL语句
|
|
|
+ String sql="insert into sms values ('"+phone+"','"+mttime+"','"+reqcode+"','"+reqmsg+"','"+reqid+"','"+content+"')";
|
|
|
+ statement.executeUpdate(sql);
|
|
|
+ conn.close();
|
|
|
+ } catch(ClassNotFoundException e) {
|
|
|
+ System.out.println("Sorry,can`t find the Driver!");
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch(Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ //接口地址
|
|
|
+ String url = "http://58.244.255.111:81/cns-bmfw-web/rest/szxxrest/addCaseInfo";
|
|
|
+ //下发时间
|
|
|
+ //String mttime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
|
|
+ Map<String,String> param = new HashMap<String,String>();
|
|
|
+ //param.put("account","N6515600");
|
|
|
+ //param.put("password", "wyIYk5oAp41883");
|
|
|
+ try {
|
|
|
+ //param.put("msg", "【鼎昱科技】您有一个待办事宜请及时处理!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //param.put("phone", "15044409703");
|
|
|
+ param.put("token", "Epoint_WebSerivce_**##0601");
|
|
|
+ param.put("params", "{rqstTitle+:1,rqstPerson:1,linkNumber:1,rqstAddress:1,rqstContent:1}");
|
|
|
+
|
|
|
+ String result = sendPost(url,param);
|
|
|
+ result=result.replaceAll("\\{", "");
|
|
|
+ result=result.replaceAll("\\}", "");
|
|
|
+ result=result.replaceAll("\"", "");
|
|
|
+ String[] resultz= result.split(",");
|
|
|
+ String reqcode=resultz[0].split(":")[1];
|
|
|
+ System.out.println(resultz);
|
|
|
+
|
|
|
+ }
|
|
|
+ public static String sendPost(String url,Map<String,String> params) {
|
|
|
+ URL u = null;
|
|
|
+ HttpURLConnection con = null;
|
|
|
+ //构建请求参数
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ StringBuffer sb1 = new StringBuffer();
|
|
|
+ if(params != null) {
|
|
|
+ for(java.util.Map.Entry<String,String> e : params.entrySet()) {
|
|
|
+ sb.append("\""+e.getKey()+"\""+":"+"\""+e.getValue()+"\""+",");
|
|
|
+ // sb.append(e.getKey()).append("'").append(e.getValue()).append("'");
|
|
|
+ }
|
|
|
+ //sb.substring(0,sb.length() - 1);
|
|
|
+ sb.deleteCharAt(sb.length()-1);
|
|
|
+ sb.insert(0,"{");
|
|
|
+ sb.append("}");
|
|
|
+ sb1.append("{\"token\":\"Epoint_WebSerivce_**##0601\",\"params\": {\"rqstTitle\": \"测试接口题目\",\"rqstPerson\": \"登记人\",\"linkNumber\": \"123\",\"rqstAddress\": \"地址\",\"rqstContent\": \"诉求内容\"}}");
|
|
|
+ }
|
|
|
+ //尝试发送请求
|
|
|
+ try {
|
|
|
+ u = new URL(url);
|
|
|
+ con = (HttpURLConnection) u.openConnection();
|
|
|
+ con.setRequestMethod("POST");
|
|
|
+ con.setConnectTimeout(6000);
|
|
|
+ con.setDoOutput(true);
|
|
|
+ con.setDoInput(true);
|
|
|
+ con.setUseCaches(false);
|
|
|
+ //con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
|
+ con.setRequestProperty("Content-Type", "application/json");
|
|
|
+ OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream(),"UTF-8");
|
|
|
+ osw.write(sb1.toString());
|
|
|
+ osw.flush();
|
|
|
+ osw.close();
|
|
|
+ }catch(Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if(con != null) {
|
|
|
+ con.disconnect();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //读取返回内容
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ try {
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
|
|
|
+ String temp;
|
|
|
+ while ((temp = br.readLine()) != null) {
|
|
|
+ buffer.append(temp).append("\n");
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(buffer);
|
|
|
+ return buffer.toString();
|
|
|
+ }
|
|
|
+ public static String MD51(String str) {
|
|
|
+ MessageDigest md5 = null;
|
|
|
+ try {
|
|
|
+ md5 = MessageDigest.getInstance("MD5");
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ char[] charArray = str.toCharArray();
|
|
|
+ byte[] byteArray = new byte[charArray.length];
|
|
|
+ for(int i = 0;i < charArray.length;i++)
|
|
|
+ byteArray[i] = (byte) charArray[i];
|
|
|
+ byte[] md5Bytes = md5.digest(byteArray);
|
|
|
+ StringBuffer hexValue = new StringBuffer();
|
|
|
+ for(int i = 0; i < md5Bytes.length;i++) {
|
|
|
+ int val = ((int) md5Bytes[i]) & 0xff;
|
|
|
+ if(val < 16) {
|
|
|
+ hexValue.append("0");
|
|
|
+ }
|
|
|
+ hexValue.append(Integer.toHexString(val));
|
|
|
+ }
|
|
|
+ return hexValue.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|