<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
 class express_zto { private static $instance; public static function init(){ if (is_null(self::$instance)){ self::$instance = new self(); } return self::$instance; } function __construct($config){ $this->company_id = $config['company_id']; $this->key_id = $config['key_id']; $this->partner = $config['partner']; } function get_code($pro_row){ $post_data = array(); if($this->partner == 'test'){ $post_data['id'] = 'xfs101100111011'; $post_data['mailno'] = '1000000000016'; $url = 'http://58.40.16.125:9001/gateway.do'; }else{ $post_data['id'] = $pro_row['bill_no']; $url = 'http://japi.zto.cn/gateway.do'; } $post_data['partner'] = $this->partner; $post_data['typeid'] = '1'; $post_data['order_type'] = '0'; $post_data['sender']['name'] = $pro_row['receive']['name']; $post_data['sender']['mobile'] = $pro_row['receive']['mobile']; $post_data['sender']['city'] = $pro_row['receive']['prov_cn'].','.$pro_row['receive']['city_cn'].','.$pro_row['receive']['dist_cn']; $post_data['sender']['address'] = $pro_row['receive']['address']; $post_data['receiver']['name'] = $pro_row['send']['name']; $post_data['receiver']['mobile'] = $pro_row['send']['mobile']; $post_data['receiver']['city'] = $pro_row['send']['prov_cn'].','.$pro_row['send']['city_cn'].','.$pro_row['send']['dist_cn']; $post_data['receiver']['address'] = $pro_row['send']['address']; $post_data = json_encode($post_data); $data['company_id'] = $this->company_id; $data['msg_type'] = 'PARTNERINSERT_SUBMITAGENT'; $data['data'] = $post_data; $data['data_digest'] = $this->sign($post_data, $this->key_id); $result = curl::post($url, $data); $code = json_decode($result); if($code->result == false){ return array('error'=>'1','msg'=>$code->message); }else{ $callback['code'] = $code; $callback['mark'] = $this->get_mark($pro_row); $callback['express_code'] = $code->data->billCode; $callback['express_name'] = 'zto'; $callback['error'] = '0'; return $callback; } } function get_mark($pro_row){ $url = "http://japi.zto.cn/gateway.do"; $post_data = array( 'unionCode'=>'12', 'send_province'=>$pro_row['send']['prov_cn'], 'send_address'=>$pro_row['send']['address'], 'receive_province'=>$pro_row['receive']['prov_cn'], 'receive_city'=>$pro_row['receive']['city_cn'], 'receive_district'=>$pro_row['receive']['dist_cn'], 'receive_address'=>$pro_row['receive']['address'], ); $post_data = json_encode($post_data); $data['company_id'] = $this->company_id; $data['msg_type'] = 'TRACEABLEMARK_GETMARK'; $data['data'] = $post_data; $data['data_digest'] = $this->sign($post_data, $this->key_id); $result = curl::post($url, $data); $result = json_decode($result); return $result; } function get_yue(){ $url = "http://japi.zto.cn/gateway.do"; $data['company_id'] = $this->company_id; $data['msg_type'] = 'TIANZHOUSERVICE_BALANCERETURNENTITY'; $data['data'] = ''; $data['data_digest'] = $this->sign($post_data, $this->key_id); $result = curl::post($url, $data); } function sign($data, $key_id){ return base64_encode(md5($data.$key_id, TRUE)); } } 