提问者:小点点

将SMS api与woocommerce集成,不发送消息


我正在整合短信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;
}

对吗?我已将此代码添加到函数中。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);

?


共3个答案

匿名用户

为每个事件集成消息API将很困难,您需要在代码级别自定义消息API。

你可以在wordpress woocommerce中使用流行的SMSplugin

https://wordpress.org/plugins/woocommerce-apg-sms-notifications/

只需从woocommerce管理员登录配置此插件,它就会自动发送短信通知。我们将其与Spring Edge sms网关一起使用。。工作很好。

匿名用户

与Woocommerce wordpress的定制api集成已测试并运行

Ufone巴基斯坦短信与woocommerce wordpress的整合

如果您希望与ufone pakistan sms api bsms ufone pakistan服务提供商与woocommerce wordpress集成,请在函数文件中使用以下代码

sms api集成ufone bsms与WoodPress woocommerce感谢本页作者将自定义sms api与woocommerce集成

//add this line for calling your function on creation of order in woocommerce 
add_action('woocommerce_order_status_processing', 'custom_func', 10, 3);

function custom_func ($order_id) {

$order_details = new WC_Order($order_id);

//fetch all required fields
$billing_phone = $order_details->get_billing_phone();
$billing_name = $order_details->get_billing_first_name();
$billing_last_name = $order_details->get_billing_last_name();
$total_bill = $order_details->get_total();

$textmessage = rawurlencode("Dear $billing_name, Thank you for your order. Your order #$order_id is being processed. Please wait for confirmation call Total Bill = $total_bill");

// Now put HTTP ufone BSMS API URL
$url = "https://bsms.ufone.com/bsms_v8_api/sendapi-0.3.jsp?id=msisdn&message=$textmessage&shortcode=SHORTCODE&lang=English&mobilenum=$billing_phone&password=password&messagetype=Nontransactional";

// NOW WILL CALL FUNCTION CURL  
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);

return $order_id;
}

匿名用户

函数中的$billingphone是ID。请尝试以下代码。它起作用了

add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id) {
//Lets get data about the order made
$order = new WC_Order( $order_id );

//Now will fetch customer/buyer id here
$customer_id = $order->user_id;

//now finally we fetch phone number 
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );

// Now put your HTTP SMS API URL . I PUT WHICH WE ARE USING
$jsonurl = "http://tsms.thirdeyegoa.com/api/sendmsg.php?user=USERNAME&pass=PASSWORD&sender=MYSENDERID&phone=".$billing_phone."&priority=ndnd&stype=normal&text=MY MESSAGE TO CUSTOMER.";

// NOW WILL CALL FUNCTION CURL  
$json = curl($jsonurl);

return $order_id;
}

同样,您也可以使用相应的钩子完成订单。