【发布时间】:2015-12-22 12:54:56
【问题描述】:
我正在将 SMS API 与 WooCommerce 集成,以便在客户在网站上进行任何购买时自动向手机发送订单更新。
下面是我的代码
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($billing_phone)
{
$username = "my username";
$hash = "d761fbd7bd31c5eeec2a5b2556d6b9d3b1a1ae51";
//Multiple mobiles numbers separated by comma
$mobileNumber = "$billing_phone";
$senderId = "ORNGMT";
$message = urlencode("Dear Customer");
$postData = array(
'hash' => $hash,
'mobiles' => $$billing_phone,
'message' => $message,
'sender' => $senderId,
);
$url='http://api.textlocal.in/send/?';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
//,CURLOPT_FOLLOWLOCATION => true
));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo $output;
}
正确吗? 我已将此代码添加到 functions.php 页面
我的短信网关提供商已向我发送以下示例代码以使用 PHP 发送短信
<?php
// Authorisation details.
$username = "your login id";
$hash = "your hash key";
// Configuration variables. Consult http://api.textlocal.in/docs for more info.
$test = "0";
// Data for text message. This is the text message data.
$sender = "API Test"; // This is who the message appears to be from.
$numbers = "44777000000"; // A single number or a comma-seperated list of numbers
$message = "This is a test message from the PHP API script.";
// 612 chars or less
// A single number or a comma-seperated list of numbers
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('http://api.textlocal.in/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); // This is the result from the API
curl_close($ch);
?>
【问题讨论】:
-
“不工作”是什么意思?哪部分不合格?你有没有采取任何步骤来找到失败点?现在您要求我们为您调试代码。
-
它不是在发送消息。
-
仍然建议您单步执行代码并 echo/var_dump 各个部分,以便您可以看到失败的地方。 PS-我还建议看看 [wp_remote_post()]codex.wordpress.org/Function_Reference/wp_remote_post)
-
例如,乍一看,我可以在一行中看到
$mobileNumber = "$billing_phone";,然后是'mobiles' => $$billing_phone,。您确定以 API 接受的格式传递有效电话号码吗? -
不,妈妈!我不确定。 :( api.textlocal.in/docs/sendsms > 这是我正在使用的 api。我对此没有任何先验知识,所以从最近几天开始搜索它。
标签: wordpress woocommerce