




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
电信增值业务一之彩信 实验报告 任课教师: 实验地点:实验时间: 小组成员:实验二 网页版彩信发送页面(修改版)代码:Client.jsp function actionEdit() var phone = document.getElementById(phone).value;var produce = document.getElementById(produce).value;if (phone.length = 0) alert(电话号码不能为空);return falseif (produce = -1) alert(请选择产品);return falsereturn true; 彩信发送页面 手机号码: 选择产品: 请选择 %List list=(List)request.getAttribute(list); for(int i=0;i option value= 彩信填写 收件号码: 标题: 内容: 附加文件选择 上传人: 上传文件: Index.jsp实验截图:实验三 实验代码: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.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.InputStream;import javax.swing.*;import javax.swing.filechooser.FileFilter;import com.cq.main.ClientInit;import com.cq.util.CommonUtil;import sun.misc.BASE64Encoder;public class MMS extends JFrame private String sendAddress = 6:8080/mms/http/SendMms;private String userName = 2010214442;private String password = 123;private String serviceId = 2;private String channelId = 1;private String phone = ;private String subject = 重庆早报(20120114);String filePath;JFrame jf = new JFrame(发彩信);/顶层容器JPanel jp = new JPanel(); /面板容器JLabel l_name = 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(取消);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按钮监听seleFile.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) JFileChooser fileChooser = new JFileChooser(D:);int returnVal = fileChooser.showOpenDialog(fileChooser);filePath = fileChooser.getSelectedFile().getAbsolutePath();/ 这个就是你选择的文件夹的路径System.out.println(filePath););send.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) send(filePath););/ 事件Cancel按钮监听cancel.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) System.exit(0););jf.setVisible(true);jf.setSize(230, 350);jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);jf.setLocation(500, 270);public void send(String filepath) ClientInit client = new ClientInit();/ 1.获取下发内容String content = client.getMMSContent(filepath);/ D:/test/mms.zip/ 2.下发StringBuffer sendParam = new StringBuffer();phone = t_name.getText();sendParam.append(phone= + phone);sendParam.append(&userName= + userName);sendParam.append(&password= + CommonUtil.MD5Encode(password);sendParam.append(&serviceId= + serviceId);sendParam.append(&channelId= + channelId);sendParam.append(&subject= + 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 BASE64Encoder encoder = new BASE64Encoder();is = new FileInputStream(new File(path);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(String args) new MMS();ClientInit.javapackage com.cq.main;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import sun.misc.BASE64Encoder;import com.cq.util.CommonUtil;public class ClientInit private static String sendAddress = 6:8080/mms/http/SendMms;private static String userName = 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 = 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= + CommonUtil.MD5Encode(password);sendParam.append(&serviceId= + serviceId);sendParam.append(&channelId= + channelId);sendParam.append(&subject= + client.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 BASE64Encoder encoder = new BASE64Encoder();is = new FileInputStream(new File(path);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;CommonUtil.javapackage com.cq.util;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.OutputStream;import .HttpURLConnection;import .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.openConnection();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 BufferedReader(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.disconnect();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) 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) 0) msg = Encoding.UTF8.GetString(buff); client.Close(); catch(Exception ) throw new Exception(); return msg; CommonUtil.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Net;using System.Security.Policy;namespace demo public class CommonUtilpublic static string connectURL(string cString, String address)WebRequest wr = WebRequest.Create(address); wr.Method = post;StringBuilder urlEncoded = new StringBuilder(); byte somebytes =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业拆迁补偿协议模板
- 定制旅游服务细节免责合同书
- 个人出租房协议书
- 智慧城市项目建设投资合同
- 设备升级改造合同范本
- 农副产品数字化平台建设协议
- XX心血管治疗器械股份有限公司2022-2023可持续发展报告:员工福祉与职业发展并行
- 2025年房地产经纪人职业资格考试模拟试卷:房地产经纪业务合同管理
- 采购框架协议4篇
- 2025年新能源环卫车辆新能源补给站充电站建设与运营产业链上下游分析报告
- GB/T 13384-2008机电产品包装通用技术条件
- 粘膜免疫系统概述
- 钢板桩及支撑施工方案
- 新部编版四年级上册语文全册完整课件
- 政府信息公开申请表
- 冷藏车保温箱冰排使用记录
- FANUC工业机器人离线与应用项目7 工业机器人KAREL程序
- 综合能源管理解决方案(完整版)
- DB43∕T 291-2006 桃源大叶茶栽培技术规程
- 精细化学品化学-课件
- T∕CIS 71001-2021 化工安全仪表系统安全要求规格书编制导则
评论
0/150
提交评论