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_str = '
';
*/
$d_province = $address['d_province'];
$d_city = $address['d_city'];
$d_county = $address['d_county'];
$d_company = $address['d_company'];
$d_contact = $address['d_contact'];
$d_tel = $address['d_tel'];
$d_address = $address['d_address'];
/*
$xml_str = '
";
$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;
}
}