您的位置:首页 > 移动开发 > 微信开发

微信公众平台开发--快递查询

2013-11-26 10:02 225 查看
1)API申请

2)手机查询API



3)服务器要求

--------------------------------------------------------------------------

1)API申请

快递100提供查询接口API,需要申请Key http://www.kuaidi100.com/openapi/applyapi.shtml

查询数量有限制,2013-11-19 最多 2000次/每天

申请条件之一,为快递100提供链接,在网站首页

申请了2次失败了

2)手机查询API

快递100提供手机查询API,http://www.kuaidi100.com/openapi/mobileapi.shtml

不需要申请Key,免费;但是,返回结果是html,需要解析

通过simple_html_dom.php解析html,终于得到想要的结果

[php]
view plaincopyprint?





<?php /* 快递100 提供的接口,返回html; 使用 simple_html_dom 解析html,得到快递结果 d_eng (sh109419@163.com) 2013-11-20 */ /* 天天快递查询电话:4001-888-888<br> <br>天天快递单号:560050137619<br>查询结果如下所示:<br>·2013-11-18 16:58:30 快件已到达【上海虹口一部】 扫描员是【11】上一站是【上海集散】<br>·2013-11-18 18:46:19 【上海普陀二部】的收件员【高军13916321314】已收件<br>·2013-11-18 22:28:08 由【上海普陀二部】发往【上海集散】<br>·2013-11-19 00:38:31 由【上海集散】发往【上海虹口一部】<br>·2013-11-19 08:13:32 快件已到达【上海虹口一部】 扫描员是【21242.1010】上一站是【上海集散】<br>·2013-11-19 08:54:45 【上海虹口一部】的派件员【孔明】正在派件<br>·2013-11-19 10:58:14 已签收,签收人是【同事代签】 */ header("Content-Type:text/html; charset=utf-8"); include("simple_html_dom.php"); function express($company,$code) { // get html $url = "http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=".$company."&fromWeb=null&&postid=".$code; $html=file_get_contents($url) or die(); //get form part $x=explode("</form>",$html); $x=explode("<form",$x[0]); $form = "<form".$x[1]."</form>"; // create dom $dom = str_get_html($form); // 找到所有<p> $text = ""; foreach($dom->find('p') as $element) { if ($text<>"") $text = $text.'<br>'; $text = $text.$element->plaintext; } return $text; } echo express('shentong','668711492860'); echo '<br>'; echo '<br>'; echo express('tiantian','560050137619'); echo '<br>'; echo '<br>'; echo express('yunda','1900497688272'); ?>
<?php
/*
快递100 提供的接口,返回html;
使用 simple_html_dom 解析html,得到快递结果

d_eng (sh109419@163.com)
2013-11-20
*/
/*
天天快递查询电话:4001-888-888<br>              <br>天天快递单号:560050137619<br>查询结果如下所示:<br>·2013-11-18 16:58:30
快件已到达【上海虹口一部】          扫描员是【11】上一站是【上海集散】<br>·2013-11-18 18:46:19
【上海普陀二部】的收件员【高军13916321314】已收件<br>·2013-11-18 22:28:08
由【上海普陀二部】发往【上海集散】<br>·2013-11-19 00:38:31
由【上海集散】发往【上海虹口一部】<br>·2013-11-19 08:13:32
快件已到达【上海虹口一部】          扫描员是【21242.1010】上一站是【上海集散】<br>·2013-11-19 08:54:45
【上海虹口一部】的派件员【孔明】正在派件<br>·2013-11-19 10:58:14
已签收,签收人是【同事代签】
*/

header("Content-Type:text/html; charset=utf-8");
include("simple_html_dom.php");
function express($company,$code) {

// get html
$url = "http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=".$company."&fromWeb=null&&postid=".$code;
$html=file_get_contents($url) or die();

//get form part
$x=explode("</form>",$html);
$x=explode("<form",$x[0]);
$form = "<form".$x[1]."</form>";

// create dom
$dom = str_get_html($form);
// 找到所有<p>
$text = "";
foreach($dom->find('p') as $element) {
if ($text<>"") $text = $text.'<br>';
$text = $text.$element->plaintext;
}
return $text;
}

echo express('shentong','668711492860');
echo '<br>';
echo '<br>';
echo express('tiantian','560050137619');
echo '<br>';
echo '<br>';
echo express('yunda','1900497688272');

?>


3)服务器要求

快递100不支持新浪SAE平台,后来试了

a) 移动的MMAE平台,倒是可以;但MMAE比较慢,不稳定,放弃

b) 腾讯云平台,开户送了200,但是,一个月PHP+mySQL差不多要200,放弃

c) 申请百度云平台,BAE可以访问快递100,but,BAE不支持Google翻译,

OK,解决方案,微信服务程序放在BAE,google翻译放在SAE,

微信使用google翻译的时候,命令发送到微信服务程序(BAE),从BAE远程调用google翻译结果(SAE)

快递调用demo做好,服务器环境建设好,开发微信程序就简单了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: