Files
wsa_server/models/Sf_express_model.php.20240424
T
2026-09-14 16:32:07 +08:00

213 lines
5.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* 顺丰对接
* luoxuancai
* @extends CI_Model
* @link https://qiao.sf-express.com/pages/developDoc/index.html?level2=460077
*/
class Sf_express_model extends MY_Model {
protected $table = 'ship_order';
public function request($xmlContent)
{
$conf = $this->config->item('sf-express');//echo($xmlContent);die;
//请求报文拼接顾客编码MD5加密再base64加密
$verifyCode = base64_encode(md5($xmlContent . $conf['checkword'],TRUE));
//$verifyCode = base64_encode(substr(md5($xmlContent . $conf['checkword']), 8, 16));
//发送参数
$post_data = array(
'xml' => $xmlContent,
'verifyCode' => $verifyCode
);
$resultCont = $this->send_post('http://bsp-oisp.sf-express.com/bsp-oisp/sfexpressService', $post_data);
//提示重复下单或不存在的顾客编码请修改txt文件内对应参数
$xml = simplexml_load_string($resultCont);
if(isset($xml->ERROR)){
$attr = $xml->ERROR->attributes();
return [false,(string)$xml->ERROR,(int)$attr->code];
}
return [true,$xml->Body];
}
/**
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
function send_post($url, $post_data) {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded;charset=utf-8',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s
)
);
$context = stream_context_create($options);
return file_get_contents($url, false, $context);
}
//寄送样品并获取运单号
public function shipSample($address=[])
{
$conf = $this->config->item('sf-express');
/*
$xml_str = '<?xml version="1.0" encoding="UTF-8"?>
<Request service="OrderService" lang="zh-CN">
<Head></Head>
<Body>
<Order
orderid=""
express_type="1"
j_province=""
j_city=""
j_county=""
j_company=""
j_contact=""
j_tel=""
j_address=""
d_province="上海"
d_city="上海市"
d_county="嘉定区"
d_company="有哈科技"
d_contact="有哈科技收样组"
d_tel="17321358370"
d_address="兴贤路1180号5栋208室"
parcel_quantity="1"
pay_method="2"
custid =""
is_docall="1"
>
</Order>
</Body>
</Request>';
*/
/*
$xml_str = '<?xml version="1.0" encoding="UTF-8"?>
<Request service="OrderService" lang="zh-CN">
<Head></Head>
<Body>
<Order
orderid=""
express_type="1"
j_province=""
j_city=""
j_county=""
j_company=""
j_contact=""
j_tel=""
j_address=""
d_province="广东省"
d_city="深圳市"
d_county="龙岗区"
d_company="有哈科技"
d_contact="有哈科技样本收集组"
d_tel="13733206710"
d_address="大鹏新区布新路97号"
parcel_quantity="1"
pay_method="2"
custid =""
is_docall="1"
>
</Order>
</Body>
</Request>';
*/
$xml_str = '<?xml version="1.0" encoding="UTF-8"?>
<Request service="OrderService" lang="zh-CN">
<Head></Head>
<Body>
<Order
orderid=""
express_type="1"
j_province=""
j_city=""
j_county=""
j_company=""
j_contact=""
j_tel=""
j_address=""
d_province="广东省"
d_city="深圳市"
d_county="龙岗区"
d_company="有哈科技"
d_contact="王先生"
d_tel="17596551135"
d_address="大鹏新区布新路97号农科院基因组所A栋"
parcel_quantity="1"
pay_method="2"
custid =""
is_docall="1"
>
</Order>
</Body>
</Request>';
$xml = simplexml_load_string($xml_str);
$xml->Head = $conf['clientCode'];
//属性
$order_attr = $xml->Body->Order->attributes();
$order_attr->orderid=$address['trade_id'];
$order_attr->j_province=$address['province'];
$order_attr->j_city=$address['city'];
$order_attr->j_county=$address['district'];
$order_attr->j_contact=$address['name'];
$order_attr->j_tel=$address['tel'];
$order_attr->j_address=$address['address'];
//月结卡号:测试卡号7551234567
$order_attr->custid=$conf['custid'];
$ret = $this->request($xml->asXML());
if(!$ret[0]){
log_message('error', $ret[1]);
return [false,$ret[1]];
}
$attr = $ret[1]->OrderResponse->attributes();
$row_base = [
'user_id'=>$address['user_id'],
'mail_no'=>(string)$attr->mailno,//
'partner_code'=>$address['trade_id'],//
'trade_id'=>$address['trade_id'],
"sender_id"=> $address['user_id'],
"sender_name"=> $address['name'],
"sender_mobile"=> $address['tel'],
"sender_prov"=> $address['province'],
"sender_city"=> $address['city'],
"sender_county"=> $address['district'],
"sender_address"=> $address['address'],
"express"=> '2',
];
$this->add($row_base);
return [true,$row_base['mail_no']];
}
//测试寄送样品并获取运单号
public function test($address)
{
$row_base = [
'user_id'=>$address['user_id'],
'mail_no'=>'1',//
'partner_code'=>$address['trade_id'],//
'trade_id'=>$address['trade_id'],
"sender_id"=> $address['user_id'],
"sender_name"=> $address['name'],
"sender_mobile"=> $address['tel'],
"sender_prov"=> $address['province'],
"sender_city"=> $address['city'],
"sender_county"=> $address['district'],
"sender_address"=> $address['address'],
];
$id = $this->add($row_base);
var_dump($id);die;
}
}