iOS Block界面反向传值
发布时间:2024-11-28
发布时间:2024-11-28
iOS Block界面反向传值
iOS Block界面反向传值
iOS KVO注册和监听方法 iOS tableView的增加,删除,刷新,更新的方法...
[文件] iic.h ~ 2KB
#ifndef __IIC_H__
#define __IIC_H__
#include "config.h"
#define ADDR_PASSWORD (0) //密码:2个字节
#define ADDR_COM_SET (2) //系统地址和波特率
#define ADDR_TRIP_TIME (16) //脱扣时间
#define ADDR_FAULT_RECORD (26) //故障记录存储地址
#define ADDR_PROTECT_SET (172) //故障报警值
[代码] [Google Go]代码
package main
import (
"io/ioutil"
"net/http"
"net/"
"fmt"
"encoding/json"
)
//----------------------------------
// 黄金数据调用示例代码 - 聚合数据
// 在线接口文档:www/docs/29
//----------------------------------
iOS lizbqrencode 导入报错
const APPKEY = "*******************" //您申请的APPKEY
iOS UICollectionView 基本创建使用...
func main(){
//1.上海黄金交易所
Request1()
//2.上海期货交易所
Request2()
//3.银行账户黄金
Request3()
}
//1.上海黄金交易所
func Request1(){
//请求地址
juhe :="/finance/gold/shgold"
iOS Block界面反向传值
//初始化参数
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("请求失败,错误信息:\r\n%v",err)
}else{
var netReturn map[string]interface{}
json.Unmarshal(data,&netReturn)
if netReturn["error_code"].(float64)==0{
fmt.Printf("接口返回result字段是:\r\n%v",netReturn["result"]) }
}
}
//2.上海期货交易所
func Request2(){
//请求地址
juhe :=":8080/finance/gold/shfuture"
//初始化参数
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("请求失败,错误信息:\r\n%v",err)
}else{
var netReturn map[string]interface{}
json.Unmarshal(data,&netReturn)
if netReturn["error_code"].(float64)==0{
fmt.Printf("接口返回result字段是:\r\n%v",netReturn["result"])
iOS Block界面反向传值
}
}
}
//3.银行账户黄金
func Request3(){
//请求地址
juhe :=":8080/finance/gold/bankgold"
//初始化参数
param:=.Values{}
//配置请求参数,方法内部已处理encode问题,中文参数可以直接传参
param.Set("key",APPKEY) //APP Key
//发送请求
data,err:=Get(juhe,param)
if err!=nil{
fmt.Errorf("请求失败,错误信息:\r\n%v",err)
}else{
var netReturn map[string]interface{}
json.Unmarshal(data,&netReturn)
if netReturn["error_code"].(float64)==0{
fmt.Printf("接口返回result字段是:\r\n%v",netReturn["result"]) }
}
}
// get 网络请求
func Get(api string,params .Values)(rs[]byte ,err error){
var *.
,err=.Parse(api)
if err!=nil{
fmt.Printf("解析错误:\r\n%v",err)
return nil,err
}
//如果参数中有中文参数,这个方法会进行Encode
.RawQuery=params.Encode()
resp,err:=http.Get(.String())
if err!=nil{
fmt.Println("err:",err)
return nil,err
}
iOS Block界面反向传值
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
}
// post 网络请求 ,params 是.Values类型
func Post(api string, params .Values)(rs[]byte,err error){
resp,err:=http.PostForm(api, params)
if err!=nil{
return nil ,err
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
}
代码描述:基于GO的黄金数据接口调用代码实例
关联数据:黄金数据
[代码] [C#]代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using http://;
using System.IO;
using http://;
using System.Diagnostics;
using System.Web;
//----------------------------------
// 黄金数据调用示例代码 - 聚合数据
// 在线接口文档:www/docs/29
// 代码中JsonObject类下载地址:/download/gcm3206021155665/7458439
//----------------------------------
namespace ConsoleAPI
{
class Program
{
static void Main(string[] args)
{
string appkey = "*******************"; //配置您申请的appkey
//1.上海黄金交易所
string 1 = ":8080/finance/gold/shgold";
iOS Block界面反向传值
var parameters1 = new Dictionary<string, string>();
parameters1.Add("key", appkey);//你申请的key
parameters1.Add("v" , ""); //JSON格式版本(0或1)默认为0
string result1 = sendPost(1, parameters1, "get");
JsonObject newObj1 = new JsonObject(result1);
String errorCode1 = newObj1["error_code"].Value;
if (errorCode1 == "0")
{
Debug.WriteLine("成功");
Debug.WriteLine(newObj1);
}
else
{
//Debug.WriteLine("失败");
Debug.WriteLine(newObj1["error_code"].Value+":"+newObj1["reason"].Value); }
//2.上海期货交易所
string 2 = ":8080/finance/gold/shfuture";
var parameters2 = new Dictionary<string, string>();
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 = newObj2["error_code"].Value;
if (errorCode2 == "0")
{
Debug.WriteLine("成功");
Debug.WriteLine(newObj2);
}
else
{
//Debug.WriteLine("失败");
iOS Block界面反向传值
Debug.WriteLine(newObj2["error_code"].Value+":"+newObj2["reason"].Value); }
//3.银行账户黄金
string 3 = ":8080/finance/gold/bankgold";
var parameters3 = new Dictionary<string, string>();
parameters3.Add("key", appkey);//你申请的key
string result3 = sendPost(3, parameters3, "get");
JsonObject newObj3 = new JsonObject(result3);
String errorCode3 = newObj3["error_code"].Value;
if (errorCode3 == "0")
{
Debug.WriteLine("成功");
Debug.WriteLine(newObj3);
}
else
{
//Debug.WriteLine("失败");
Debug.WriteLine(newObj3["error_code"].Value+":"+newObj3["reason"].Value); }
}
/// <summary>
/// Http (GET/POST)
/// </summary>
/// <param name="">请求</param>
/// <param name="parameters">请求参数</param>
/// <param name="method">请求方法</param>
/// <returns>响应内容</returns>
static string sendPost(string , IDictionary<string, string> parameters, string method)
{
if (method.ToLower() == "post")
{
iOS Block界面反向传值
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.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.GetResponse();
Encoding encoding = Encoding.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"));
//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,
iOS Block界面反向传值
Encoding.GetEncoding("utf-8"));
//返回内容
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
/// <summary>
/// 组装普通文本请求参数。
/// </summary>
/// <param name="parameters">Key-Value形式请求参数字典</param>
/// <returns>编码后的请求数据</returns>
static string BuildQuery(IDictionary<string, string> parameters, string encode)
{
StringBuilder postData = new StringBuilder();
bool hasParam = false;
IEnumerator<KeyValuePair<string, 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)
{
postData.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));
}
iOS Block界面反向传值
else
{
postData.Append(value);
}
hasParam = true;
}
}
return postData.ToString();
}
/// <summary>
/// 把响应流转换为文本。
/// </summary>
/// <param name="rsp">响应流对象</param>
/// <param name="encoding">编码方式</param>
/// <returns>响应文本</returns>
static string GetResponseAsString(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 != null) stream.Close();
if (rsp != null) rsp.Close();
}
}
}
}
[代码] [PHP]代码
/**
* c远程传输工具
*/
public function post_c($,$body,$header,$type='POST'){
$ch = c_init();
c_setopt($ch,COPT_,$);
iOS Block界面反向传值
c_setopt($ch,COPT_HEADER,0);//0只要正文
c_setopt($ch,COPT_TIMEOUT,5);//设置超时时间
c_setopt($ch,COPT_CONNECTTIMEOUT,5);
//将c_exec()获取的信息以文件流的形式返回,而不是直接输出。
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_HTTPHEADER,$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_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; Trident/4.0)');// 模拟用户使用的浏览器
if(c_errno($ch)){
return c_error($ch);
}
$content = c_exec($ch);
c_close($ch);//关闭c资源,并且释放系统资源
iOS Block界面反向传值
$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 -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 <stdio.h>
/*建立通讯区域*/
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 TYPESIZE 13
#define TIDSIZE 6
EXEC SQL END DECLARE SECTION;
#define EOLN '\0'
/*
** Forward declarations of the error and message handlers and
** other subroutines called from main().
*/
void error_handler();
void warning_handler();
int
main(int argc, char *argv[])
{
/*声明宿主变量*/
EXEC SQL BEGIN DECLARE SECTION;
/* storage for login name and password. */
char username[30];
iOS Block界面反向传值
char sname[30];
char password[30];
char server[30];
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 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 FOR
SELECT SNAME FROM STUDENT;
EXEC SQL OPEN c1;
printf("name in table student\n");
do {
EXEC SQL FETCH c1 INTO :sname;
if (sqlca.sqlcode != 0) break;
printf( "student name = %s\n", 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.
*/
void
error_handler(void)
iOS Block界面反向传值
{
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, "\n\n");
exit(-1);
}
/*
** void warning_handler()
**
** Displays warning messages.
*/
void
warning_handler(void)
{
if (sqlca.sqlwarn[1] == 'W')
{
fprintf(stderr,
"\n** Data truncated.\n");
}
if (sqlca.sqlwarn[3] == 'W')
{
fprintf(stderr,
"\n** Insufficient host variables to store results.\n");
}
return;
}
[代码] Log4j配置
<!-- 日志jar -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
导入这个包,会引入下面两个jar
<!--spring 的基本jar包 -->
iOS Block界面反向传值
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- commons-login是必须的,而且没有依赖,是独立的包 -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>1.1</version>
</dependency>
<dependency><!-- transactionManager实务管理的时候,需要这个jar包 -->
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency><!--当spring-config.xml文件中配置<aop:aspect >需要加入此包 --> <groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
[文件] 无缝滚动.html ~ 1KB
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;padding: 0;
}
#wrap ul li{
width: 380px;
height: 230px;
float: left;
list-style: none;
}
#wrap ul{
position: absolute;
left: 0;
top: 0;
iOS Block界面反向传值
}
#wrap{
width: 1520px;
height: 230px;
margin: 100px 50px;
position: relative;
background: red;
overflow: hidden;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById('wrap');
var oUl=oDiv.getElementsByTagName('ul')[0];
var oLi=oUl.getElementsByTagName('li');
oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
oUl.style.width=oLi[0].offsetWidth*oLi.length+'px';
setInterval(function(){
if(oUl.offsetLeft<-oUl.offsetWidth/2){
oUl.style.left='0'
}
oUl.style.left=oUl.offsetLeft-2+'px';
},30)
}
</script>
</head>
<body>
<div id="wrap">
<ul>
<li><img src="img/tour1.jpg"/></li>
<li><img src="img/tour2.jpg"/></li>
<li><img src="img/tour3.jpg"/></li>
<li><img src="img/tour4.jpg"/></li>
</ul>
</div>
</body>
</html>
[代码] 获取的参数
//获取的参数
function getParam(paramKey){
//获取当前
iOS Block界面反向传值
var = location.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(getParamStr);
}
[代码] 添加参数
//添加参数
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,.indexOf("?"));
var next = "";
var arr = new Array();
if(Param!=""){
var ParamArr = Param.split("&");
for(var i=0;i<ParamArr.length;i++){
var paramArr = ParamArr[i].split("=");
if(paramArr[0]!=paramKey){
arr.push(ParamArr[i]);
}
}
}
上一篇:《网络营销》试卷分析
下一篇:广州小学英语-3-6年级单词分类