doxrxwn2252 2015-06-18 11:55
浏览 41
已采纳

xml_data传递PHP变量

I have integrated SMS Gateway in my Opencart CMS

It uses the following SYNTAX

    $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);

Please make note that I have not used my personal credentials and this is just a syntax. I have tested the code and it works absolutely fine using my credentials

Now, What I want is it should load the order number, instead it shows the text {$order_id} in my message!

Moreover I want the text to be sent to the user who has logged-in in my stored by fetching the $telephone variable

Please help and thanks in advance

File in which this code is included: catalog/controller/checkout/sucess.php

Opencart version: 1.5.6

Find the Screenshot of the message I have Received here

  • 写回答

1条回答 默认 最新

  • dpzlz08480 2015-06-18 12:35
    关注

    Now, What I want is it should load the order number, instead it shows the text {$order_id} in my message!

    That's because you are using a single quoted string for the variable $xml_data, single quoted strings in PHP display things as is (variables won't be substituted with their values, they will be treated as text), to solve this issue, use a double quoted string instead (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

    simply $telephone = $this->customer->getTelephone(), now you just need to put the variable $telephone in the correct tag in $xml_data

    Edit

    I have read the post comments and noticed that you get an error that says $order_id is not defined, to solve that, use $this->session->data['order_id'] instead of $order_id and place your SMS code in the beginning of the
    if (isset($this->session->data['order_id'])) code block like that (to use the value of order id before it's erased from session):

    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();
        // ...
    }
    

    Finally, delete cotenets of the the folder vqcache

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?