mannysoft /
globe-connect-php
全球API
Requires
- php: >=7.0.0
This package is not auto-updated.
Last update: 2024-09-20 20:41:44 UTC
README
设置
composer require globelabs/globe-connect-php
认证
概述
如果您尚未注册,请按照入门指南中的说明进行操作以获取App ID和App Secret,这些令牌将用于验证您与全球API的大部分交互请求。
The authenication process follows the protocols of **OAuth 2.0**. The example code below shows how you can swap your app tokens for an access token.
示例代码
use Globe\Connect\Oauth; $oauth = new Oauth("[key]", "[secret]"); // get redirect url echo $oauth->getRedirectUrl(); // redirect to dialog and process the code then ... // get access token $oauth->setCode("[code]"); echo $oauth->getAccessToken();
示例结果
{
"access_token":"1ixLbltjWkzwqLMXT-8UF-UQeKRma0hOOWFA6o91oXw",
"subscriber_number":"9171234567"
}
SMS
概述
短消息服务(SMS)使您的应用程序或服务能够向全球/TM用户发送和接收安全、定向的文本消息和警报。
Note: All API calls must include the access_token as one of the Universal Resource Identifier (URI) parameters.
SMS发送
向一个或多个移动终端发送短信消息
示例代码
use Globe\Connect\Sms; $sms = new Sms("[sender]", "[token]"); $sms->setReceiverAddress("[address]"); $sms->setMessage("[message]"); $sms->setClientCorrelator("[correlator]"); echo $sms->sendMessage();
示例结果
{
"outboundSMSMessageRequest": {
"address": "tel:+639175595283",
"deliveryInfoList": {
"deliveryInfo": [],
"resourceURL": "https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/8011/requests?access_token=3YM8xurK_IPdhvX4OUWXQljcHTIPgQDdTESLXDIes4g"
},
"senderAddress": "8011",
"outboundSMSTextMessage": {
"message": "Hello World"
},
"receiptRequest": {
"notifyURL": "http://test-sms1.herokuapp.com/callback",
"callbackData": null,
"senderName": null,
"resourceURL": "https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/8011/requests?access_token=3YM8xurK_IPdhvX4OUWXQljcHTIPgQDdTESLXDIes4g"
}
}
}
SMS二进制
通过短信发送二进制数据
示例代码
use Globe\Connect\Sms; $sms = new Sms("[sender]", "[token]"); $sms->setReceiverAddress("[address]"); $sms->setUserDataHeader("[header]"); $sms->setDataEncodingScheme("[scheme]"); $sms->setMessage("[message]"); echo $sms->sendBinaryMessage();
示例结果
{
"outboundBinaryMessageRequest": {
"address": "9171234567",
"deliveryInfoList": {
"deliveryInfo": [],
"resourceURL": "https://devapi.globelabs.com.ph/binarymessaging/v1/outbound/{senderAddress}/requests?access_token={access_token}",
"senderAddress": "21581234",
"userDataHeader": "06050423F423F4",
"dataCodingScheme": 1,
"outboundBinaryMessage": {
"message": "samplebinarymessage"
},
"receiptRequest": {
"notifyURL": "http://example.com/notify",
"callbackData": null,
"senderName": null
},
"resourceURL": "https://devapi.globelabs.com.ph/binarymessaging/v1/outbound/{senderAddress}/requests?access_token={access_token}"
}
}
SMS移动主叫(SMS-MO)
接收来自全球的短信(移动主叫 - 订户到应用程序)
示例代码
// print post data from your callback url print_r(json_encode($_POST));
示例结果
{
"inboundSMSMessageList":{
"inboundSMSMessage":[
{
"dateTime":"Fri Nov 22 2013 12:12:13 GMT+0000 (UTC)",
"destinationAddress":"tel:21581234",
"messageId":null,
"message":"Hello",
"resourceURL":null,
"senderAddress":"9171234567"
}
],
"numberOfMessagesInThisBatch":1,
"resourceURL":null,
"totalNumberOfPendingMessages":null
}
}
语音
概述
全球API提供了您可以在应用程序中使用的一系列详细语音功能。
语音询问
您可以通过利用全球的自动询问协议来帮助服务客户,无需手动干预常见问题,例如。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web Api"); $choices = $voice->choices("[5 DIGITS]"); $askSay = $voice->say("Please enter yout 5 digit zip code."); $ask = $voice->ask($askSay) ->setChoices($choices) ->setAttempts(3) ->setBargein(false) ->setName("foo") ->setRequired(true) ->setTimeout(10); $on = $voice->on("continue") ->setNext("http://somefakehost.com:8000/") ->setRequired(true); echo $voice->addSay($say) ->addAsk($ask) ->addOn($on);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API."
}
},
{
ask: {
choices: {
value: "[5 DIGITS]"
},
attempts: 3,
bargein: false,
name: "foo",
required: true,
say: {
value: "Please enter your 5 digit zip code."
},
timeout: 10
}
},
{
on: {
event: "continue",
next: "http://somefakehost.com:8000/",
required: true
}
}
]
}
语音回答
您可以通过利用全球的自动询问协议来帮助服务客户,无需手动干预常见问题,例如。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web Api."); echo $voice->addSay($say);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API."
}
},
{
hangup: { }
}
]
}
语音询问和回答
以下是一个更好的询问和回答对话框示例。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web API"); $voice->addSay($say); if($url == "/ask") { $choices = $voice->choices("[5 DIGITS]"); $askSay = $voice->say("Please enter yout 5 digit zip code."); $ask = $voice->ask($askSay) ->setChoices($choices) ->setAttempts(3) ->setBargein(false) ->setName("foo") ->setRequired(true) ->setTimeout(10); $on = $voice->on("continue") ->setNext("/answer") ->setRequired(true); $voice->addSay($say) ->addAsk($ask) ->addOn($on); } elseif($url == "/answer") { $result = $voice->result($data) ->getObject(); $interprertation = $result["actions"]["ineterpretation"]; $say = $voice->say("Your zip is " . $interpretation . ", thank you!"); $voice->addSay($say); } echo $voice;
示例结果
if path is ask? { tropo: [ { say: { value: "Welcome to my Tropo Web API." } }, { ask: { choices: { value: "[5 DIGITS]" }, attempts: 3, bargein: false, name: "foo", required: true, say: { value: "Please enter your 5 digit zip code." }, timeout: 10 } }, { on: { event: "continue", next: "/askanswer/answer", required: true } } ] } if path is answer? { tropo: [ { say: { value: "Your zip code is 52521, thank you!" } } ] }
语音通话
您可以将应用程序连接到客户,以启动询问和回答功能。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $call = $voice->call("9065263453") ->setFrom("sip:21584130@sip.tropo.net"); $say = $voice->say("Hello World"); echo $voice->addCall($call) ->addSay($say);
示例结果
{
tropo: [
{
call: {
to: "9065272450",
from: "sip:21584130@sip.tropo.net"
}
},
[
{
value: "Hello World"
}
]
]
}
语音会议
您可以通过利用全球的自动询问协议来帮助服务客户,无需手动干预常见问题,例如。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web API Conference Call."); $jPrompt = $voice->joinPrompt("http://openovate.com/hold-music.mp3"); $lPrompt = $voice->leavePrompt("http://openovate.com/hold-music.mp3"); $conference = $voice->conference("12345") ->setMute(false) ->setName("foo") ->setPlayTones(true) ->setTerminator("#") ->setJoinPrompt($jPrompt) ->setLeavePrompt($lPrompt); echo $voice->addSay($say) ->addConference($conference);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API Conference Call."
}
},
{
conference: {
id: "12345",
mute: false,
name: "foo",
playTones: true,
terminator: "#",
joinPrompt: {
value: "http://openovate.com/hold-music.mp3"
},
leavePrompt: {
value: "http://openovate.com/hold-music.mp3"
}
}
}
]
}
语音事件
根据接收者的响应触发呼叫事件。事件与询问和回答功能一起使用。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $e1 = $voice->say("Sorry, I did not hear anything.") ->setEvent("timeout"); $e2 = $voice->say("Sorry, that was not a valid option.") ->setEvent("nomatch:1"); $e3 = $voice->say("Nope, still not a valid response.") ->setEvent("nomatch:2"); $say = $voice->say("Welcome to my Tropo Web API"); $eventSay = $voice->say("Please enter your 5 digit zip code.") ->setEvent(array($e1, $e2, $e3)); $choices = $voice->choices("[5 DIGITS]"); $ask = $voice->ask($eventSay) ->setChoices($choices) ->setAttempts(3) ->setBargein(false) ->setName("foo") ->setRequired(true) ->setTimeout(10); $on = $voice->on("continue") ->setNext("/answer") ->setRequired(true); echo $voice->addSay($say) ->addAsk($ask) ->addOn($on);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API."
}
},
{
ask: {
choices: {
value: "[5 DIGITS]"
},
attempts: 3,
bargein: false,
name: "foo",
required: true,
say: [
{
value: "Sorry, I did not hear anything.",
event: "timeout"
},
{
value: "Sorry, that was not a valid option.",
event: "nomatch:1"
},
{
value: "Nope, still not a valid response",
event: "nomatch:2"
},
{
value: "Please enter your 5 digit zip code."
}
],
timeout: 5
}
},
{
on: {
event: "continue",
next: "http://somefakehost:8000/",
required: true
}
}
]
}
语音挂断
在您的自动化对话框(询问和回答)之间,您可以使用此功能自动关闭语音通话。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web Api, Thank you"); echo $say->addSay($say) ->addHangup("");
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API, thank you!"
}
},
{
hangup: { }
}
]
}
语音录音
有时记录对话很有用,例如帮助改进自动化对话框(询问和回答)。以下示例显示了如何使用应用程序与语音录音功能连接。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web API."); $sayTimeout = $voice->say("Sorry, I did not here anything. Please call back.") ->setEvent("timeout"); $say2 = $voice->say("Please leave a message") ->setEvent(array($sayTimeout)); $choices = $voice->choices() ->setTerminator("#"); $transcription = $voice->transcription("1234") ->setUrl("mailto:charles.andacc@gmail.com"); $record = $voice->record("foo", "http://openovate.com/globe.php") ->setFormat("wav") ->setAttempts(3) ->setBargein(false) ->setMethod("POST") ->setRequired(true) ->setSay($say2) ->setChoices($choices) ->setTranscription($transcription); echo $voice->addSay($say) ->addRecord($record);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API."
}
},
{
record: {
attempts: 3,
bargein: false,
method: "POST",
required: true,
say: [
{
value: "Sorry, I did not hear anything. Please call back.",
event: "timeout"
},
{
value: "Please leave a message"
}
],
name: "foo",
url: "http://openovate.com/globe.php",
format: "audio/wav",
choices: {
terminator: "#"
},
transcription: {
id: "1234",
url: "mailto:charles.andacc@gmail.com"
}
}
}
]
}
语音拒绝
要自动过滤传入的调用,您可以使用以下示例。
示例代码
use Globe\Connect\Voice $voice = new Voice(); echo $voice->addreject("");
示例结果
{
tropo: [
{
reject: { }
}
]
}
语音路由
为了帮助将全球语音与Web应用程序集成,此API使用路由,可以轻松地在框架内进行路由。
示例代码
use Globe\Connect\Voice $voice = new Voice(); if($url == "/routing") { $say = $voice->say("Welcome to my Tropo Web API."); $on = $voice->on("continue") ->setNext("/routing1"); $voice->addSay($say) ->addOn($on); } else if($url == "/routing1") { $say = $voice->say("Hello from resource one."); $on = $voice->on("continue") ->setNext("/routing2"); $voice->addSay($say) ->addOn($on); } else if($url == "/routing2") { $say = $voice->say("Hello from resource two! Thank you."); $voice->addSay($say); } echo $voice;
示例结果
if path is routing? { tropo: [ { say: { value: "Welcome to my Tropo Web API." } }, { on: { next: "/VoiceSample/RoutingTest1", event: "continue" } } ] } if path is routing1? { tropo: [ { say: { value: "Hello from resource one!" } }, { on: { next: "/VoiceSample/RoutingTest2", event: "continue" } } ] } if path is routing2? { tropo: [ { say: { value: "Hello from resource two! thank you." } } ] }
语音说话
传递给say的消息将被转换成自动语音。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo web API"); $say2 = $voice->say("I will play an audio file for you, please wait."); $say3 = $voice->say("http://openovate.com/tropo-rocks.mp3"); echo $voice->addSay($say) ->addSay($say2) ->addSay($say3);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API."
}
},
{
say: {
value: "I will play an audio file for you, please wait."
}
},
{
say: {
value: "http://openovate.com/tropo-rocks.mp3"
}
}
]
}
语音转接
以下示例解释了将接收者转接到另一个电话号码所需的对话框。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web API, you are now being transfered."); $e1 = $voice->say("Sorry I did not hear anything") ->setEvent("timeout"); $e2 = $voice->say("Sorry, that was an invalid option") ->setEvent("nomatch:1"); $eventSay = $voice->say("Please enter your 5 digit zip code") ->setEvent(array($e1, $e2)); $choices = $voice->choices("[5 DIGITS]"); $ask = $voice->ask($eventSay) ->setChoices($choices) ->setAttempts(3) ->setBargein(false) ->setName("foo") ->setRequired(true) ->setTimeout(5); $ringSay = $voice->say("http://openovate.com/hold-music.mp3"); $onRing = $voice->on("ring") ->setSay($ringSay); $onConnect = $voice->on("connect") ->setAsk($ask); $on = array($onRing, $onConnect); $transfer = $voice->transfer("9053801178") ->setRingRepeat(2) ->setOn($on); echo $voice->addSay($say) ->addTransfer($transfer);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API, you are now being transferred."
}
},
{
transfer: {
to: "9053801178",
ringRepeat: 2,
on: [
{
event: "ring",
say: {
value: "http://openovate.com/hold-music.mp3"
}
},
{
event: "connect",
ask: {
choices: {
value: "[5 DIGITS]"
},
attempts: 3,
bargein: false,
name: "foo",
required: true,
say: [
{
value: "Sorry, I did not hear anything.",
event: "timeout"
},
{
value: "Sorry, that was not a valid option.",
event: "nomatch:1"
},
{
value: "Nope, still not a valid response",
event: "nomatch:2"
},
{
value: "Please enter your 5 digit zip code."
}
],
timeout: 5
}
}
]
}
}
]
}
语音转接耳语
待办事项
示例代码
use Globe\Connect\Voice; $voice = new Voice(); if($url == "/whisper") { $say = $voice->say("Welcome to my Tropo Web API"); $askSay = $voice->say("Press 1 to continue this call or any other to reject"); $choices = $voice->choices("1") ->setMode("DTMF"); $ask = $voice->ask($askSay) ->setChoices($choices) ->setName("color") ->setTimeout(60); $onConnect1 = $voice->on("connect") ->setAsk($ask); $sayCon2 = $voice->say("You are now being connected"); $onConnect2 = $voice->on("connect") ->setSay($sayCon2); $sayRing = $voice->say("http://openovate.com/hold-music.mp3"); $onRing = $voice->on("ring") ->setSay($say); $on = array($onRing, $onConnect1, $onConnect2); $transfer = $voice->transfer("9054799241") ->setName("foo") ->setOn($on) ->setRequired(true) ->terminator("*") $incompleteSay = $voice->say("Your are now being disconnected"); $onIncomplete = $voice->on("incomplete") ->setNext("/whisperIncomplete") ->setSay($incompleteSay); echo $voice->addSay($say) ->addTransfer($transfer) ->addOn($onIncomplete); } else if($url == "/whisperIncomplete") { echo $voice->addHangup(""); }
示例结果
if transfer whisper? { tropo: [ { say: { value: "Welcome to my Tropo Web API, please hold while you are being transferred." } }, { transfer: { to: "9054799241", name: "foo", on: [ { event: "ring", say: { value: "http://openovate.com/hold-music.mp3" } }, { event: "connect", ask: { choices: { value: "1", mode: "dtmf" }, name: "color", say: { value: "Press 1 to accept this call or any other number to reject" }, timeout: 60 } }, { event: "connect", say: { value: "You are now being connected." } } ], required: true, terminator: "*" } }, { on: { event: "incomplete", next: "/transferwhisper/hangup", say: { value: "You are now being disconnected." } } } ] } if hangup? { tropo: [ { hangup: { } } ] }
语音等待
要使接收者保持通话,您可以使用以下示例。
示例代码
use Globe\Connect\Voice; $voice = new Voice(); $say = $voice->say("Welcome to my Tropo Web API."); $wait = $voice->wait(5000) ->setAllowSignals(true); $say2 = $voice->say("Thank you for waiting."); echo $voice->addSay($say) ->addWait($wait) ->addSay($say2);
示例结果
{
tropo: [
{
say: {
value: "Welcome to my Tropo Web API, please wait for a while."
}
},
{
wait: {
milliseconds: 5000,
allowSignals: true
}
},
{
say: {
value: "Thank you for waiting!"
}
}
]
}
USSD
概述
USSD是基于大多数智能手机的基本功能,允许手机用户与菜单项选择进行交互。
USSD发送
以下示例显示了如何发送USSD请求。
示例代码
use Globe\Connect\Ussd; $ussd = new Ussd("[token]", "[shortcode]"); // send ussd request $ussd->setAddress("[address]"); $ussd->setUssdMessage("[message]"); $ussd->setFlash("[flash]"); print $ussd->sendUssdRequest();
示例结果
{
"outboundUSSDMessageRequest": {
"address": "639954895489",
"deliveryInfoList": {
"deliveryInfo": [],
"resourceURL": "https://devapi.globelabs.com.ph/ussd/v1/outbound/21589996/reply/requests?access_token=access_token"
},
"senderAddress": "21580001",
"outboundUSSDMessage": {
"message": "Simple USSD Message\nOption - 1\nOption - 2"
},
"receiptRequest": {
"ussdNotifyURL": "http://example.com/notify",
"sessionID": "012345678912"
},
"resourceURL": "https://devapi.globelabs.com.ph/ussd/v1/outbound/21589996/reply/requests?access_token=access_token"
}
}
USSD回复
以下示例显示了如何发送USSD回复。
示例代码
use Globe\Connect\Ussd; $ussd = new Ussd("[token]", "[shortcode]"); $ussd->setAddress("[address]"); $ussd->setUssdMessage("[message]"); $ussd->setFlash("[flash]"); $ussd->setSessionId("[session_id]"); print $ussd->replyUssdRequest();
示例结果
{
"outboundUSSDMessageRequest": {
"address": "639954895489",
"deliveryInfoList": {
"deliveryInfo": [],
"resourceURL": "https://devapi.globelabs.com.ph/ussd/v1/outbound/21589996/reply/requests?access_token=access_token"
},
"senderAddress": "21580001",
"outboundUSSDMessage": {
"message": "Simple USSD Message\nOption - 1\nOption - 2"
},
"receiptRequest": {
"ussdNotifyURL": "http://example.com/notify",
"sessionID": "012345678912",
"referenceID": "f7b61b82054e4b5e"
},
"resourceURL": "https://devapi.globelabs.com.ph/ussd/v1/outbound/21589996/reply/requests?access_token=access_token"
}
}
支付
概述
您的应用程序可以通过向客户发送支付请求来从客户的手机话费中盈利,客户可以选择接受。
支付请求
以下示例显示了您如何向客户请求支付。
示例代码
use Globe\Connect\Payment; $payment = new Payment("[token]"); // payment request $payment->setEndUserId("[user_id]"); $payment->setAmount("[amount]"); $payment->setDescription("[description]"); $payment->setReferenceCode("[reference_code]"); $payment->setTransactionOperationStatus("[status]"); print $payment->sendPaymentRequest();
示例结果
{
"amountTransaction":
{
"endUserId": "9171234567",
"paymentAmount":
{
"chargingInformation":
{
"amount": "0.00",
"currency": "PHP",
"description": "my application"
},
"totalAmountCharged": "0.00"
},
"referenceCode": "12341000023",
"serverReferenceCode": "528f5369b390e16a62000006",
"resourceURL": null
}
}
支付最后参考
以下示例展示了如何获取最后一条支付参考信息。
示例代码
use Globe\Connect\Payment; // get last reference code request $payment->setAppKey("[key]"); $payment->setAppSecret("[secret]"); print $payment->getLastReferenceCode();
示例结果
{
"referenceCode": "12341000005",
"status": "SUCCESS",
"shortcode": "21581234"
}
Amax
概述
Amax 是一个自动促销构建器,您可以在您的应用程序中使用它,以奖励客户获得某些全球优惠。
示例代码
use Globe\Connect\Amax; $amax = new Amax("[app_id]", "[app_secret]"); $amax->setToken("[token]"); $amax->setAddress("[address]"); $amax->setPromo("[promo]"); echo $amax->sendReward();
示例结果
{
"outboundRewardRequest": {
"transaction_id": 566,
"status": "Please check your AMAX URL for status",
"address": "9065272450",
"promo": "FREE10MB"
}
}
位置
概述
为了确定您客户的一般区域(纬度,经度),您可以利用此功能。
示例代码
use Globe\Connect\Location; $location = new Location("[token]"); $location->setAddress("[address]"); $location->setRequestedAccuracy("[accuracy]"); echo $location->getLocation();
示例结果
{
"terminalLocationList": {
"terminalLocation": {
"address": "tel:9171234567",
"currentLocation": {
"accuracy": 100,
"latitude": "14.5609722",
"longitude": "121.0193394",
"map_url": "http://maps.google.com/maps?z=17&t=m&q=loc:14.5609722+121.0193394",
"timestamp": "Fri Jun 06 2014 09:25:15 GMT+0000 (UTC)"
},
"locationRetrievalStatus": "Retrieved"
}
}
}
订阅者
概述
订阅者数据查询API接口允许Web应用程序查询移动网络运营商客户的最终用户客户档案。
订阅者余额
以下示例展示了如何获取订阅者余额。
示例代码
use Globe\Connect\Subscriber; $subscriber = new Subscriber("[token]"); $subscriber->setAddress("[address]"); print $subscriber->getSubscriberBalance();
示例结果
{
"terminalLocationList":
{
"terminalLocation":
[
{
address: "639171234567",
subBalance: "60200"
}
]
}
}
订阅者充值
以下示例展示了如何获取订阅者充值金额。
示例代码
use Globe\Connect\Subscriber; $subscriber = new Subscriber("[token]"); $subscriber->setAddress("[address]"); print $subscriber->getReloadAmount();
示例结果
{
"terminalLocationList":
{
"terminalLocation":
[
{
address: "639171234567",
reloadAmount: "30000"
}
]
}
}