版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、基于php的基金财务数据接口调用代码实例,基于php的苏州实时公交/地铁接口调用代码Python的黄金数据接口调用代码实例 Python,间歇性滚动(源代码)检测版本更新提示(每个版本更新自动识别并 简单的本地缓存,支持命名空间,以及定期清理过期缓 将数字转换为人民币大写 PythonStatus ListInput(Sqlist &L) /数据录入 if(L.length=-1) return ERROR; coutLength=L.length; coutn; L.length+=n; ElemType e; coutLength=L.length; for(;iL.length;i+)
2、cout请输入第i+1e; ListInsert(L,i+1,e); -L.length; /每次插入都会L.length+,所以此处-防止死循环/ Date()对象的应用实例 return OK; Status ListSort(Sqlist &L) /排序,冒泡算法/3DTouch功能的应用 /angularjs 分页封装 if(L.length=-1) return ERROR; ElemType t; for(int i=0;iL.length-1;i+) for(int j=0;jL.elemj+1) t=L.elemj+1;L.elemj+1=L.elemj;L.elemj=t;
3、return OK; void ListPrint(Sqlist &L) /输出表内数据 ElemType e; for(int i=0;iL.length;i+) GetElem(L,i+1,e); coute ; 代码 Google Go代码 package mainimport ( io/ioutil net/http net/ fmt encoding/json) /-/ 黄金数据调用示例代码 聚合数据/ 在线接口文档:www/docs/29/- const APPKEY = * /您申请的APPKEY func main() /1.上海黄金交易所 Request1() /2.上海期货
4、交易所 Request2() /3.银行账户黄金 Request3() /1.上海黄金交易所func Request1() /请求地址 juhe :=web:8080/finance/gold/shgold /初始化参数 param:=.Values /配置请求参数,方法内部已处理encode问题,中文参数可以直接传参 param.Set(key,APPKEY) /APP Key param.Set(v,) /JSON格式版本(0或1)默认为0 /发送请求 data,err:=Get(juhe,param) if err!=nil fmt.Errorf(请求失败,错误信息:rn%v,err)
5、else var netReturn mapstringinterface json.Unmarshal(data,&netReturn) if netReturnerror_code.(float64)=0 fmt.Printf(接口返回result字段是:rn%v,netReturnresult) /2.上海期货交易所func Request2() /请求地址 juhe :=web:8080/finance/gold/shfuture /初始化参数 param:=.Values /配置请求参数,方法内部已处理encode问题,中文参数可以直接传参 param.Set(key,APPKEY)
6、 /APP Key param.Set(v,) /JSON格式版本(0或1)默认为0 /发送请求 data,err:=Get(juhe,param) if err!=nil fmt.Errorf(请求失败,错误信息:rn%v,err) else var netReturn mapstringinterface json.Unmarshal(data,&netReturn) if netReturnerror_code.(float64)=0 fmt.Printf(接口返回result字段是:rn%v,netReturnresult) /3.银行账户黄金func Request3() /请求地址
7、 juhe :=web:8080/finance/gold/bankgold /初始化参数 param:=.Values /配置请求参数,方法内部已处理encode问题,中文参数可以直接传参 param.Set(key,APPKEY) /APP Key /发送请求 data,err:=Get(juhe,param) if err!=nil fmt.Errorf(请求失败,错误信息:rn%v,err) else var netReturn mapstringinterface json.Unmarshal(data,&netReturn) if netReturnerror_code.(floa
8、t64)=0 fmt.Printf(接口返回result字段是:rn%v,netReturnresult) / get 网络请求func Get(api string,params .Values)(rsbyte ,err error) var *. ,err=.Parse(api) if err!=nil fmt.Printf(解析错误:rn%v,err) return nil,err /如果参数中有中文参数,这个方法会进行Encode .RawQuery=params.Encode() resp,err:=http.Get(.String() if err!=nil fmt.Println
9、(err:,err) return nil,err defer resp.Body.Close() return ioutil.ReadAll(resp.Body) / post 网络请求 ,params 是.Values类型func Post(api string, params .Values)(rsbyte,err error) resp,err:=http.PostForm(api, params) if err!=nil return nil ,err defer resp.Body.Close() return ioutil.ReadAll(resp.Body)代码描述:基于GO的
10、黄金数据接口调用代码实例关联数据:黄金数据代码 C#代码 using System;using System.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类下载地址:/- namespace ConsoleAPI class Program
11、 static void Main(string args) string appkey = *; /配置您申请的appkey /1.上海黄金交易所 string 1 = web:8080/finance/gold/shgold; var parameters1 = new Dictionary(); parameters1.Add(key, appkey);/你申请的key parameters1.Add(v , ); /JSON格式版本(0或1)默认为0 string result1 = sendPost(1, parameters1, get); JsonObject newObj1 =
12、 new JsonObject(result1); String errorCode1 = newObj1error_code.Value; if (errorCode1 = 0) Debug.WriteLine(成功); Debug.WriteLine(newObj1); else /Debug.WriteLine(失败); Debug.WriteLine(newObj1error_code.Value+:+newObj1reason.Value); /2.上海期货交易所 string 2 = web:8080/finance/gold/shfuture; var parameters2 =
13、 new Dictionary(); parameters2.Add(key, appkey);/你申请的key parameters2.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.WriteLine(成功); Debug.WriteLine(newOb
14、j2); else /Debug.WriteLine(失败); Debug.WriteLine(newObj2error_code.Value+:+newObj2reason.Value); /3.银行账户黄金 string 3 = web:8080/finance/gold/bankgold; var parameters3 = new Dictionary(); parameters3.Add(key, appkey);/你申请的key string result3 = sendPost(3, parameters3, get); JsonObject newObj3 = new Json
15、Object(result3); String errorCode3 = newObj3error_code.Value; if (errorCode3 = 0) Debug.WriteLine(成功); Debug.WriteLine(newObj3); else /Debug.WriteLine(失败); Debug.WriteLine(newObj3error_code.Value+:+newObj3reason.Value); / / Http (GET/POST) / / 请求 / 请求参数 / 请求方法 / 响应内容 static string sendPost(string ,
16、IDictionary parameters, string method) if (method.ToLower() = post) HttpWebRequest req = null; HttpWebResponse rsp = null; System.IO.Stream reqStream = null; try req = (HttpWebRequest)WebRequest.Create(); req.Method = method; req.KeepAlive = false; req.ProtocolVersion = HttpVersion.Version10; req.Ti
17、meout = 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.GetResponse(); Encoding encoding = Encoding
18、.GetEncoding(rsp.CharacterSet); return GetResponseAsString(rsp, encoding); catch (Exception ex) return ex.Message; finally if (reqStream != null) reqStream.Close(); if (rsp != null) rsp.Close(); else /创建请求 HttpWebRequest request = (HttpWebRequest)WebRequest.Create( + ? + BuildQuery(parameters, utf8)
19、; /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 StreamReader(myResponseStream, E
20、ncoding.GetEncoding(utf-8); /返回内容 string retString = myStreamReader.ReadToEnd(); return retString; / / 组装普通文本请求参数。 / / Key-Value形式请求参数字典 / 编码后的请求数据 static string BuildQuery(IDictionary parameters, string encode) StringBuilder postData = new StringBuilder(); bool hasParam = false; IEnumeratorKeyValue
21、Pair 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) postData.Append(&); postData.Append(name); postData.Append(=); if (encode = gb23
22、12) postData.Append(HttpUtility.Encode(value, Encoding.GetEncoding(gb2312); else if (encode = utf8) postData.Append(HttpUtility.Encode(value, Encoding.UTF8); else postData.Append(value); hasParam = true; return postData.ToString(); / / 把响应流转换为文本。 / / 响应流对象 / 编码方式 / 响应文本 static string GetResponseAsSt
23、ring(HttpWebResponse rsp, Encoding encoding) System.IO.Stream stream = null; StreamReader reader = null; try / 以字符流的方式读取HTTP响应 stream = rsp.GetResponseStream(); reader = new StreamReader(stream, encoding); return reader.ReadToEnd(); finally / 释放资源 if (reader != null) reader.Close(); if (stream != nu
24、ll) stream.Close(); if (rsp != null) rsp.Close(); 代码 PHP代码 /* * c远程传输工具 */public function post_c($,$body,$header,$type=POST) $ch = c_init(); c_setopt($ch,COPT_,$); c_setopt($ch,COPT_HEADER,0);/0只要正文 c_setopt($ch,COPT_TIMEOUT,5);/设置超时时间 c_setopt($ch,COPT_CONNECTTIMEOUT,5); /将c_exec()获取的信息以文件流的形式返回,而不
25、是直接输出。 c_setopt($ch,COPT_RETURNTRANSFER,1); /增加header头信息 / array_push($header,Accept:application/json); / array_push($header,Content-Type:application/json); / array_push($header,http:multipart/form-data); if(count($body)0) c_setopt($ch,COPT_POSTFIELDS,$body); if(count($header)0) c_setopt($ch,COPT_HT
26、TPHEADER,$header); /设置上传文件相关 c_setopt($ch,COPT_FOLLOWLOCATION,true); c_setopt($ch,COPT_MAXREDIRS,3);/递归 c_setopt($ch,COPT_SSL_VERIFYPEER,false);/ 对认证证书来源的检查 c_setopt($ch,COPT_SSL_VERIFYHOST,0);/ 从证书中检查SSL加密算法 switch ($type) case GET: c_setopt($ch,COPT_HTTPGET,1); break; case POST: c_setopt($ch,COPT_
27、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_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
28、; 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(!empty($result) return $result; else return $content; 代码 C/C+代码 /*编译指令$ /opt/sybase/OCS-16_0/bin/cpre64 -m teststu.cp$ cc -m64 -g -DSYB_LP64
29、-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 -lsybunic64 -rdynamic -ldl -lnsl -lm -o teststu*/#include /*建立通讯区域*/EXEC SQL INCLUDE SQLCA;/* * These tokens must be declared in a dec
30、lare section* because they are used in declare sections below.*/EXEC SQL BEGIN DECLARE SECTION;#define TYPESIZE 13#define TIDSIZE 6EXEC SQL END DECLARE SECTION; #define EOLN 0/* * Forward declarations of the error and message handlers and* other subroutines called from main().*/void error_handler();
31、void warning_handler(); 小型臭氧发生器 侳侱侲 intmain(int argc, char *argv)/*声明宿主变量*/ EXEC SQL BEGIN DECLARE SECTION; /* storage for login name and password. */ char username30; char sname30; char password30; char server30; EXEC SQL END DECLARE SECTION;/*错误处理*/ EXEC SQL WHENEVER SQLERROR CALL error_handler();
32、 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 declared for them in the declare section. */ strcpy(username, mymotif); strcpy(password, wxwpxh); strcpy(ser
33、ver, MYMOTIFVOSTRO145480); EXEC SQL CONNECT :username IDENTIFIED BY :password using :server; EXEC SQL USE testdb; EXEC SQL DECLARE c1 CURSOR FOR SELECT SNAME FROM STUDENT; EXEC SQL OPEN c1; printf(name in table studentn); do EXEC SQL FETCH c1 INTO :sname; if (sqlca.sqlcode != 0) break; printf( stude
34、nt 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(void) fprintf(stderr, n* SQLCODE=(%ld), sqlca.sqlcode); if (sqlca.sqlerrm.sqlerrml) fprintf(st
35、derr, 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(stderr, n* Data truncated.n); if (sqlca.sqlwarn3 = W) fprintf(stderr, n* Insufficient host variables to store results.n); re
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 客运船舶驾驶员班组考核能力考核试卷含答案
- 稀土磁性材料成型工安全知识竞赛考核试卷含答案
- 废钢加工工创新思维模拟考核试卷含答案
- 炭素配料工岗前持续改进考核试卷含答案
- 轧制加热工岗前冲突解决考核试卷含答案
- 机场雷达操纵修理工发展趋势强化考核试卷含答案
- 磨毛(绒)机挡车工安全实操测试考核试卷含答案
- 医疗器械装配工操作技能强化考核试卷含答案
- 贵金属首饰手工制作工安全生产规范评优考核试卷含答案
- 卷烟卷接设备操作工安全知识能力考核试卷含答案
- 小学语文课程的跨学科整合与教学设计
- 化工仪表事故案例1范文合集
- 人教版-数学五年级上册 数的运算、式与方程 全套
- 八年级上册数学教学工作总结(11篇)
- 职业病人员登记表
- 中国企业家投融资俱乐部
- 恩施市建筑垃圾综合利用处理厂可行性研究报告
- 高校辅导员素质能力大赛题库
- GB 3836.20-2010爆炸性环境第20部分:设备保护级别(EPL)为Ga级的设备
- 兽药营销课程资源库兽药产品策略课件
- 医院医疗欠费管理办法(医院财务管理制度)
评论
0/150
提交评论