This repository has been archived by the owner on Jul 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unisender.class.php
76 lines (74 loc) · 2.11 KB
/
unisender.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
<?php
class Unisender
{
protected $apikey = '';
protected $apiurl = 'https://api.unisender.com/ru/api/';
protected $lastrequest = 'No result';
function __construct($key) {
$this->apikey=$key;
}
function request($r) {
$this->lastrequest=$r;
if($curl = curl_init()) {
curl_setopt($curl, CURLOPT_URL, $r);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 6);
curl_setopt($curl, CURLOPT_ENCODING, 'utf8');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLINFO_HEADER_OUT, false);
$a = curl_exec($curl);
curl_close($curl);
return $a;
} else {
return ['error' => 'cant find curl on your system'];
}
}
function getlast() {
return $this->lastrequest;
}
function r_quest($m, $pams = []) {
$r=$this->apiurl.$m."?format=json&request_compression=bzip2&api_key=".$this->apikey;
if(!empty($pams)) {
foreach ($pams as $key => $value) {
$r.='&'.$key.'='.urlencode($value);
}
}
return json_decode($this->request($r));
}
function getLists() {
return $this->r_quest('getLists');
}
function subscribe($list_ids, $pams = []) {
foreach ($pams as $key => $value) {
$pams['fields['.$key.']'] = $value;
unset($pams[$key]);
}
$pams['list_ids']=$list_ids;
return $this->r_quest('subscribe',$pams);
}
function import($listids,$pams) {
if(count($pams) > 3) return false;
if(count($pams) == 2) {
foreach ($pams as $key => $value) {
$pams['data[0]['.$key.']'] = $value;
unset($pams[$key]);
}
$pams['field_names[0]'] = 'Name';
$pams['field_names[1]'] = 'email';
$pams['field_names[2]'] = 'email_list_ids';
$pams['data[0][2]'] = $listids;
return $this->r_quest('importContacts',$pams);
}
foreach ($pams as $key => $value) {
$pams['data[0]['.$key.']'] = $value;
unset($pams[$key]);
}
$pams['field_names[0]'] = 'Name';
$pams['field_names[1]'] = 'email';
$pams['field_names[2]'] = 'phone';
$pams['field_names[3]'] = 'email_list_ids';
$pams['data[0][3]'] = $listids;
return $this->r_quest('importContacts',$pams);
}
}