【发布时间】:2021-05-18 05:00:07
【问题描述】:
我需要在成功下单后给客户发送短信。我已经在 Smsbroadcast 注册,他们提供带有 curl 的 API。谁能帮我将它与 wordpress 集成?
<?php
function sendSMS($content) {
$ch = curl_init('https://api.smsbroadcast.com.au/api-adv.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
return $output;
}
$username = 'USERNAME';
$password = 'PASSWORD';
$destination = '0400000000'; //Multiple numbers can be entered, separated by a comma
$source = 'MyCompany';
$text = 'This is our test message.';
$ref = 'abc123';
$content = 'username='.rawurlencode($username).
'&password='.rawurlencode($password).
'&to='.rawurlencode($destination).
'&from='.rawurlencode($source).
'&message='.rawurlencode($text).
'&ref='.rawurlencode($ref);
$smsbroadcast_response = sendSMS($content);
$response_lines = explode("\n", $smsbroadcast_response);
foreach( $response_lines as $data_line){
$message_data = "";
$message_data = explode(':',$data_line);
if($message_data[0] == "OK"){
echo "The message to ".$message_data[1]." was successful, with reference ".$message_data[2]."\n";
}elseif( $message_data[0] == "BAD" ){
echo "The message to ".$message_data[1]." was NOT successful. Reason: ".$message_data[2]."\n";
}elseif( $message_data[0] == "ERROR" ){
echo "There was an error with this request. Reason: ".$message_data[1]."\n";
}
}
?>
【问题讨论】:
标签: php wordpress woocommerce sms-gateway