如何将 msg91 php api 与 Prestasms 或 Prestashop 集成?
How to integrate msg91 php api with Prestasms or Prestashop?
<?php
error_reporting(E_ALL ^ E_NOTICE);ini_set('error_reporting', E_ALL ^ E_NOTICE);
define('IS_ADMIN_FLAG', false);
include_once(dirname(__FILE__).'/../../config/config.inc.php');
include_once(dirname(__FILE__).'/../../config/setting.inc.php');
include_once('includes/model/smsAdapter.php');
include_once('includes/model/sms.php');
include_once('includes/model/variables.php');
class ControllerSmsApi
{
public function __construct()
{
$this->index();
}
public function index()
{
die("DISABLED");
$to = $this->getVar("to");
$text = $this->getVar("text");
$unicode = $this->getVar("unicode");
$type = $this->getVar("type");
$transaction = $this->getVar("transaction");
if(isset($to) && strlen($to) > 4 && strlen($text) > 0)
{
$sms = new SmsModel(true, SmsModel::TYPE_SIMPLE, $type, ($transaction ? SmsModel::SMS_TRANSACTION : SmsModel::SMS_BULK));
$sms->number($to)->text($text)->unicode($unicode)->send();
if(!$sms->isError())
{
echo "SMSSTATUS:OK";
}
else
{
echo "SMSSTATUS:ERROR";
}
}
else
{
echo "SMSSTATUS:ERROR";
}
}
private function getVar($var)
{
if(filter_input(INPUT_POST, $var))
{
return filter_input(INPUT_POST, $var);
}
elseif(filter_input(INPUT_GET, $var))
{
return filter_input(INPUT_GET, $var);
}
else
{
return null;
}
}
}
new ControllerSmsApi();
?>
我有一个 ecommers 网站,客户在其中下订单并通过电子邮件服务获取所有更新,但现在我想将其用于短信服务,我在 msg91 中有短信 api 用于 [=21] =].但不幸的是,我无法通过 prestasms 或任何其他免费模块将它与 prestashop 集成。
实际上制作一个模块应该可以完成工作并添加
各种挂钩都可以完成这项工作,您可以在这里生成几乎所有您需要的挂钩:https://validator.prestashop.com/
根据您的回答,您肯定需要两个挂钩:actionOrderStatusUpdate 和 actionValidateOrder。您还可以在此处获取更新列表 http://www.prestarocket.com/blog/prestashop-1-7-hook-list-liste-des-hooks/.
如果您需要运行良好的模块示例,可以查看 modules/dashactivity/ 哪个模块最符合 Prestashops 准则。
您的代码最终可能如下所示:
<?php
class Msg91SMS extends Module
{
public function __construct()
{
$this->name = 'msg91sms';
$this->tab = 'front_office';
$this->version = '1.0.1';
$this->author = 'YourName';
$this->displayName = $this->l('MSG91SMS');
$this->description = $this->l('Description');
// Hooks you need, setup on install so you might do it again
$this->hooks = array(
'actionValidateOrder',
'actionOrderStatusUpdate',
);
}
public function install() {
if (!parent::install()) {
return false;
} else {
if (isset($this->hooks) && !empty($this->hooks)) {
foreach ($this->hooks as $v) {
if (!$this->registerHook($v)) {
return false;
}
}
}
}
}
public function hookActionValidateOrder($params) {
$order = $params['order'];
// Do your magic here
}
public function hookActionOrderStatusUpdate($params) {
// Same as above, remember to check order state to see if it interests you some ways with $order->id_state and a switch / case
}
}
<?php
error_reporting(E_ALL ^ E_NOTICE);ini_set('error_reporting', E_ALL ^ E_NOTICE);
define('IS_ADMIN_FLAG', false);
include_once(dirname(__FILE__).'/../../config/config.inc.php');
include_once(dirname(__FILE__).'/../../config/setting.inc.php');
include_once('includes/model/smsAdapter.php');
include_once('includes/model/sms.php');
include_once('includes/model/variables.php');
class ControllerSmsApi
{
public function __construct()
{
$this->index();
}
public function index()
{
die("DISABLED");
$to = $this->getVar("to");
$text = $this->getVar("text");
$unicode = $this->getVar("unicode");
$type = $this->getVar("type");
$transaction = $this->getVar("transaction");
if(isset($to) && strlen($to) > 4 && strlen($text) > 0)
{
$sms = new SmsModel(true, SmsModel::TYPE_SIMPLE, $type, ($transaction ? SmsModel::SMS_TRANSACTION : SmsModel::SMS_BULK));
$sms->number($to)->text($text)->unicode($unicode)->send();
if(!$sms->isError())
{
echo "SMSSTATUS:OK";
}
else
{
echo "SMSSTATUS:ERROR";
}
}
else
{
echo "SMSSTATUS:ERROR";
}
}
private function getVar($var)
{
if(filter_input(INPUT_POST, $var))
{
return filter_input(INPUT_POST, $var);
}
elseif(filter_input(INPUT_GET, $var))
{
return filter_input(INPUT_GET, $var);
}
else
{
return null;
}
}
}
new ControllerSmsApi();
?>
我有一个 ecommers 网站,客户在其中下订单并通过电子邮件服务获取所有更新,但现在我想将其用于短信服务,我在 msg91 中有短信 api 用于 [=21] =].但不幸的是,我无法通过 prestasms 或任何其他免费模块将它与 prestashop 集成。
实际上制作一个模块应该可以完成工作并添加 各种挂钩都可以完成这项工作,您可以在这里生成几乎所有您需要的挂钩:https://validator.prestashop.com/
根据您的回答,您肯定需要两个挂钩:actionOrderStatusUpdate 和 actionValidateOrder。您还可以在此处获取更新列表 http://www.prestarocket.com/blog/prestashop-1-7-hook-list-liste-des-hooks/.
如果您需要运行良好的模块示例,可以查看 modules/dashactivity/ 哪个模块最符合 Prestashops 准则。
您的代码最终可能如下所示:
<?php
class Msg91SMS extends Module
{
public function __construct()
{
$this->name = 'msg91sms';
$this->tab = 'front_office';
$this->version = '1.0.1';
$this->author = 'YourName';
$this->displayName = $this->l('MSG91SMS');
$this->description = $this->l('Description');
// Hooks you need, setup on install so you might do it again
$this->hooks = array(
'actionValidateOrder',
'actionOrderStatusUpdate',
);
}
public function install() {
if (!parent::install()) {
return false;
} else {
if (isset($this->hooks) && !empty($this->hooks)) {
foreach ($this->hooks as $v) {
if (!$this->registerHook($v)) {
return false;
}
}
}
}
}
public function hookActionValidateOrder($params) {
$order = $params['order'];
// Do your magic here
}
public function hookActionOrderStatusUpdate($params) {
// Same as above, remember to check order state to see if it interests you some ways with $order->id_state and a switch / case
}
}