-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestapi.php
93 lines (84 loc) · 3.86 KB
/
testapi.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
if (!@include('lib/pear/XML/RPC.php')) {
die('Error: cannot load the PEAR XML_RPC class');
}
$xmlRpcHost = 'mclick.mobi';
$webXmlRpcDir = '/www/api/v1/xmlrpc';
$logonXmlRpcWebServiceUrl = $webXmlRpcDir . '/LogonXmlRpcService.php';
$publisherXmlRpcWebServiceUrl = $webXmlRpcDir . '/PublisherXmlRpcService.php';
$zoneXmlRpcWebServiceUrl = $webXmlRpcDir . '/ZoneXmlRpcService.php';
//--------------------------------------------------replace your username and password here
$username = 'user_admin';
$password = 'user_admin';
//
function returnXmlRpcResponseData($oResponse)
{
if (!$oResponse->faultCode()) {
$oVal = $oResponse->value();
$data = XML_RPC_decode($oVal);
return $data;
} else {
die('Fault Code: ' . $oResponse->faultCode() . "\n" .
'Fault Reason: ' . $oResponse->faultString() . "\n");
}
}
//s--------------------------------------------------tart login with user and password you insert
$aParams = array(
new XML_RPC_Value($username, 'string'),
new XML_RPC_Value($password, 'string')
);
$oMessage = new XML_RPC_Message('logon', $aParams);
$oClient = new XML_RPC_Client($logonXmlRpcWebServiceUrl, $xmlRpcHost);
$oResponse = $oClient->send($oMessage);
if (!$oResponse) {
die('Communication error: ' . $oClient->errstr);
}
$sessionId = returnXmlRpcResponseData($oResponse);
echo 'User logged on with session Id : ' . $sessionId . '<br>';
//--------------------------------------------------end login with api
//--------------------------------------------------this function start insert Website to your account , you need change agencyId with your id account and change fields ( publisherName,contactName,emailAddress,website,username....)
$Publisher = new XML_RPC_Value(
array(
'agencyId' => new XML_RPC_Value(10,'int'),
'publisherName' => new XML_RPC_Value('tuan eway', 'string'),
'contactName' => new XML_RPC_Value('tuan eway2', 'string'),
'emailAddress' => new XML_RPC_Value('[email protected]', 'string'),
'website' => new XML_RPC_Value('eway-tuan.vn', 'string'),
'username' => new XML_RPC_Value('tuan_eway', 'string'),
),
'struct'
);
$aParams = array(
new XML_RPC_Value($sessionId, 'string'),
$Publisher
);
$oMessage = new XML_RPC_Message('addPublisher', $aParams);
$oClient = new XML_RPC_Client($publisherXmlRpcWebServiceUrl, $xmlRpcHost);
$oResponse = $oClient->send($oMessage);
$PublisherId = returnXmlRpcResponseData($oResponse);
echo 'Publisher with id: ' . $PublisherId . ' added <br>';
//--------------------------------------------------end insert Publisher
//--------------------------------------------------this function start insert Zone to your website , you need change $publisherId and fields below
$publisherId=13;
$Zone = new XML_RPC_Value(
array(
'publisherId' => new XML_RPC_Value($publisherId,'int'),
'zoneName' => new XML_RPC_Value('tuan zonename new4', 'string'),
'type' => new XML_RPC_Value(4, 'int'),
'width' => new XML_RPC_Value('300', 'int'),
'height' => new XML_RPC_Value('50', 'int'),
'comments' => new XML_RPC_Value('comments here', 'string'),
),
'struct'
);
$aParams = array(
new XML_RPC_Value($sessionId, 'string'),
$Zone
);
$oMessage = new XML_RPC_Message('addZone', $aParams);
$oClient = new XML_RPC_Client($zoneXmlRpcWebServiceUrl, $xmlRpcHost);
$oResponse = $oClient->send($oMessage);
$ZoneId = returnXmlRpcResponseData($oResponse);
echo 'Zone with id: ' . $ZoneId . ' added <br>';
//--------------------------------------------------end insert zone
?>