在WordPress的xml请求期间获取错误

时间:2019-04-18 08:19:19

标签: php xml wordpress api

我正在使用API​​在WordPress中发布XML请求。我编写了这段代码,并在function.php中键入了代码,但出现错误:

无法在/ home / aquamahi / public_html / wp-content / themes / topcommerce / functions中重新声明createRequestXML()(先前在/home/aquamahi/public_html/wp-content/themes/topcommerce/functions.php:1641中声明) .php 1639行

第1639行是: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("\n","",$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 个答案:

答案 0 :(得分:0)

您正在两次加载包含功能的文件。找到第二次需要的位置,然后删除包含/要求,或将其更改为require_once()