我已在我的Opencart CMS中集成了SMS Gateway
它使用以下语法
$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
答案 0 :(得分:0)
现在,我想要的是它应该加载订单号,而不是在我的消息中显示文本{$ order_id}!
那是因为你对变量$xml_data
使用单引号字符串,PHP中的单引号字符串显示 (变量不会被它们的值替换,它们将被视为文本),要解决此问题,请使用双引号字符串(according to the PHP manual)
此外,我希望通过获取$ telephone变量
将文本发送给已存储的用户
只需$telephone = $this->customer->getTelephone()
,现在您只需将变量$telephone
放入$xml_data
我已阅读帖子评论,发现您收到的错误是$order_id
未定义,要解决此问题,请使用$this->session->data['order_id']
代替$order_id
并将您的短信代码放入这样的if (isset($this->session->data['order_id']))
代码块的开头(在从会话中删除之前使用order 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