xml_data 传递 PHP 变量
xml_data to pass PHP variables
我在我的 Opencart CMS 中集成了短信网关
它使用以下语法
$xml_data ='<?xml version="1.0"?><smslist><sms><user>username</user
<password>112131</password><message>Your order # {$order_id} has been successfully received. Thank you for placing an Order at mystore.com</message><mobiles>9898000000</mobiles><senderid>Sherif</senderid><cdmasenderid>00201009546310</cdmasenderid><accountusagetypeid>1</accountusagetypeid></sms></smslist>';
$URL = "http://mainadmin.dove-sms.com/sendsms.jsp?";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
请注意,我没有使用我的个人凭据,这只是一种语法。我已经测试了代码,使用我的凭据
它绝对可以正常工作
现在,我想要的是它应该加载订单号,而不是在我的消息中显示文本 {$order_id}
!
此外,我希望通过获取 $telephone
变量
将文本发送给已登录我的存储的用户
请帮助并提前致谢
包含此代码的文件:catalog/controller/checkout/sucess.php
Opencart 版本:1.5.6
找到我收到的消息的截图here
Now, What I want is it should load the order number, instead it shows the text {$order_id} in my message!
那是因为您对变量 $xml_data
使用单引号字符串,PHP 中的单引号字符串按原样 显示内容 (变量不会' t 被替换为它们的值,它们将被视为文本),要解决此问题,请改用双引号字符串 (according to the PHP manual)
Moreover I want the text to be sent to the user who has logged-in in my stored by fetching the $telephone variable
简单地$telephone = $this->customer->getTelephone()
,现在你只需要将变量$telephone
放在$xml_data
中的正确标签中
编辑
我已阅读 post 评论并注意到您收到一条错误消息,指出 $order_id
未定义,要解决此问题,请使用 $this->session->data['order_id']
而不是 $order_id
并将您的 SMS 代码放在
if (isset($this->session->data['order_id']))
代码块的开头(使用订单 ID 在从会话中删除之前的值):
if (isset($this->session->data['order_id'])) {
$xml_data ="<?xml version="1.0"?><smslist><sms><user>username</user
<password>112131</password><message>Your order # {$this->session->data['order_id']} has been successfully received. Thank you for placing an Order at mystore.com</message><mobiles>9898000000</mobiles><senderid>Sherif</senderid><cdmasenderid>00201009546310</cdmasenderid><accountusagetypeid>1</accountusagetypeid></sms></smslist>";
$URL = "http://mainadmin.dove-sms.com/sendsms.jsp?";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// here put the rest of the code
$this->cart->clear();
// ...
}
最后,删除文件夹vqcache
的cotenets
我在我的 Opencart CMS 中集成了短信网关
它使用以下语法
$xml_data ='<?xml version="1.0"?><smslist><sms><user>username</user
<password>112131</password><message>Your order # {$order_id} has been successfully received. Thank you for placing an Order at mystore.com</message><mobiles>9898000000</mobiles><senderid>Sherif</senderid><cdmasenderid>00201009546310</cdmasenderid><accountusagetypeid>1</accountusagetypeid></sms></smslist>';
$URL = "http://mainadmin.dove-sms.com/sendsms.jsp?";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
请注意,我没有使用我的个人凭据,这只是一种语法。我已经测试了代码,使用我的凭据
它绝对可以正常工作现在,我想要的是它应该加载订单号,而不是在我的消息中显示文本 {$order_id}
!
此外,我希望通过获取 $telephone
变量
请帮助并提前致谢
包含此代码的文件:catalog/controller/checkout/sucess.php
Opencart 版本:1.5.6
找到我收到的消息的截图here
Now, What I want is it should load the order number, instead it shows the text {$order_id} in my message!
那是因为您对变量 $xml_data
使用单引号字符串,PHP 中的单引号字符串按原样 显示内容 (变量不会' t 被替换为它们的值,它们将被视为文本),要解决此问题,请改用双引号字符串 (according to the PHP manual)
Moreover I want the text to be sent to the user who has logged-in in my stored by fetching the $telephone variable
简单地$telephone = $this->customer->getTelephone()
,现在你只需要将变量$telephone
放在$xml_data
编辑
我已阅读 post 评论并注意到您收到一条错误消息,指出 $order_id
未定义,要解决此问题,请使用 $this->session->data['order_id']
而不是 $order_id
并将您的 SMS 代码放在 if (isset($this->session->data['order_id']))
代码块的开头(使用订单 ID 在从会话中删除之前的值):
if (isset($this->session->data['order_id'])) {
$xml_data ="<?xml version="1.0"?><smslist><sms><user>username</user
<password>112131</password><message>Your order # {$this->session->data['order_id']} has been successfully received. Thank you for placing an Order at mystore.com</message><mobiles>9898000000</mobiles><senderid>Sherif</senderid><cdmasenderid>00201009546310</cdmasenderid><accountusagetypeid>1</accountusagetypeid></sms></smslist>";
$URL = "http://mainadmin.dove-sms.com/sendsms.jsp?";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// here put the rest of the code
$this->cart->clear();
// ...
}
最后,删除文件夹vqcache
的cotenets