This repository was archived by the owner on Nov 8, 2017. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathservice.php
103 lines (91 loc) · 3.31 KB
/
service.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
94
95
96
97
98
99
100
101
102
103
<?php
ini_set('soap.wsdl_cache_enabled', '0');
require_once 'lib/googleVoice.php';
require_once 'settings.php';
$server = new SoapServer('xml/oms.wsdl');
$server->addFunction('GetServiceInfo');
$server->addFunction('GetUserInfo');
$server->addFunction('DeliverXms');
$server->addFunction('SendXms');
$server->handle();
function load_xml($file)
{
ob_start();
include $file;
$return = ob_get_contents();
ob_end_clean();
return $return;
}
function GetServiceInfo()
{
global $soap;
$soap = true;
return ['GetServiceInfoResult' => load_xml('xml/serviceInfo.xml')];
}
function GetUserInfo($complex)
{
global $soap;
$soap = true;
$xmsUser = $complex->xmsUser;
$xmsUser = str_replace('UTF-16', 'UTF-8', $xmsUser);
$return = '<?xml version="1.0" encoding="utf-16"?>'."\n";
try {
$xml = new SimpleXMLElement($xmsUser);
$user = $xml->userId;
$pass = $xml->password;
try {
$gv = new GoogleVoice($user, $pass);
$email = $user;
$phone = $gv->getNumber();
$return .= '<userInfo xmlns="http://schemas.microsoft.com/office/Outlook/2006/OMS">';
$return .= '<replyPhone>'.$phone.'</replyPhone>';
$return .= '<smtpAddress>'.$email.'</smtpAddress>';
$return .= '<error code="ok" severity="neutral" />';
$return .= '</userInfo>';
} catch (Exception $e) {
$return .= '<userInfo xmlns="http://schemas.microsoft.com/office/Outlook/2006/OMS">';
$return .= '<error code="invalidUser" severity="failure" />';
$return .= '</userInfo>';
}
} catch (Exception $e) {
$return .= '<userInfo xmlns="http://schemas.microsoft.com/office/Outlook/2006/OMS"><error code="invalidFormat" severity="failure" /></userInfo>';
}
return ['GetUserInfoResult' => $return];
}
function SendXms($complex)
{
$t = DeliverXms($complex);
return ['SendXmsResult' => $t['DeliverXmsResult']];
}
function DeliverXms($complex)
{
global $soap;
$soap = true;
$xmsData = $complex->xmsData;
$xmsData = str_replace('UTF-16', 'UTF-8', $xmsData);
$return = '<?xml version="1.0" encoding="utf-16"?>'."\n";
try {
$xml = new SimpleXMLElement($xmsData);
$user = ((string) $xml->user->userId);
$pass = ((string) $xml->user->password);
try {
$gv = new GoogleVoice($user, $pass);
$recps = $xml->xmsHead->to->recipient;
$msgs = $xml->xmsBody->content;
foreach ($recps as $to) {
if (substr($to, 0, 1) == 1) {
$to = substr($to, 1);
}
foreach ($msgs as $msg) {
$gv->sms($to, $msg);
}
}
$return .= '<xmsResponse xmlns="http://schemas.microsoft.com/office/Outlook/2006/OMS"><error code="ok" severity="neutral" /></xmsResponse>';
} catch (Exception $e) {
$return .= '<userInfo xmlns="http://schemas.microsoft.com/office/Outlook/2006/OMS"><error code="invalidUser" severity="failure" /></userInfo>';
}
} catch (Exception $e) {
$return .= '<userInfo xmlns="http://schemas.microsoft.com/office/Outlook/2006/OMS"><error code="invalidFormat" severity="failure" /></userInfo>';
}
return ['DeliverXmsResult' => $return];
}