将 SMS api 与 woocommerce 集成,不发送消息 [英] Integrating SMS api with woocommerce , Not sending messages

查看:26
本文介绍了将 SMS api 与 woocommerce 集成,不发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 SMS API 与 WooCommerce 集成,以便在客户在网站上进行任何购买时自动向其手机发送订单更新.

I'm integrating SMS API with WooCommerce to send automatic order updates to customers mobiles whenever the make any purchase on site.

下面是我的代码

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页面

is it correct ? I've added this code to functions.php page

我的短信网关提供商已将以下示例代码发送给我,以使用 PHP 发送短信

my sms gateway provider has sent me below example code to send sms with 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);

?>

推荐答案

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

Integrating message API for each event will be difficult and you need to customize the at the code level.

您可以为 wordpress woocommerce 使用流行的 SMSplugin

You can use a popular SMSplugin for wordpress woocommerce

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

您只需要从 woocommerce Admin 登录配置此插件,它就会自动发送短信通知.我们将它与 Spring Edge 短信网关一起使用.. 运行良好.

Just you need to configure this plugin from woocommerce Admin login and it will send sms notifications automatically. We are using it with Spring Edge sms gateway.. Working Good.

这篇关于将 SMS api 与 woocommerce 集成,不发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆