Magento:与第三方电子邮件服务的XML SOAP集成

时间:2017-09-08 14:33:42

标签: php xml forms magento soap

我正在尝试通过表单操作帖子与Magento中的第三方电子邮件服务集成,但它似乎不起作用。我希望消除在将其发送给第三方服务部门进行调查之前我可能在Magento端出现某种错误的可能性。

首先,这是我的HTML:

<form action="/external/multisubscribe.php" method="post" width="600px" style="margin: 0 auto;">
	<table style="text-align: center; vertical-align: middle; width: 100%;">
		<tbody>
			<tr>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: 0 20px 0 20px;">
					<a href="www.example.com/pilotshop/">
						<img style="width: 100%; margin: 0 auto;" src="{{media url='wysiwyg/spslogo.png'}}" alt="Pilot Shop" />
					</a>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: 0 20px 0 20px;">
					<a href="">
						<img style="width: 60%; margin: 0 auto;" src="{{media url='wysiwyg/Aflogo.jpg'}}" alt="" />
					</a>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: 0 20px 0 20px;">
					<a href="">
						<img style="width: 60%; margin: 0 auto;" alt="iPad Pilot News" src="/files/2016/03/iPad-Pilot-News-header-544-white-300x99.png" />
					</a>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: padding: 0 20px 0 20px;">
					<a href="">
						<img style="width: 50%; margin: 0 auto;" alt="Student Pilot News" src="/media/wysiwyg/Student-Pilot-News-final-140.png" />
					</a>
				</td>
			</tr>
			<tr>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: 0 20px 0 20px;">
					<p>The online magazine where readers are pilot in command. Opinion, analysis, tips and debate.</p>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: 0 20px 0 20px;">
					<p>The online magazine where readers are pilot in command. Opinion, analysis, tips and debate.</p>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: 0 20px 0 20px;">
					<p>Your #1 source for tips, tricks, videos and quizzes about flying with the iPad.</p>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%; padding: 0 20px 0 20px;">
					<p>Everything new pilots need, from free videos to a flight school directory.</p>
				</td>
			</tr>
			<tr>
				<td style="text-align: center; vertical-align: middle; width:25%;">
					<label>
						<input style="text-align: center; vertical-align: middle; margin: 0 auto; display: inline-block;" name="pilotshop" type="checkbox" /> Sign Me Up 
					</label>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%;">
					<label>
						<input style="text-align: center; vertical-align: middle; margin: 0 auto; display: inline-block;" name="airfacts" type="checkbox" /> Sign Me Up 
					</label>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%;">
					<label>
						<input style="text-align: center; vertical-align: middle; margin: 0 auto; display: inline-block;" name="ipad" type="checkbox" /> Sign Me Up 
					</label>
				</td>
				<td style="text-align: center; vertical-align: middle; width:25%;">
					<label>
						<input style="text-align: center; vertical-align: middle; margin: 0 auto; display: inline-block;" name="learntofly" type="checkbox" /> Sign Me Up 
					</label>
				</td>
			</tr>			
		</tbody>
	</table>
	<div style="text-align:center;vertical-align:center;width:100%;margin-top:3.0em;">
		<input style="text-align: center; vertical-align: middle; margin: 0 auto;" name="email" placeholder="Enter Your Email" type="email" />
		<button style="text-align: center; vertical-align: middle; margin: 0 auto;margin-top:1.200em;" type="submit" name="submit" title="Subscribe" class="button">Subscribe</button>
	</div>
	<input name="redirect" value="{{store url="email-subscribe-success"}}" type="hidden" />
	<input name="action" value="subscribe" type="hidden" />
</form>

这是我的PHP for multisubscribe.php

<?php
include_once "../app/Mage.php";
if(isset($_POST['submit'])) {
    $choices = array();
    if (isset($_POST['airfacts'])) {
        $choices[] = 'airfacts';
    }
    if (isset($_POST['ipad'])) {
        $choices[] = 'ipad';
    }
    if (isset($_POST['learntofly'])) {
        $choices[] = 'learntofly';
    }
    if (isset($_POST['pilotshop'])) {
        $choices[] = 'pilotshop';
    }
    if (count($choices) == 0) {
        echo "Please choose at least one subscription.";
    } else {
        $email = $_POST['email'];
        $email = filter_var($email, FILTER_SANITIZE_EMAIL);
        wpSubscription($choices, $email, $_POST['action']);
    }
        $redirect = $_POST['redirect'];
        header('Location: ' . $redirect);
    }

    function wpSubscription($sites, $email, $action)
    {
        $mh = curl_multi_init();
        $curl_reference_array = array();
        $unsubscribe_url_array = array();
        foreach ($sites as $site) {

             if ($site =='pilotshop') {
                $sh_param = array(
                    'UserName' => "", //Removed user for security purposes
                    'Password' => "" //Removed pass for security purposes
                );
                $authvalues = new SoapVar($sh_param, SOAP_ENC_OBJECT);
                $headers[] = new SoapHeader("https://webservices.listrak.com/v31/",
                    'WSUser', $sh_param);
                $soapClient = new SoapClient(
                    "https://webservices.listrak.com/v31/IntegrationService.asmx?WSDL",
                    array(
                        'trace' => 1,
                        'exceptions' => true,
                        'cache_wsdl' => WSDL_CACHE_NONE,
                        'soap_version' => SOAP_1_2
                    )
                );

                $soapClient->__setSoapHeaders($headers);
                $params = array(
                    'WSContact' => array(
                        'EmailAddress' => $email,
                        'ListID' => '348377'
                    ),
                    'ProfileUpdateType' => 'Overwrite',
                    'ExternalEventIDs' => '12182',
                    'OverrideUnsubscribe' => true
                );

                Mage::log($params, null, 'mylogfile.log');

                try {

                    $rest = $soapClient->SetContact($params);

                } catch (SoapFault $e) {

                    echo '<pre>';

                    print($e->getMessage());

                    echo '</pre>';
                }

                $listtracksend = true;
                return $this;
            }
            else if ($action == 'subscribe' and in_array($sites, array('airfacts', 'ipad', 'learntofly'))) {
                 $url = "http://example.com/" . $site . "/?na=ajaxsub";
            }
            else if ($action == 'unsubscribe') {
                 $url = "/unsubscribe.php";
            }
            else {
                return $this;
            }

            $fields = array(
                'ne' => $email,
                'site' => $site
            );
            $ch = curl_init($url);
            if ($action == 'unsubscribe') {
                $returntransfer = true;
            } else {
                $returntransfer = false;
            }
            $opts = array(
                CURLOPT_POSTFIELDS => $fields,
                CURLOPT_RETURNTRANSFER => $returntransfer
            );
            curl_setopt_array($ch, $opts);
            curl_multi_add_handle($mh, $ch);
            $curl_reference_array[] = $ch;
        }

        $active = null;

        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($active > 0);

        foreach ($curl_reference_array as $chref) {
            $html = curl_multi_getcontent($chref);
            $chu = curl_init($html);
            $fields = array(
                'ts' => time()
            );
            $opts = array(
                CURLOPT_POSTFIELDS => $fields
            );
            curl_setopt_array($chu, $opts);
            curl_exec($chu);
            curl_close($chu);
            curl_multi_remove_handle($mh, $chref);
        }

        curl_multi_close($mh);
        return $this;
    }

?>

1 个答案:

答案 0 :(得分:0)

更改了这一行:

$headers[] = new SoapHeader("https://webservices.listrak.com/v31/",

删除https并且有效。怪异。

$headers[] = new SoapHeader("http://webservices.listrak.com/v31/",
相关问题