1 public class MessageSendUtil { 2 /** 3 * @param args 4 * @throws IOException 5 */ 6 public static boolean handleMsg(String phoneNo,int num,String message)throws Exception { 7 boolean sendFlag = false; 8 // 发送内容 9 String content=null; 10 if (num==1) { 11 content = "您申请的商户已通过审核【窝便利】"; 12 }else if (num==2) { 13 content= "您申请的商户未过审核!【窝便利】"; 14 }else if(num==3) 15 { 16 content= "您的验证码为"+message+"【窝便利】"; 17 } 18 else if(num==5) 19 { 20 content= ""+message+"【窝便利】"; 21 } 22 else 23 { 24 content= message+"【窝便利】"; 25 } 26 //String content = new String(sendInfo.getBytes( "UTF-8")); 27 System.out.println(content); 28 // 创建StringBuffer对象用来操作字符串 29 StringBuffer sb = new StringBuffer("http://http.yunsms.cn/tx/?"); 30 31 // 向StringBuffer追加用户名 32 sb.append("uid="); 33 34 // 向StringBuffer追加密码(密码采用MD5 32位 小写) 35 String a=""; 36 sb.append("&pwd="+Md5PasswordEncoder.encode(a)+""); 37 38 // 向StringBuffer追加手机号码 39 sb.append("&mobile="+phoneNo+""); 40 //sb.append("&encode=utf8"); 41 // 向StringBuffer追加消息内容转URL标准码 42 sb.append("&content=" + content); 43 // System.out.println(sb.toString()); 44 // 创建url对象 45 URL url = new URL(sb.toString()); 46 47 // 打开url连接 48 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 49 50 // 设置url请求方式 ‘get’ 或者 ‘post’ 51 connection.setRequestMethod("POST"); 52 53 // 发送 54 BufferedReader in = new BufferedReader(new InputStreamReader( 55 url.openStream())); 56 57 // 返回发送结果 58 String inputline = in.readLine(); 59 60 // 返回结果为‘100’ 发送成功 61 System.out.println(inputline); 62 if(inputline.indexOf("100") != -1) 63 { 64 sendFlag = true; 65 } 66 67 // 输出结果 68 System.out.println(inputline); 69 return sendFlag; 70 71 } 72 }