1ea3b987
Administrator
maby first commit
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
/////////////////////////////////////////////////////////////////////////////
/**
* Запрос на расчёт стоимости доставки
$to_city — город получатель
$weight — вес
$pub_price — заявленная стоимость
$height — высота коробки
$width — ширина коробки
$depth — длинна коробки
*/
public function price( $to_city, $pub_price, $weight, $height = 50, $width = 20, $depth = 20 )
{
$xml=
'<?xml version="1.0" encoding="utf-8"?>
<file>
<auth>'.$this->_api_key.'</auth>
<countPrice>
<senderCity>'.$this->_out_city.'</senderCity>
<recipientCity>'.$to_city.'</recipientCity>
<mass>'.$weight.'</mass>
<height>'.$height.'</height>
<width>'.$width.'</width>
<depth>'.$depth.'</depth>
<publicPrice>'.$pub_price.'</publicPrice>
<deliveryType_id>4</deliveryType_id>
<floor_count>0</floor_count>
<date>'.date( 'd.m.Y' ).'</date>
</countPrice>
</file>';
//p($xml,1);
$xml = simplexml_load_string($this->send($xml));
return strval($xml->cost);
}
/////////////////////////////////////////////////////////////////////////////
/**
* Запрос на создание декларации на отправку
$order_id — номер заказа на вашем сайте (для вашего удобства)
$city — город получения
$warehouse — номер склада получения
$name — имя получателя
$phone — телефон получателя
$weight — вес посылки
$pub_price — заявленная стоимость
$date — дата отправки
$payer — плательщик (1 — получатель, 0 — отправитель, 2 — третья сторона)
*/
/////////////////////////////////////////////////////////////////////////////
public function ttn( $order_id, $city, $warehouse, $street_name, $name, $phone, $weight, $pub_price, $payer=0)
{
$xml =
'<?xml version="1.0" encoding="utf-8"?>
<file>
<auth>'.$this->_api_key.'</auth>
<order
order_id="'.$order_id.'"
sender_city="'.$this->_out_city.'"
sender_company="'.$this->_out_company.'"
sender_address="'.$this->_out_warehouse.'"
sender_contact="'.$this->_out_name.'"
sender_phone="'.$this->_out_phone.'"
rcpt_name="'.$this->_rcpt_name.'"
rcpt_city_name="'.$city.'" '.
(
!empty( $warehouse )
?
'rcpt_warehouse="'.$warehouse.'" '
:
'rcpt_street_name="'.$street_name.'" '
).
'rcpt_contact="'.$name.'"
rcpt_phone_num="'.$phone.'"
pack_type="'.$this->_pack.'"
description="'.$this->_description.'"
pay_type="1"
payer="'.$payer.'"
cost="'.$pub_price.'"
date="'.date( 'd.m.Y' ).'"
weight="'.$weight.'">
<order_cont
cont_description="'.$this->_description.'" />
</order>
</file>';
$xml = simplexml_load_string($this->send($xml));
//return array('oid'=>$order_id,'ttn'=>trim($xml->order->attributes()->np_id));
return strval($xml->order->attributes()->np_id);
}
/////////////////////////////////////////////////////////////////////////////
public function ttn_ref( $order_id, $city_ref, $warehouse_ref, $street_name, $name, $phone, $weight, $pub_price, $payer=0)
{
$xml =
'<?xml version="1.0" encoding="utf-8"?>
<file>
<auth>'.$this->_api_key.'</auth>
<order
order_id="'.$order_id.'"
sender_city_ref="'.$this->_sender_city_ref.'"
sender_company="'.$this->_out_company.'"
sender_warehouse_ref="'.$this->_sender_warehouse_ref.'"
sender_contact="'.$this->_out_name.'"
sender_phone="'.$this->_out_phone.'"
rcpt_name="'.$this->_rcpt_name.'"
rcpt_city_ref="'.$city_ref.'" '.
(
!empty( $warehouse_ref )
?
'rcpt_warehouse_ref="'.$warehouse_ref.'" '
:
'rcpt_street_name="'.$street_name.'" '
).
'rcpt_contact="'.$name.'"
rcpt_phone_num="'.$phone.'"
pack_type="'.$this->_pack.'"
description="'.$this->_description.'"
pay_type="1"
payer="'.$payer.'"
cost="'.$pub_price.'"
date="'.date( 'd.m.Y' ).'"
weight="'.$weight.'">
<order_cont
cont_description="'.$this->_description.'" />
</order>
</file>';
$xml = simplexml_load_string($this->send($xml));
//return array('oid'=>$order_id,'ttn'=>trim($xml->order->attributes()->np_id));
return strval($xml->order->attributes()->np_id);
}
/////////////////////////////////////////////////////////////////////////////
/**
* Запрос на удаление декларации из базы Новой почты
$ttn — номер декларации, которую нужно удалить
*/
public function remove($ttn)
{
$xml =
'<?xml version="1.0" encoding="utf-8"?>
<file>
<auth>'.$this->_api_key.'</auth>
<close>'.$ttn.'</close>
</file>';
$xml = simplexml_load_string($this->send($xml));
return $xml;
}
/////////////////////////////////////////////////////////////////////////////
/**
* Запрос на печать маркировок для декларации (производит перенаправление на страницу печати)
$ttn — номер декларации, которую нужно напечатать
*/
public static function printit($ttn){
header('location: http://orders.novaposhta.ua/pformn.php?o='.$ttn.'&num_copy=4&token='.NP::$api_key);
}
/////////////////////////////////////////////////////////////////////////////
/**
* Запрос на получение списка складов Новой почты для определённого города (или полный список, если город не указан)
$filter — город, по которому нужно отфильтровать список складов Новой почты
*/
|