电信增值业务及软件开发一实践报告学院:软件学院专业:软件工程班级:学号:姓名2:指导老师:2013年06月22日实验一:短消息MO指令匹配算法一、实验步骤及实验结果实验代码:#includeiostream.h#includestring.hvoidmain(){charS[100];charT[50];cinS;cinT;intlen1,len2;intlen;intnext[100];inti,j;intk;intcount=0;len1=strlen(S);len2=strlen(T);len=len1-len2;j=1,k=0;next[1]=0;while(jlen2){if(k==0||T[j-1]==T[k-1]){j++;k++;next[j]=k;}elsek=next[k];}i=0;j=0;while(j!=len2&&ilen1){count++;if(S[i]!=T[j]){if(j==0)i++;elsej=next[j+1]-1;}else{i++;j++;}}coutlen1endl;coutiendl;coutjendl;if(j==len2){cout匹配成功,初始匹配成功的位置为第:i-len2+1个字符endl;cout匹配次数为:countendl;}else{cout匹配次数为:countendl;cout匹配失败endl;}}二、实验截图:二、心得:通过这次实验,用C/C++/C#或Java编程实现短消息MO指令匹配算法,该算法能够实现短消息MO指令的长号码和指令内容的模糊和精确匹配、空指令匹配功能。实验二:短消息增值业务软件开发平台及接口一、实验步骤及实验结果(1)实验内容“根据短信增值业务软件开发平台的操作手册熟悉短信增值业务软件开发平台”的实验步骤如下:登陆短信增值业务平台创建一个属于自己的业务,按需求和格式定义业务名称、指令类型、匹配方式、资费、处理方式、通道并送发审核。实验结果短信成功接收到,并且程序返回值为“0”结果分析通过平台下发的测试短信最终预期收到。说明在平台上创建的业务通道,格式正确。并且已经通过管理员的审核,能够合法的使用平台提供的通道资源。测试代码的发送成功还说明在程序中调用平台接口的方式是正确的。(2)实验内容“根据短消息增值业务软件开发平台的接口手册,熟悉短消息增值业务软件开发平台的HTTP接口、API接口、WebService接口等的使用方法”的实验步骤如下:http接口的参数定义格式:在程序中调用已通过审核的业务Stringurl=读取接口传递过来的参数并封装数据RequestDatard=newRequestData();rd.setPhone(15923932303);rd.setServiceId(2);rd.setChannelId(1);rd.setDestNumber(1);rd.setLinkId();rd.setMoId();rd.setSpNumber();rd.setFunctionType();rd.setType();通过程序来实现短信的下发代码实现:MainClass.javapackagecom.cqupt.http;publicclassMainClass{Stringphone=;publicMainClass(){StringmtMsg=;StringcommString=;Stringurl=读取接口传递过来的参数并封装数据RequestDatard=newRequestData();rd.setPhone(15923932303);rd.setServiceId(2);rd.setChannelId(1);rd.setDestNumber(1);rd.setLinkId();rd.setMoId();rd.setSpNumber();rd.setFunctionType();rd.setType();//业务逻辑判断mtMsg=第二条测试信息;rd.setMtMsg(mtMsg);//拼接数据commString=RequestUtil.getInstance().commString(rd);//转发到重邮平台RequestUtil.getInstance().requestURL(commString,url);}publicstaticvoidmain(String[]args){MainClassmainClass=newMainClass();}}RequestData.javapackagecom.cqupt.http;publicclassRequestData{privateStringphone;privateStringdestNumber;privateStringserviceId;privateStringchannelId;privateStringlinkId;privateStringmoId;privateStringspNumber;privateStringfunctionType;privateStringtype;privateStringcontent;privateStringmtMsg;publicStringgetPhone(){returnphone;}publicvoidsetPhone(Stringphone){this.phone=phone;}publicStringgetDestNumber(){returndestNumber;}publicvoidsetDestNumber(StringdestNumber){this.destNumber=destNumber;}publicStringgetServiceId(){returnserviceId;publicvoidsetServiceId(StringserviceId){this.serviceId=serviceId;}publicStringgetChannelId(){returnchannelId;}publicvoidsetChannelId(StringchannelId){this.channelId=channelId;}publicStringgetLinkId(){returnlinkId;}publicvoidsetLinkId(StringlinkId){this.linkId=linkId;}publicStringgetMoId(){returnmoId;}publicvoidsetMoId(StringmoId){this.moId=moId;}publicStringgetSpNumber(){returnspNumber;}publicvoidsetSpNumber(StringspNumber){this.spNumber=spNumber;}publicStringgetFunctionType(){returnfunctionType;}publicvoidsetFunctionType(StringfunctionType){this.functionType=functionType;}publicStringgetType(){returntype;}publicvoidsetType(Stringtype){this.type=type;}publicStringgetContent(){returncontent;}publicvoidsetContent(Stringcontent){this.content=content;}publicStringgetMtMsg(){returnmtMsg;}publicvoidsetMtMsg(StringmtMsg){this.mtMsg=mtMsg;}}RequestUtil.javapackagecom.cqupt.http;importjava.io.BufferedReader;importjava.io.InputStreamReader;importjava.io.OutputStream;importjava.io.UnsupportedEncodingException;importjava.net.HttpURLConnection;importjava.net.URL;importjava.net.URLEncoder;publicclassRequestUtil{privateRequestUtil(){}privatestaticRequestUtilrequestUtil=null;/***单例模式,返回RequestUtil的实例化对象**@returnrequestUtil*/publicstaticRequestUtilgetInstance(){if(requestUtil==null){requestUtil=newRequestUtil();//需要的时候才new,节省空间。}returnrequestUtil;}/***拼接字符串*@paramrd传递的参数封装成的包信息*@returncommString拼接好的请求信息字符串*/publicStringcommString(RequestDatard){StringcommString=;try{commString=userName=2012123667&password=123&phone=+rd.getPhone()+&destNumber=+rd.getDestNumber()+&serviceId=+rd.getServiceId()+&channelId=+rd.getChannelId()+&linkId=+rd.getLinkId()+&moId=+rd.getMoId()+&spNumber=+rd.getSpNumber()+&content=+URLEncoder.encode(rd.getMtMsg(),UTF-8)+&functionType=+rd.getFunctionType()+&type=+rd.getType()+&=3;}catch(UnsupportedEncodingExceptione){e.printStackTrace();}returncommString;}/***将结果短信转发到指定的平台*@paramcommString请求字符串*@paramaddress信息发送的目的URL地址*@returnrec_string发送结果内容*/publicStringrequestURL(StringcommString,Stringaddress){Stringrec_string=;URLurl=null;HttpURLConnectionurlConn=null;try{url=newURL(address);urlConn=(HttpURLConnection)url.openConnection();urlConn.setConnectTimeout(30000);urlConn.setReadTimeout(30000);urlConn.setRequestMethod(POST);urlConn.setDoOutput(true);OutputStreamout=urlConn.getOutputStream();out.write(commString.getBytes(GBK));out.flush();out.close();BufferedReaderrd=newBufferedReader(n