版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、电信增值业务一之彩信 实验报告 任课教师: 实验地点:实验时间: 小组成员:实验二 网页版彩信发送页面(修改版)代码:Client.jsp<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <title></title>
2、;<script type="text/javascript">function actionEdit() var phone = document.getElementById("phone").value;var produce = document.getElementById("produce").value;if (phone.length = 0) alert("电话号码不能为空");return falseif (produce = -1) alert("请选择产品")
3、;return falsereturn true;</script> </head> <body><p align="center"> 彩信发送页面</p><form id="form1" name="form1" method="post" action="servlet/" enctype="multipart/form-data"> <table border="0" al
4、ign="center"> <tr><td width="35%" align="right" style="background-color: rgb(255, 128, 0);">手机号码:</td><td style="background-color: rgb(255, 128, 0);"><input type="text" name="phone" maxlength="15
5、0" size="50"></td></tr> <tr><td align="right" style="background-color: rgb(255, 128, 0);">选择产品:</td> <td style="background-color: rgb(255, 128, 0);"><select name="produce"> <option value="-1&q
6、uot;>请选择</option> <%List<String> list=(List)request.getAttribute("list"); for(int i=0;i<list.size();i+)%> <option value="<%=list.get(i)%>"><%=list.get(i)%></option> <%> </select> </td></tr> <tr align="
7、;center"><td align="right" style="background-color: rgb(255, 128, 0);"><input type="submit" onclick="javascript:return actionEdit()" value="发送"></td><td align="left" style="background-color: rgb(255, 128, 0
8、);"><input type="reset" value="重置"></td></tr> </table></form> <p align="center"> 彩信填写</p><form id="form1" name="form1" method="post" action="servlet/" enctype="multipart/fo
9、rm-data"> <table border="0" align="center"> <tr><td width="35%" align="right" style="background-color: rgb(255, 128, 128);">收件号码:</td><td style="background-color: rgb(255, 128, 128);"><input type=&qu
10、ot;text" name="phoneto" maxlength="150" size="50"></td></tr> <tr><td width="35%" align="right" style="background-color: rgb(255, 128, 128);">标题:</td><td style="background-color: rgb(255, 128, 12
11、8);"><input type="text" name="title" maxlength="150" size="50"></td></tr> <tr><td width="5%" align="right" style="background-color: rgb(255, 128, 128);">内容:</td><td style="backgr
12、ound-color: rgb(255, 128, 128);"><input type="text" name="test" maxlength="150" size="50"></td></tr> <tr align="center"><td align="right" style="background-color: rgb(255, 128, 128);"><inpu
13、t type="submit" onclick="javascript:return actionEdit()" value="发送"></td><td align="left" style="background-color: rgb(255, 128, 128);"><input type="reset" value="重置"></td></tr> </table></
14、form> <p align="center"> 附加文件选择</p><form id="form1" name="form1" method="post" action="servlet/" enctype="multipart/form-data"> <table border="0" align="center"><tr> <td style="ba
15、ckground-color: rgb(0, 255, 255);">上传人:</td><td style="background-color: rgb(0, 255, 255);"> <input name="name" type="text" id="name" size="20" ></td> </tr> <tr> <td style="background-color: rgb(0,
16、255, 255);">上传文件:</td> <td style="background-color: rgb(0, 255, 255);"><input name="file" type="file" size="20" ></td> </tr> <tr> <td style="background-color: rgb(0, 255, 255);"></td><td styl
17、e="background-color: rgb(0, 255, 255);"> <input type="submit" name="submit" value="提交" > <input type="reset" name="reset" value="重置" > </td></tr></table></form> </body></html>Inde
18、x.jsp<%request.getRequestDispatcher("/http/MmsService").forward(request, response);%>实验截图:实验三 实验代码:MMS.javapackage com.cq.view;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.FlowLayout;import java.io.File;import java.io.;import java.io.;import
19、java.io.;import java.io.IOException;import java.io.InputStream;import javax.swing.*;import javax.swing.;import com.cq.main.ClientInit;impormonUtil;import sun.misc.BASE64Encoder;public class MMS extends JFrame private String sendAddress = ""private String userName = "2010214442"pr
20、ivate String password = "123"private String serviceId = "2"private String channelId = "1"private String phone = ""private String subject = "重庆早报(20120114)"String ;JFrame jf = new JFrame("发彩信");/顶层容器JPanel jp = new JPanel(); /面板容器JLabel l_na
21、me = new JLabel("电话号码:");static JTextField t_name = new JTextField(10);JButton seleFile = new JButton("附件");JLabel lb = new JLabel("短信内容: ");static JTextArea t_test = new JTextArea(12,18);JButton send = new JButton("发送");JButton cancel = new JButton("取消&q
22、uot;);public MMS() jp.add(l_name);jp.add(t_name);jp.add(seleFile);jp.add(lb);jp.add(t_test);jp.add(send);jp.add(cancel);jf.add(jp);/ 事件OK按钮监听sele(new ActionListener() public void actionPerformed(ActionEvent e) J = new J("D:");int returnVal = (); = ().getAbsolutePath();/ 这个就是你选择的文件夹的路径Syste
23、m.out.println(););send.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) send(););/ 事件Cancel按钮监听cancel.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) System.exit(0););jf.setVisible(true);jf.setSize(230, 350);jf.setDefaultCloseOperati
24、on(jf.EXIT_ON_CLOSE);jf.setLocation(500, 270);public void send(String ) ClientInit client = new ClientInit();/ 1.获取下发内容String content = client.getMMSContent();/ "D:/test/mms.zip"/ 2.下发StringBuffer sendParam = new StringBuffer();phone = t_name.getText();sendParam.append("phone=" +
25、 phone);sendParam.append("&userName=" + userName);sendParam.append("&password=" + CommonUtil.MD5Encode(password);sendParam.append("&serviceId=" + serviceId);sendParam.append("&channelId=" + channelId);sendParam.append("&subject="
26、+ subject);sendParam.append("&content=" + content);String resp = CommonUtil.connectURL(String.valueOf(sendParam),sendAddress);System.out.println("Send MMS response:" + resp);public String getMMSContent(String path) String result = ""InputStream is = null;try BASE64E
27、ncoder encoder = new BASE64Encoder();is = new (new );byte bAry = new byteis.available();is.read(bAry);result = encoder.encode(bAry); catch (Exception e) System.out.println(e); finally if (null != is) try is.close(); catch (IOException e) System.out.println(e);return result;public static void main(St
28、ring args) new MMS();ClientInit.javapackage com.cq.main;import java.io.File;import java.io.;import java.io.IOException;import java.io.InputStream;import sun.misc.BASE64Encoder;impormonUtil;public class ClientInit private static String sendAddress = ""private static String userName = "
29、2010214442"private static String password = "123"private static String serviceId = "2"private static String channelId = "1"private String phone = ""private String subject = "重庆早报(20120114)"public static void main(String args) ClientInit client =
30、 new ClientInit();/ 1.获取下发内容String content = client.getMMSContent("D:/test/mms.zip");/ 2.下发StringBuffer sendParam = new StringBuffer();sendParam.append("phone=" + client.phone);sendParam.append("&userName=" + userName);sendParam.append("&password=" + C
31、ommonUtil.MD5Encode(password);sendParam.append("&serviceId=" + serviceId);sendParam.append("&channelId=" + channelId);sendParam.append("&subject=" + client.subject);sendParam.append("&content=" + content);String resp = CommonUtil.connectURL(Str
32、ing.valueOf(sendParam), sendAddress);System.out.println("Send MMS response:" + resp);public String getMMSContent(String path) String result = ""InputStream is = null;try BASE64Encoder encoder = new BASE64Encoder();is = new (new );byte bAry = new byteis.available();is.read(bAry);r
33、esult = encoder.encode(bAry); catch (Exception e) System.out.println(e); finally if (null != is) try is.close(); catch (IOException e) System.out.println(e);return result;CommonUtil.javapackage com.cq.util;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.OutputStream;imp
34、or.HttpURLConnection;impor.URL;import java.security.MessageDigest;public class CommonUtil public static String connectURL(String commString, String address) HttpURLConnection urlConn = null;String rec_string = ""URL url = null;try url = new URL(address);urlConn = (HttpURLConnection) url.op
35、enConnection();urlConn.setConnectTimeout(30000);urlConn.setReadTimeout(30000);urlConn.setRequestMethod("POST");urlConn.setDoOutput(true);OutputStream out = urlConn.getOutputStream();out.write(commString.getBytes("UTF-8");out.flush();out.close();BufferedReader rd = new BufferedRea
36、der(new InputStreamReader(urlConn.getInputStream(), "UTF-8");StringBuffer sb = new StringBuffer();int ch;while (ch = rd.read() > -1) sb.append(char) ch);rec_string = sb.toString().trim();rd.close(); catch (Exception e) rec_string = "-107" finally if (urlConn != null) urlConn.d
37、isconnect();return rec_string;public static String MD5Encode(String sourceString) String resultString = null;try resultString = new String(sourceString);MessageDigest md = MessageDigest.getInstance("MD5");resultString = byte2hexString(md.digest(resultString.getBytes(); catch (Exception ex)
38、 System.out.println(ex);return resultString;private static String byte2hexString(byte bytes) StringBuffer bf = new StringBuffer(bytes.length * 2);for (int i = 0; i < bytes.length; i+) if (bytesi & 0xff) < 0x10) bf.append("0");bf.append(Long.toString(bytesi & 0xff, 16);return
39、bf.toString();JdbcUtil.javapackage com.cq.util;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class JdbcUtil public static final int CONNTYPE_MYSQL = 1;public static Connection getConnect(String ip, Str
40、ing db, String user, String password) return getConnect(CONNTYPE_MYSQL, ip, 3306, db, user, password);public static Connection getConnect(int type, String ip, int port, String db, String user, String password) Connection conn = null;String driver = null;String url = null;switch (type) case CONNTYPE_
41、MYSQL:driver = "com.mysql.jdbc.Driver"url = "jdbc:mysql:/" + ip + ":" + port + "/" + db;break;if (null != driver && null != url) try Class.forName(driver);conn = DriverManager.getConnection(url, user, password); catch (Exception e) System.out.println(e
42、);return conn;public static void closeConnect(Connection conn) if (null != conn) try conn.close(); catch (SQLException e) System.out.println(e);public static ResultSet query(Connection conn, String sql) Statement st = null;ResultSet rs = null;try st = conn.createStatement(ResultSet.TYPE_SCROLL_INSEN
43、SITIVE, ResultSet.CONCUR_READ_ONLY);rs = st.executeQuery(sql); catch (Exception e) System.out.println(e);return rs;实验截图:实验四实验代码:Form1.csusing System;using System.Collections.Generic;usinponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
44、usin;usin.Sockets;using System.IO;namespace demo public partial class Form1 : Form private static String sendAddress; private static String userName; private static String password; private static String serviceId; private static String channelId; public String phone; public String subject; public F
45、orm1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) textBox1.Text = "" textBox2.Text = "2010214787" textBox3.Text = "*" textBox4.Text = "2" textBox5.Text = "1" textBox6.Text = "" textBox7.Text = "重庆邮电大学欢迎您
46、" textBox8.Text = "D:/mms.zip" comboBox1.SelectedIndex = 0; public String getMMSContent(String path) string result="" byte b_data = new byte2500; char c_data = new char2500; try lock (this) if (path) = false) MessageBox.Show("文件不存在", "提示信息"); else fs = ne
47、w (path, );fs.Seek(0, SeekOrigin.Begin); fs.Read(b_data, 0, 2000);Decoder d = Encoding.UTF8.GetDecoder();d.GetChars(b_data, 0, b_data.Length, c_data, 0);result = new string(c_data); return result; catch (IOException e)return(e.Message);private void button1_Click(object sender, EventArgs e) sendAddre
48、ss = textBox1.Text.Trim(); userName = textBox2.Text.Trim(); password = textBox3.Text.Trim(); serviceId = textBox4.Text.Trim(); channelId = textBox5.Text.Trim(); phone = textBox6.Text.Trim(); subject = textBox7.Text.Trim(); string path = textBox8.Text.Trim(); string content = getMMSContent(path); IPE
49、ndPoint point = new IPEndPoint(IPAddress.Parse("6"), 8080); string sendParam = "phone=" + phone + "&userName=" + userName + "&password=" + password + "&serviceId=" + serviceId + "&channelId=" + channelId + "
50、&subject=" + subject + "&content=" + content; try switch (comboBox1.SelectedIndex) case 0:string data=CommonUtil.connectURL(sendParam, sendAddress);MessageBox.Show("成功发送:"+data,"结果"); break;case 1:string msg=mySockets.send(sendParam, point); MessageBox.Show
51、("返回:"+msg,"结果"); break;default:MessageBox.Show("请选择正确的发送方式!", "提示信息"); break; catch(Exception ex) MessageBox.Show(ex.Message,"警告信息"); private void button2_Click(object sender, EventArgs e)if (open() = DialogResult.OK) textBox8.Text = open; private void label2_Click(object sender, EventArgs e) private void label3_Click(object sender, EventArgs e) mySocket.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;usin;usin.Sockets;namespace demo class mySockets public static string se
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年限供应商战略合作协议
- 2024年度商品交易居间服务协议
- 2024知识产权交易协议模板
- 2024年专项品牌副食销售代理协议
- 2024年专业讲座施工建设协议模板
- 2024年度专业安保劳务派遣协议样本
- 2024幼教人员劳动协议样本
- 安装项目承揽协议范本2024年
- 2024年企业间合作联营协议
- 2024年度保安职位劳动协议模板
- 中国钱币的演变课件
- 《路由与交换技术》课程教学大纲
- 小学生自我介绍竖版
- 北师大版八年级数学上册教案(全册完整版)教学设计含教学反思
- DB43∕T 1780-2020 工业企业天然气使用安全规程
- SF6全封闭组合电器GIS常见故障及其处理
- 世界主要航线教学课件
- 设备故障报修维修记录单
- 时间序列市场预测法课件
- 四年级下语文教学参考挑山工_教科版
- 中国医院质量安全管理 第4-6部分:医疗管理 医疗安全(不良)事件管理 T∕CHAS 10-4-6-2018
评论
0/150
提交评论