将自定义SMS API与woocommerce集成

时间:2017-09-15 13:14:56

标签: php wordpress api woocommerce sms

所以我一直致力于将自定义SMS API与woocommerce和wc供应商插件集成的项目。不幸的是,我没有找到任何特定的解决方案。每个人都在谈论一些实际支持现有网关的插件。我想知道如果有人想将自己的api与woocommerce集成在一起的话!

最后,我提出了自己的代码,如下所示。代码转到子主题中的function.php。 FYKI,我不得不使用 rawurlencode 来编码短信,因为一些电信公司需要编码信息。

谢谢。

特别感谢:Integrating SMS api with woocommerce , Not sending messages

5 个答案:

答案 0 :(得分:1)

//DYNAMIC ORDER MSG TO CUSTOMER 
add_action('woocommerce_order_status_processing', 'custom_msg_customer_process_order', 10, 3);

function custom_msg_customer_process_order ($order_id) {
//Lets get data about the order made
$order = new WC_Order($order_id);

//Now will fetch billing phone
$billing_phone = $order->get_billing_phone();
$billing_name = $order->get_billing_first_name();

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

// Now put HTTP SMS API URL
$url = "http://msms.THE_COMPANY.com/RequestSMS.php?user_name=YOUR_USER_NAME&pass_word=YOUR_PASSWORD&brand=YOUR_BRAND_NAME&type=1&destination=$billing_phone&sms=$textmessage";

// 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;
}

答案 1 :(得分:0)

要将Datagen SMS API脚本集成到没有任何插件的Wordpress Woocommerce中,只需将Funcation.php代码添加到全球成千上万的客户中,相信Datagen可以向其客户发送数百万条消息。单一的SMS API集成服务可以改变您的业务并将其推向新的高度。有了它,您就可以在启用SMS的任何应用程序,系统或网站上通过短码,长号等实现国际双向双向消息传递,从而将目标锁定在全球范围内。

只要在网站上进行任何购买,Dategen SMS API就会发送消息

  

Wordpress WooCommerce将自动订单更新发送给客户   只要在网站上进行购买就可以移动。

如何在Wordpress woocommerce中集成短信API

在设置此dataen API之前,请注意两件事

auth Key
Sender ID

现在,您需要将此代码添加到functions.php页面

add_action('woocommerce_thankyou', 'send_sms_api', 10, 1);

function send_sms_api($billing_phone)
{   

$results = $GLOBALS['wpdb']->get_results("SELECT * FROM wp_postmeta WHERE post_id = $billing_phone AND meta_key IN ('_billing_phone')", OBJECT);

    $mobilenois=$results[0]->meta_value;    
$auth = "Enter Your Auth Key Here "; // add auth Key Here  
 $mobileNumber = $mobilenois;
$senderId = "Enter Send ID Here"; // add Sender ID 
$message = urlencode("Thannk you for order with us. "); // Add Message here 
$postData = array(
    'auth' => $auth,
    'msisdn' => $mobileNumber,
    'message' => $message,
    'senderid' => $senderId,
);
$url='http://sms.datagenit.in/API/sms-api.php';
$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);
 $output;
}

https://datagenit.com/api-developer.php

免费技术支持:致电+ 91-9999-706-864或向我们发送电子邮件:hello@datagenit.com

答案 2 :(得分:0)

我最近遇到了这个挑战,我找到了一种使用插件从WooCommerce发送通知SMS消息的简便方法,但是我需要一些以自己的方式发送消息的消息。

我最终将Twilio服务及其API一起使用,我编写了本教程,介绍如何进行全部设置,希望对您有所帮助!

function wpcodetips_send_sms( $smsMessage , $contactNumber ){
// Change to your account SID
$accountSID = 'XXXXXXXXXXXXX'; 
// Change to your account Auth Key
$authKey = 'XXXXXXXXXXXXX';
// Change to your account trial number
$sendNumber = '+XXXXXXXXXXX';
// The Twilio API Url 
$url = "https://api.twilio.com/2010-04-01/Accounts/".$accountSID."/Messages.json";
// The data being sent to the API
$data = array(
            'From' => $sendNumber,
            'To' => $contactNumber,
            'Body' => $smsMessage
        ); 
// Set the authorisation header
$headers = array( 'Authorization' => 'Basic ' . base64_encode($accountSID . ':' . $authKey));
// Send the POST request and store the response in a variable
$result = wp_remote_post($url, array( 'body' => $data, 'headers' => $headers));
// Return the response body to ensure it has worked
return json_decode($result['body'], true);
}

https://www.wpcodetips.com/wordpress-tutorials/how-to-send-an-sms-from-wordpress-programmatically/

答案 3 :(得分:0)

不确定这是否对任何人有帮助,但我最近开设了一家 woocommerce 商店,店主在外地时无法整天查看电子邮件中的订单。

因此,我将 Hasan 和 Gary 的帖子合并到一起,以便在有新订单时使用 Twilio 通过 SMS 发送通知。

只需将以下内容添加到您的functions.php 并替换accountSID、authKey、SendNumber 和contactNumber 值。当然,还可以根据您的喜好更改消息。

也使用特殊字符(如 ÅÄÖ)对其进行了测试,结果奏效了。

//Send SMS Notification to admin
add_action('woocommerce_order_status_processing', 'send_woo_order_sms', 10, 3);

function send_woo_order_sms ($order_id){
    //Get order data
    $order = new WC_Order($order_id);
    //Get first name from order
    $billing_first_name = $order->get_billing_first_name();
    //Get last name from order
    $billing_last_name = $order->get_billing_last_name();
    // Change to your Twilio account SID
    $accountSID = 'xxxxxxxxxxxxxxxx';
    // Change to your Twilio account Auth Key
    $authKey = 'xxxxxxxxxxxxxxxx';
    // Change to your Twilio account number
    $sendNumber = '+xxxxxxxxxxxxxxxx';
    //Change to your verified caller number (receiver of the sms)
    $contactNumber = '+xxxxxxxxxxxxxxxx';
    //Message to send
    $smsMessage =  "$billing_first_name $billing_last_name has just placed an order. See order #$order_id.";
    // The Twilio API Url 
    $url = "https://api.twilio.com/2010-04-01/Accounts/".$accountSID."/Messages.json";
    // The data being sent to the API
    $data = array(
                'From' => $sendNumber,
                'To' => $contactNumber,
                'Body' => $smsMessage
            ); 
    // Set the authorisation header
    $headers = array( 'Authorization' => 'Basic ' . base64_encode($accountSID . ':' . $authKey));
    // Send the POST request and store the response in a variable
    $result = wp_remote_post($url, array( 'body' => $data, 'headers' => $headers));

    return $order_id;
}

我想可以很容易地将其更改为发送给客户,而不是将 contactNumber 更改为计费电话。

$contactNumber = $order->get_billing_phone();

然而,这需要 Twilio 的付费计划。

答案 4 :(得分:-1)

Ufone巴基斯坦短信与woocommerce wordpress集成

如果要与woocommerce wordpress的ufone巴基斯坦sms api bsms ufone巴基斯坦服务提供商集成,请在函数文件中使用以下代码

sms api与WordPress woocommerce集成ufone bsms 感谢本页上的作者 将自定义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;
}