Initial commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Model;
|
||||
use Think\Model;
|
||||
class KuaidiModel extends Model{
|
||||
public function __construct($com,$num){
|
||||
$this->com=$com;
|
||||
$this->num=$num;
|
||||
}
|
||||
//快递接口api查询
|
||||
public function getKuaidi(){
|
||||
$post_data = array();
|
||||
$post_data["customer"] = C("shop.customer");
|
||||
$key= C("shop.sign");
|
||||
$post_data["param"]=array(
|
||||
"com"=>$this->com,
|
||||
"num"=>$this->num
|
||||
);
|
||||
$post_data["param"] = json_encode($post_data["param"]);
|
||||
$url='http://poll.kuaidi100.com/poll/query.do';
|
||||
$post_data["sign"] = md5($post_data["param"].$key.$post_data["customer"]);
|
||||
$post_data["sign"] = strtoupper($post_data["sign"]);
|
||||
$o="";
|
||||
foreach ($post_data as $k=>$v)
|
||||
{
|
||||
$o.= "$k=".$v."&"; //默认UTF-8编码格式
|
||||
}
|
||||
$post_data=substr($o,0,-1);
|
||||
$url2=$url."?".$post_data;
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_URL,$url);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$result = curl_exec($ch);
|
||||
$data = str_replace("\"",'"',$result );
|
||||
$data = json_decode($data,true);
|
||||
//检测状态
|
||||
if($data["status"]!=200){
|
||||
$this->error=$data["message"];
|
||||
return false;
|
||||
}else{
|
||||
return $data["data"];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user