doujin8673 2019-04-18 08:19
浏览 54

在WordPress中的xml请求期间收到错误

I'm using an API to post XML request in WordPress. I wrote this code and I typed it in function.php but I get an error:

Cannot redeclare createRequestXML() (previously declared in /home/aquamahi/public_html/wp-content/themes/topcommerce/functions.php:1641) in /home/aquamahi/public_html/wp-content/themes/topcommerce/functions.php on line 1639

and line 1639 is: function createRequestXML()

$user = get_users();

foreach($user as $item){

    $URL = 'http://api.payamak-panel.com/post/Contacts.asmx';

    function createRequestXML() {

        $first_name = get_user_meta($item->id,"first_name",true);
        $last_name = get_user_meta($item->id,"last_name",true);

        $xml = '    <?xml version="1.0" encoding="UTF-8" ?>
                    <SecurityInfo>
                        <Username>09212395651</Username>
                        <Password>M@hiPet@12345</Password>
                    </SecurityInfo>
                    <Lead>
                        <GroupIds>571566</GroupIds>
                        <FirstName>'.$first_name.'</FirstName>
                        <LastName>'.$last_name.'</LastName>
                        <MobileNumber>'.$item->login.'</MobileNumber>
                        <BirthDate>01/01/1300</BirthDate>
                        <Gender>2</Gender>
                        <Province>021</Province>
                        <City>021</City>
                        <AdditionalDate>1/1/1300</AdditionalDate>

                    </Lead>';

        return str_replace("
","",$xml);
    }

    $send = createRequestXML();

    try {
        $client = new SoapClient("http://api.payamak-panel.com/post/Contacts.asmx?wsdl",array(
            'location'      => $URL,
            'uri'           => "http://www.reefservices.co.uk/leadws/",
            'trace'         => 1,
            'exceptions'    => true
        ));

        $return = $client->Submit(array('Data' => $send));

        echo '<pre>';
        print_r($return);
        echo '</pre>';
    } catch(SoapFault $e) {
        echo '<h3>Exception</h3>';
        echo '<pre>';
        print_r($e);
        echo '</pre>';
    }
}
  • 写回答

1条回答 默认 最新

  • douqufan9148 2019-04-18 08:23
    关注

    You are loading the file containing the functions twice. Find where it is being required for the second time, and remove the include/require, or change it to require_once()

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错