![]() |
#2
huaxialonger2010-07-19 18:03
手头只有一PHP例子,但需要ASP。。。,谁帮忙给翻译一下
function getBalance($reg, $pwd){ $res = new ResFee(); if($reg == null || strlen($reg) == 0){ $res->result = -1; $res->des = "注册号不能为空!"; return res; } if($pwd == null || strlen($pwd) == 0) { $res->result = -1; $res->des = "密码不能为空!"; return res; } $path = "<END><COMMAND>S059</COMMAND><REGISTRYCODE>$reg</REGISTRYCODE><PWD>$pwd</PWD></END>"; $path=mb_convert_encoding($path, "UTF-8", "GBK"); $address = gethostbyname($this->host); /* Create a TCP/IP socket. */ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $result = socket_connect($socket, $address, $this->port); // make header $in = "GET ".$path." HTTP/1.0\r\n"; $in .= "Content-Type: application/x-www-form-urlencoded\r\n"; $in .= "\r\n\r\n"; // out data $out = ''; socket_write($socket, $in, strlen($in)); while ($out = socket_read($socket, 2048)) { $temp_out .= $out; //结束标志 if (preg_match("/<\/DES>/",$temp_out )) { break; } } //关闭socket链接 socket_close($socket); //处理返回结果 preg_match("/<DES>(.*)<\/DES>/i",$temp_out,$matches); //处理返回结果$matches[1] $i = strpos($matches[1],'result=', 0); $j = strpos($matches[1],'&balance=', 0); if($j >0){ if(($j - $i - 7) <= 0){ $res->result = -1; $res->des = '接收服务器错误!'; $res->balance = -1; }else if (($j - $i - 7) > 0) { $result = (int)substr($matches[1],$i+7,$j); if((strlen($matches[1])- $j - 4)>0){ $des = substr($matches[1],$j + 9,strlen($matches[1])); $res->result = $result; $res->des = '查询余额成功'; $res->balance = (int)$des; }else{ $res->result = -1; $res->des = '接收服务器错误!'; $res->balance = -1; } } } return $res; } |
今天从网上找了一天,关于ASP Socket的例子,都没有找到。希望大家能给个例子,实现从服务器上获取信息就可以。
下面是PHP的源码,求相关的ASP源码
function getBalance($reg, $pwd){
$res = new ResFee();
if($reg == null || strlen($reg) == 0){
$res->result = -1;
$res->des = "注册号不能为空!";
return res;
}
if($pwd == null || strlen($pwd) == 0) {
$res->result = -1;
$res->des = "密码不能为空!";
return res;
}
$path = "<END><COMMAND>S059</COMMAND><REGISTRYCODE>$reg</REGISTRYCODE><PWD>$pwd</PWD></END>";
$path=mb_convert_encoding($path, "UTF-8", "GBK");
$address = gethostbyname($this->host);
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //主要是这个方法,在ASP里不知道怎么用
$result = socket_connect($socket, $address, $this->port); //还有这个
// make header
$in = "GET ".$path." HTTP/1.0\r\n";
$in .= "Content-Type: application/x-www-form-urlencoded\r\n";
$in .= "\r\n\r\n";
// out data
$out = '';
socket_write($socket, $in, strlen($in)); //不知道这个方法在ASP里有没有对应的方法
while ($out = socket_read($socket, 2048)) {
$temp_out .= $out;
//结束标志
if (preg_match("/<\/DES>/",$temp_out )) {
break;
}
}
//关闭socket链接
socket_close($socket);
//处理返回结果
preg_match("/<DES>(.*)<\/DES>/i",$temp_out,$matches);
//处理返回结果$matches[1]
$i = strpos($matches[1],'result=', 0);
$j = strpos($matches[1],'&balance=', 0);
if($j >0){
if(($j - $i - 7) <= 0){
$res->result = -1;
$res->des = '接收服务器错误!';
$res->balance = -1;
}else if (($j - $i - 7) > 0) {
$result = (int)substr($matches[1],$i+7,$j);
if((strlen($matches[1])- $j - 4)>0){
$des = substr($matches[1],$j + 9,strlen($matches[1]));
$res->result = $result;
$res->des = '查询余额成功';
$res->balance = (int)$des;
}else{
$res->result = -1;
$res->des = '接收服务器错误!';
$res->balance = -1;
}
}
}
return $res;
}