深圳通余额查询的API,可以通过深圳通号码查询到余额及卡有效期等信息。 用到Domxpath和Curl两方面的知识。 源码已托管到github,另外要加载个类:myclass 项目地址:https://github.com/skiy/dev 演示:http://api.oupag.com/dev/api/shenzhentong.php?cardn
深圳通余额查询的API,可以通过深圳通号码查询到余额及卡有效期等信息。
用到Domxpath和Curl两方面的知识。
源码已托管到github,另外要加载个类:myclass
项目地址:https://github.com/skiy/dev
演示:http://api.oupag.com/dev/api/shenzhentong.php?cardno=293005762
update 2014.10.20 22:53
原来可以直接用GET方式,不需要用curl的POST方式来处理,这样响应快些~
PHP
<?php /** * shenzhentong.php * 深圳通的API * @autuor: Skiychan * @contact: developer@zzzzy.com & QQ:1005043848 * @website: www.zzzzy.com & http://weibo.com/ckiy * @date: 2014-10-19 * @readme https://github.com/skiy/dev/blob/master/docs/shenzhentong.md */ /** 链接:http://query.shenzhentong.com:8080/sztnet/qrycard.jsp 接口信息 URL:http://query.shenzhentong.com:8080/sztnet/qryCard.do http://query.shenzhentong.com:8080/sztnet/qryCard.do?cardno=328375558 POST方法:cardno:328375558 ### 返回字段 json格式 返回值字段 | 字段类型 | 字段说明 ----|------|---- card_number | int | 卡号 card_balance | string | 卡内余额 balance_time | string | 余额截止时间 card_validity | string | 卡有效期 current_time | string | 查询时间 */ require_once "../libs/myclass.php"; date_default_timezone_set("Asia/Shanghai"); $cardno = isset($_GET["cardno"]) ? $_GET["cardno"] : 0; $post_cardno = "cardno={$cardno}"; $data = new Myclass(); //curl 的POST方式 //$page = $data->curls("http://query.shenzhentong.com:8080/sztnet/qryCard.do", false, $post_cardno); //直接GET方式 $page = $data->curls("http://query.shenzhentong.com:8080/sztnet/qryCard.do?cardno={$cardno}"); $page = $data->pageToDom($page, "GBK"); $tr = $page->query("//table[@class='tableact']/tr/td"); function getTextContent($m_query, $m_id) { $myTXT = str_replace(":", "", $m_query->item($m_id)->textContent); return $myTXT; } //截止时间内余额 preg_match("/截止到([^\)]*)/", getTextContent($tr, 2), $expires); $results = array( "card_number" => (int) getTextContent($tr, 1), "card_balance" => getTextContent($tr, 3), "balance_time" => $expires[1], "card_validity" => getTextContent($tr, 5), "current_time" => date("Y-m-d H:i:s", time())); echo json_encode($results); ?>
<?php /** * myclass.php * dev的基础类库 * Autuor: Skiychan * Contact: developer@zzzzy.com & QQ:1005043848 * Website: www.zzzzy.com & http://weibo.com/ckiy * Date: 2014-10-19 */ class Myclass { /* curl配置: 取网页源码、模拟登陆、POST提交 * @param $url: 如果非数组,则为http;如是数组,则为https * @param $header: 头文件 * @param $post: post方式提交 array 或 abc=1&bcd=2 形式 * @param $cookies: 0默认无cookie,1为设置,2为获取 */ public function curls($urls, $header = FALSE, $post = FALSE, $cookies = 0) { $url = is_array($urls) ? $urls['0'] : $urls; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //带header方式提交 if($header != FALSE){ curl_setopt($ch, CURLOPT_HTTPHEADER, $header); } //post提交方式 if($post != FALSE){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } //cookies if($cookies == 1){ curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile"); }else if($cookies == 2){ curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile"); } //https if(is_array($urls)){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } $data = curl_exec($ch); curl_close($ch); return $data; } /* 将网页转换成XML,再转换成DOM * @param $data 非数组=>源码,数组 array($url, 1)1为file_get_contents,2为curl */ public function pageToDom($data, $encoded = "utf-8"){ if (is_array($data)) { if ($data[1] == 1) { $datas = @file_get_contents($data[0]); } if ($data[1] == 2) { $datas = @$this->curls($data[0]); } } else { $datas = $data; } if (empty($datas)){ return false; } $meta = '<meta http-equiv="Content-Type" content="text/html; charset='.$encoded.'"/>'; $datas = $meta.$datas; $xmldoc = new DOMDocument(); @$xmldoc->loadHTML($datas); $xmldoc->normalizeDocument(); $domresult = new Domxpath($xmldoc); return $domresult; } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
