不同类型的多控制器完美切换简单小代码

上传人:d****1 文档编号:178486338 上传时间:2022-12-28 格式:DOCX 页数:25 大小:30.72KB
收藏 版权申诉 举报 下载
不同类型的多控制器完美切换简单小代码_第1页
第1页 / 共25页
不同类型的多控制器完美切换简单小代码_第2页
第2页 / 共25页
不同类型的多控制器完美切换简单小代码_第3页
第3页 / 共25页
资源描述:

《不同类型的多控制器完美切换简单小代码》由会员分享,可在线阅读,更多相关《不同类型的多控制器完美切换简单小代码(25页珍藏版)》请在装配图网上搜索。

1、版本新特性框架(添加了版本的本地缓存功能,适应各. 本地推送和简单的约束的添加 ,不同类型的多控制器完美切换 侧滑手势 ios 关于 interactivePopGestureRecognizer.Status ListDelete(Sqlist &L,int i)/删除 i 位置的数据if(iL.length) return ERROR;for(int j=i;j=L.length-1;j+)L.elemj-1=L.elemj;L.length-;return OK;Status ListInput(Sqlist &L)/数据录入if(L.length=-1) return ERROR; c

2、outLength=n;L.length+=n;ElemType e;coutLength=L.length;for(;iL.length;i+)cou t请输入第i+l个数据:;cine;ListInsert(L,i+1,e);-L.length;/每次插入都会L.length+,所以此处一防止死循环/xib 中 view 得 Mode 属性中的 Scale To Fill.return OK;Status ListSort(Sqlist &L)/排序,冒泡算法if(L.length=-1) return ERROR;ElemType t;for(int i=0;iL.length-1;i+

3、)for(int j=0;jL.length-i-1;j+)if(L.elemjL.elemj+1)t=L.elemj+1;L.elemj+1=L.elemj;L.elemj=t; return OK;代码Google Go代码package mainimport (io/ioutilnet/httpnet/fmt 1 . / encoding/json)/ 黄金数据调用示例代码 聚合数据/在线接口文档:www/docs/29/const APPKEY = * /您申请的 APPKEYfunc main()/1.上海黄金交易所 Request1()/2.上海期货交易所 Request2()/3

4、.银行账户黄金 Request3()/1.上海黄金交易所func Request1()/请求地址juhe :=web:8080/finance/gold/shgold/初始化参数 param:=.Values/配置请求参数,方法内部已处理encode问题,中文参数可以直接传参 param.Set(key,APPKEY) /APP Keyparam.Set(v,) /JSON 格式版本(0 或 1)默认为 0/发送请求 data,err:=Get(juhe,param) if err!=nilfmt .Errorf(请求失败,错误信息:rn%v,err)elsevar netReturn map

5、stringinterfacejson.Unmarshal(data,&netReturn)if netReturnerror_code.(float64)=0fmt.Printf (接口返回 result 字段是:rn%v,netReturnresult)/2. 上海期货交易所func Request2()/请求地址juhe :=web:8080/finance/gold/shfuture/初始化参数param:=.Values/配置请求参数,方法内部已处理encode问题,中文参数可以直接传参 param.Set(key,APPKEY) /APP Keyparam.Set(v,) /JSO

6、N 格式版本(0 或 1)默认为 0/发送请求data,err:=Get(juhe,param)if err!=nilfmt .Errorf(请求失败,错误信息:rn%v,err)elsevar netReturn mapstringinterfacejson.Unmarshal(data,&netReturn)if netReturnerror_code.(float64)=0fmt.Printf(接口返回 result 字段是:rn%v,netReturnresult)/3. 银行账户黄金func Request3()/请求地址juhe :=web:8080/finance/gold/ba

7、nkgold/初始化参数 param:=.Values/配置请求参数,方法内部已处理encode问题,中文参数可以直接传参 param.Set(key,APPKEY) /APP Key/发送请求data,err:=Get(juhe,param)if err!=nilfmt .Errorf(请求失败,错误信息:rn%v,err)elsevar netReturn mapstringinterface json.Unmarshal(data,&netReturn)if netReturnerror_code.(float64)=0fmt.Printf (接口返回 result 字段是:rn%v,n

8、etReturnresult) / get 网络请求func Get(api string,params .Values)(rsbyte ,err error)var *.,err=.Parse(api)if err!=nilfmt .Prin tf(解析错误:rn%v,err)return nil,err/如果参数中有中文参数,这个方法会进行Encode.RawQuery=params.Encode() resp,err:=http.Get(.String() if err!=nilfmt.Println(err:,err)return nil,errdefer resp.Body.Clos

9、e()return ioutil.ReadAll(resp.Body)/ pos t网络请求,params是.Values类型func Post(api string, params .Values)(rsbyte,err error) resp,err:=http.PostForm(api, params)if err!=nil return nil ,errdefer resp.Body.Close()return ioutil.ReadAll(resp.Body)代码描述:基于GO的黄金数据接口调用代码实例 关联数据:黄金数据代码C#代码using System;using System

10、.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.IO;using Xfrog.Net;using System.Diagnostics;using System.Web;/ 黄金数据调用示例代码 聚合数据/ 在线接口文档: www/docs/29/ 代码中 JsonObject 类下载地址:/download/gcm3206021155665/7458439 /namespace ConsoleAPIclass Programstatic void Main(strin

11、g args)string appkey = *; /配置您申请的 appkey/1.上海黄金交易所string 1 = web:8080/finance/gold/shgold;var parameters1 = new Dictionary();parametersl.Add(key, appkey);/你申请的 keyparametersl.Add(v , ); /JSON格式版本(0 或 1)默认为 0 string result1 = sendPost(1, parameters1, get);JsonObject newObj1 = new JsonObject(result1);

12、String errorCode1 = newObj1error_code.Value;if (errorCode1 = 0)Debug.Wri teLine(成功);Debug.WriteLine(newObj1);else/Debug.Wri teLine(失败);Debug.WriteLine(newObj1error_code.Value+:+newObj1reason.Value);/2. 上海期货交易所string 2 = web:8080/finance/gold/shfuture;var parameters2 = new Dictionary();parameters2.Ad

13、d(key, appkey);/你申请的 keyparameters2.Add(v , ); /JSON格式版本(0 或 1)默认为 0 string result2 = sendPost(2, parameters2, get);JsonObject newObj2 = new JsonObject(result2);String errorCode2 = newObj2error_code.Value;if (errorCode2 = 0)Debug.Wri teLine(成功);Debug.WriteLine(newObj2);else/Debug.Wri teLine(失败);Debu

14、g.WriteLine(newObj2error_code.Value+:+newObj2reason.Value);/3. 银行账户黄金string 3 = web:8080/finance/gold/bankgold;var parameters3 = new Dictionary();parameters3.Add(key, appkey);/你申请的 keystring result3 = sendPost(3, parameters3, get);JsonObject newObj3 = new JsonObject(result3);String errorCode3 = newO

15、bj3error_code.Value;if (errorCode3 = 0)Debug.Wri teLine(成功); Debug.WriteLine(newObj3);else/Debug.Wri teLine(失败);Debug.WriteLine(newObj3error_code.Value+:+newObj3reason.Value);/ / Http (GET/POST)/ /param name二请求/param/param name二parame ters请求参数/param/ param name二me thod请求方法/param/ re turns响应内容/re tu

16、rnsstatic string sendPost(string , IDictionarystring, string parameters, string method)if (method.ToLower() = post)HttpWebRequest req = null; HttpWebResponse rsp = null; System.IO.Stream reqStream = null;tryreq = (HttpWebRequest)WebRequest.Create(); req.Method = method;req.KeepAlive = false;req.Prot

17、ocolVersion = HttpVersion.Version10;req.Timeout = 5000;req.ContentType = application/x-www-form-encoded;charset=utf-8;byte postData =Encoding.UTF8.GetBytes(BuildQuery(parameters, utf8);reqStream = req.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); rsp = (HttpWebResponse)req.GetRe

18、sponse();Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet); return GetResponseAsString(rsp, encoding);catch (Exception ex)return ex.Message;finallyif (reqStream != null) reqStream.Close();if (rsp != null) rsp.Close();else/创建请求HttpWebRequest request = (HttpWebRequest)WebRequest.Create( + ?+

19、BuildQuery(parameters, utf8);/GET 请求request.Method = GET;request.ReadWriteTimeout = 5000; request.ContentType = text/html;charset=UTF-8; HttpWebResponse response =(HttpWebResponse)request.GetResponse();Stream myResponseStream = response.GetResponseStream();StreamReader myStreamReader = new StreamRea

20、der(myResponseStream, Encoding.GetEncoding(utf-8);/返回内容string retString = myStreamReader.ReadToEnd(); return retString;/ / 组装普通文本请求参数。/ /param name二parame tersKey-Value 形式请求参数字典/param/ re turns编码后的请求数据/re tu rnsstringstatic string BuildQuery(IDictionarystring, string parameters, encode)StringBuilder

21、 postData = new StringBuilder();bool hasParam = false;IEnumeratorKeyValuePairstring, string dem = parameters.GetEnumerator();while (dem.MoveNext()string name = dem.Current.Key;string value = dem.Current.Value;/ 忽略参数名或参数值为空的参数if(!string.IsNullOrEmpty(name)/& !string.IsNullOrEmpty(value)if (hasParam)p

22、ostData.Append(&);postData.Append(name); postData.Append(=);if (encode = gb2312)postData.Append(HttpUtility.Encode(value,Encoding.GetEncoding(gb2312);else if (encode = utf8)postData.Append(HttpUtility.Encode(value,Encoding.UTF8);elsepostData.Append(value);hasParam = true;return postData.ToString();/

23、 / 把响应流转换为文本。/ /param name二rsp响应流对象/param/param name二encoding编码方式/param/ 0)c_setopt($ch,COPT_POSTFIELDS,$body);if(count($header)0) c_setopt($ch,COPT_HTTPHEADER,$header);/设置上传文件相关 c_setopt($ch,COPT_FOLLOWLOCATION,true);c_se top t($ch,C0PT_MAXREDIRS,3);/递归c_setopt ($ch,COPT_SSL_VERIFYPEER,false);/ 对认证

24、证书来源的检查c_setopt($ch,COPT_SSL_VERIFYHOST,O);/ 从证书中检查 SSL 加密算法 switch ($type) case GET: c_setopt($ch,COPT_HTTPGET,1);break;case POST:c_setopt($ch,COPT_POST,1);break;case PUT:c_setopt($ch,COPT_CUSTOMREQUEST,PUT);break;case DELETE: c_setopt($ch,COPT_CUSTOMREQUEST,DELETE);break;/上传文件相关设置c_setopt($ch,COPT

25、_ENCODING,gzip); c_setopt($ch,COPT_USERAGENT,SSTS Browser/1.0);c_setopt ($ch, COPT_USERAGENT, Mozilla/4.0 (compatible ; MSIE 8.0 ; Windows NT 6.0 ;Trident/4.0);/模拟用户使用的浏览器if(c_errno($ch)return c_error($ch);$content = c_exec($ch);c_close($ch);/关闭c资源,并且释放系统资源$result = json_decode($content,true);if(!em

26、pty($result)return $result;elsereturn $content;代码C/C+代码/*编译指令$ /opt/sybase/OCS-16_0/bin/cpre64 -m teststu.cp$ cc -m64 -g -DSYB_LP64 -I. -I/opt/sybase/OCS-16_0/include teststu.c /opt/sybase/OCS-16_0/include/sybesql.c -L/opt/sybase/OCS-16_0/lib -lsybct64 -lsybtcl64 -lsybcs64 -lsybcomn64 -lsybintl64 -l

27、sybunic64 -rdynamic -ldl -lnsl -lm -o teststu*/#include /*建立通讯区域*/EXEC SQL INCLUDE SQLCA;/* These tokens must be declared in a declare section* because they are used in declare sections below.*/EXEC SQL BEGIN DECLARE SECTION;#define TYPESIZE13#define TIDSIZE6EXEC SQL END DECLARE SECTION; 秦皇岛同城购 俷俸俹

28、#define EOLN 0/* Forward declarations of the error and message handlers and* other subroutines called from main().*/void error_handler();void warning_handler();intmain(int argc, char *argv)/*声明宿主变量*/EXEC SQL BEGIN DECLARE SECTION;/* storage for login name and password. */char username30;char sname30

29、;char password30;char server30;EXEC SQL END DECLARE SECTION;/*错误处理*/EXEC SQL WHENEVER SQLERROR CALL error_handler();EXEC SQL WHENEVER SQLWARNING CALL warning_handler();EXEC SQL WHENEVER NOT FOUND CONTINUE;/*连接到 SQL SERVER 服务器*/* Copy the user name and password defined in sybsqlex.h to* the variables

30、 declared for them in the declare section.*/ strcpy(username, mymotif);strcpy(password, wxwpxh);strcpy(server, MYMOTIFVOSTRO145480);EXEC SQL CONNECT :username IDENTIFIED BY :password using :server;EXEC SQL USE testdb;EXEC SQL DECLARE c1 CURSOR FORSELECT SNAME FROM STUDENT;EXEC SQL OPEN c1;printf(nam

31、e in table studentn);do EXEC SQL FETCH c1 INTO :sname;if (sqlca.sqlcode != 0) break;printf( student name = %sn, sname ); while ( 1 );EXEC SQL CLOSE c1;return(0);/*错误处理程序*/* void error_handler()* Displays error codes and numbers from the SQLCA and exits with* an ERREXIT status.*/voiderror_handler(voi

32、d)fprintf(stderr, n* SQLCODE=(%ld), sqlca.sqlcode);if (sqlca.sqlerrm.sqlerrml)fprintf(stderr, n* ASE Error );fprintf(stderr, n* %s, sqlca.sqlerrm.sqlerrmc);fprintf(stderr, nn);exit(-1);/* void warning_handler()* Displays warning messages.*/voidwarning_handler(void)if (sqlca.sqlwarn1 = W)fprintf(stde

33、rr,n* Data truncated.n);if (sqlca.sqlwarn3 = W)fprintf(stderr,n* Insufficient host variables to store results.n); return;代码 Log4j 配置org.slf4j slf4j-log4j12 导入这个包,会引入下面两个 jar org.springframework spring-context-support commons-loggingcommons-logging-api1.1org.springframeworkspring-ormdependency!一当 spr

34、ing-config.xml 文件中配置aop:aspect需要加入此包一org.aspectjartifactIdaspectjweaver/artifactId/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactId/dependency文件无缝滚动.html 1KB!DOCTYPE htmlhtmlheadmeta charset=utf-8title/titlestyle type=text/css*margin: 0;padding: 0;#wrap ul liw

35、idth: 380px;height: 230px;float: left;list-style: none;#wrap ulposition: absolute;left: 0;top: 0;#wrapwidth: 1520px;height: 230px;margin: 100px 50px;position: relative;background: red; overflow: hidden;window.onload=function()var oDiv=document.getElementById(wrap);var oUl=oDiv.getElementsByTagName(u

36、l)0;var oLi=oUl.getElementsByTagName(li);oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;oUl.style.width=oLi0.offsetWidth*oLi.length+px; setInterval(function()if(oUl.offsetLeft-oUl.offsetWidth/2) oUl.style.left=0 oUl.style.left=oUl.offsetLeft-2+px;,30)代码 获取的参数/获取的参数function getParam(paramKey)/获取当前var = lo

37、cation.href;/获取要取得的 get 参数位置var get = .indexOf(paramKey +=);if(get = -1)return false;/截取字符串var getParamStr = .slice(paramKey.length + get + 1);/判断截取后的字符串是否还有其他get参数var nextparam = getParamStr.indexOf(&); if(nextparam != -1)getParamStr = getParamStr.slice(0, nextparam); return decodeURIComponent(getP

38、aramStr);代码 添加参数/添加参数function addParam(,paramKey,paramVal)var andStr = ?;var beforeparam = .indexOf(?); if(beforeparam != -1)andStr = &;return + andStr + paramKey + =+ encodeURIComponent(paramVal); 代码 删除参数/删除参数function delParam(,paramKey)var Param = .substr(.indexOf(?)+1);var before = .substr(0,.ind

39、exOf(?);. var next = ;var arr = new Array(); if(Param!=)var ParamArr = Param.split(&);for(var i=0;i0)next = ?+arr.join(&);= before+next; return ;代码C#代码#region 防止 sql 注入式攻击(可用于 UI 层控制) /判断字符串中是否有SQL攻击代码/ 传入用户提交数据/ true-安全;false-有注入攻击现有;public bool ProcessSqlStr(string inputString)string SqlStr =and|o

40、r|exec|execute|insert|select|delete|update|alter|create|drop|count|*|ch r|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators;tryif (inputString != null) & (inputString != String.Empty)string str_Regex = b( + SqlStr + )b;Regex Regex = n

41、ew Regex(str_Regex, RegexOptions.IgnoreCase);/string s = Regex.Match(inputString).Value;if (true = Regex.IsMatch(inputString)return false;catchreturn false;return true;/ 处理用户提交的请求,校验 sql 注入式攻击,在页面装置时候运行/System.Configuration.ConfigurationSettings.AppSettingsErrorPage.ToString(); 为用户自定义错误页面提示地址,/ 在 We

42、b.Config 文件时里面添加一个 ErrorPage 即可/public void ProcessRequest()trystring getkeys = ;string sqlErrorPage =System.Configuration.ConfigurationSettings.AppSettingsErrorPage.ToString();if (System.Web.HttpContext.Current.Request.QueryString != null)for (int i = 0; i System.Web.HttpContext.Current.Request.Que

43、ryString.Count; i+)getkeys = System.Web.HttpContext.Current.Request.QueryString.Keysi;if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.QueryStringgetkeys)System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage + ?errmsg= + getkeys + 有 SQL 攻击嫌疑!);System.Web.HttpContext.Current.Response

44、.End();if (System.Web.HttpContext.Current.Request.Form != null)for (int i = 0; i maxLength)inputString = inputString.Substring(0, maxLength);return inputString;/ 将输入字符串中的 sql 敏感字,替换成敏感字,要求输出时,替换回来/public string MyEncodeInputString(string inputString)/要替换的敏感字string SqlStr =and|or|exec|execute|insert|

45、select|delete|update|alter|create|drop|count|*|ch r|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators;tryif (inputString != null) & (inputString != String.Empty)string str_Regex = b( + SqlStr + )b;Regex Regex = new Regex(str_Regex, Re

46、gexOptions.IgnoreCase);/string s = Regex.Match(inputString).Value;MatchCollection matches = Regex.Matches(inputString);for (int i = 0; i matches.Count; i+)inputString = inputString.Replace(matchesi.Value, +matchesi.Value + );catch. return ;return inputString;/ 将已经替换成的敏感字,转换回来为敏感字/public string MyDec

47、odeOutputString(string outputstring)/要替换的敏感字string SqlStr =and|or|exec|execute|insert|select|delete|update|alter|create|drop|count|*|ch r|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators;tryif (outputstring != null) & (outputstring !

48、= String.Empty)string str_Regex = b( + SqlStr + )b;Regex Regex = new Regex(str_Regex, RegexOptions.IgnoreCase); MatchCollection matches = Regex.Matches(outputstring);for (int i = 0; i matches.Count; i+)outputstring = outputstring.Replace(matchesi.Value,matchesi.Value.Substring(1, matchesi.Value.Length - 2);catch. return ;return outputstring;#endregionvoid ListPrint(Sqlist &L)/输出表内数据ElemType e;for(int i=0;iL.length;i+)GetElem(L,i+1,e); coute;coutendl;int main()int Choice=-1,Ifsort=-1;Sqlist L;L.length=-1;while(1)cout+Choice;switch(Choice)case 0:cou t谢谢使用endl;system(pause);return 0;bre

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!