Php 无法让plivo发送短信
我正在使用Plivo PHP库通过Plivo发送短信 我正在库中设置正确的身份验证凭据,它是按照curl_请求方法中的库进行base64编码的 我认为标题是正确的,我与我的平台的集成工作正常,但是当尝试使用send_message方法发送简单消息时,我无法让它工作,并且总是得到一个响应状态401,即身份验证错误 我做错了什么 非常感谢 我的代码:Php 无法让plivo发送短信,php,authentication,curl,plivo,Php,Authentication,Curl,Plivo,我正在使用Plivo PHP库通过Plivo发送短信 我正在库中设置正确的身份验证凭据,它是按照curl_请求方法中的库进行base64编码的 我认为标题是正确的,我与我的平台的集成工作正常,但是当尝试使用send_message方法发送简单消息时,我无法让它工作,并且总是得到一个响应状态401,即身份验证错误 我做错了什么 非常感谢 我的代码: //Load library messages $this->load->library( 'Plivo'
//Load library messages
$this->load->library( 'Plivo' );
$p = new RestAPI( 'MANXXXXXXXXXXXXXZIWOD', 'MmXXXXXXXXXXXXXXXXXXXXXXXXXXXX' );
// //for each phone Numbers generate password associated to event
foreach ( $nums as $key => $num ) {
//For each combo send Message
$params = array(
'src' => '13307782635', // Sender's phone number with country code (US)
'dst' => '447598XXXXXX', // Receiver's phone number with country code (UK)
'text' => 'Hi, Message from your fired', // Your SMS text message
'url' => site_url( 'eventPromotion/report' ), // The URL to which with the status of the message is sent
'method' => 'POST' // The method used to call the url
);
// Send message
$response = $p->send_message($params);
// Print the response
echo "Response : ";
var_dump( $response );
可以使用api代替库使用
<?php
# Plivo AUTH ID
$AUTH_ID = 'AUTH_ID-GOES-HERE';
# Plivo AUTH TOKEN
$AUTH_TOKEN = 'AUTH-TOKEN-GOES-HERE';
# SMS sender ID.
$src = 'SM123';
# SMS destination number
$dst = 'MOBILE-NUMBER';
# SMS text
$text = 'Hello';
$url = 'https://api.plivo.com/v1/Account/'.$AUTH_ID.'/Message/';
$data = array("src" => "$src", "dst" => "$dst", "text" => "$text");
$data_string = json_encode($data);
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_USERPWD, $AUTH_ID . ":" . $AUTH_TOKEN);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec( $ch );
curl_close($ch);
print_r($response);
?>
可以使用api代替库使用
<?php
# Plivo AUTH ID
$AUTH_ID = 'AUTH_ID-GOES-HERE';
# Plivo AUTH TOKEN
$AUTH_TOKEN = 'AUTH-TOKEN-GOES-HERE';
# SMS sender ID.
$src = 'SM123';
# SMS destination number
$dst = 'MOBILE-NUMBER';
# SMS text
$text = 'Hello';
$url = 'https://api.plivo.com/v1/Account/'.$AUTH_ID.'/Message/';
$data = array("src" => "$src", "dst" => "$dst", "text" => "$text");
$data_string = json_encode($data);
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_USERPWD, $AUTH_ID . ":" . $AUTH_TOKEN);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec( $ch );
curl_close($ch);
print_r($response);
?>
对于使用curl在Plivo中发送sms,您将从plivoapi获得正确的JSON返回
$auth_id = 'auth_id';
$auth_token = 'auth_token';
$src = '+1XXXXXXXXXXX';
$dst = '+1XXXXXXXXXXX';
$text = 'Hello, this is testing message';
$api = curl_init("https://api.plivo.com/v1/Account/$auth_id/Message/");
curl_setopt_array($api, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array("Authorization: Basic ".base64_encode($auth_id.':'.$auth_token)),
CURLOPT_POSTFIELDS => array(
'src' =>$src,
'dst' => $dst,
'text' => $text
)
));
$resp = curl_exec($api);
$resp = curl_exec($api);
curl_close($api);
var_dump($resp);
对于使用curl在Plivo中发送sms,您将从plivoapi获得正确的JSON返回
$auth_id = 'auth_id';
$auth_token = 'auth_token';
$src = '+1XXXXXXXXXXX';
$dst = '+1XXXXXXXXXXX';
$text = 'Hello, this is testing message';
$api = curl_init("https://api.plivo.com/v1/Account/$auth_id/Message/");
curl_setopt_array($api, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array("Authorization: Basic ".base64_encode($auth_id.':'.$auth_token)),
CURLOPT_POSTFIELDS => array(
'src' =>$src,
'dst' => $dst,
'text' => $text
)
));
$resp = curl_exec($api);
$resp = curl_exec($api);
curl_close($api);
var_dump($resp);
非常不需要使用供应商库。非常不需要使用供应商库。