通过PHP cURL使用login.microsoftonline.com进行身份验证(SSL连接错误)

时间:2015-06-11 15:29:11

标签: php ssl curl dynamics-crm-2015

我正在尝试使用PHP从Micorosft Dynamics CRM 2015中提取数据。从各种来源我了解到我必须从login.microsoftonline.com开始认证。

我正在使用cURL发送XML请求,导致SSL连接错误。

XML请求:

> head(Full.df)
Count.G   Count.W   Count.S       Date      Month       Week       Year
    x         x          15 2008-01-01 2008-01-01 2007-12-31 2008-01-01
    x         x          11 2008-01-02 2008-01-01 2007-12-31 2008-01-01
    x         x          10 2008-01-03 2008-01-01 2007-12-31 2008-01-01
    x         x          12 2008-01-04 2008-01-01 2007-12-31 2008-01-01
    x         x          10 2008-01-06 2008-01-01 2007-12-31 2008-01-01
    x         x           3 2008-01-07 2008-01-01 2008-01-07 2008-01-01

cURL设置:

 <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>         
    <a:MessageID>urn:uuid:4e586759-a5cc-483c-bbd0-9f3eed7667dc</a:MessageID> 
    <a:ReplyTo>
         <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> 
    </a:ReplyTo>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo4TBVw9fIMZFmc7ZFxBXIcYAAAAAbd1LF/fnfUOzaja8sGev0GKsBdINtR5Jt13WPsZ9dPgACQAA</VsDebuggerCausalityData> 
    <a:To s:mustUnderstand="1">https://login.microsoftonline.com/RST2.srf</a:To> 
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <u:Timestamp u:Id="_0">
              <u:Created>2015-06-11T17:14:09.00Z</u:Created> 
              <u:Expires>2015-06-12T17:14:09.00Z</u:Expires> 
        </u:Timestamp>
        <o:UsernameToken u:Id="uuid-14bed392-2320-44ae-859d-fa4ec83df57f-4">
            <o:Username>{username}</o:Username> 
            <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">{password}</o:Password> 
        </o:UsernameToken>
    </o:Security>
</s:Header>
<s:Body>
    <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
        <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
            <a:EndpointReference>
                <a:Address>urn:crmemea:dynamics.com</a:Address> 
            </a:EndpointReference>
        </wsp:AppliesTo>
        <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType> 

    </t:RequestSecurityToken>
</s:Body>

标题

$headers = array(
        "POST " . $postUrl . " HTTP/1.1",
        "Host: " . $hostname,
        'Connection: Keep-Alive',
        "Content-type: application/soap+xml; charset=UTF-8",
        "Content-length: " . strlen($content),
);

$cURLHandle = curl_init();
$soapUrl = "https://login.microsoftonline.com/RST2.srf";
curl_setopt($cURLHandle, CURLOPT_URL, $soapUrl);
curl_setopt($cURLHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURLHandle, CURLOPT_TIMEOUT, 60);
curl_setopt($cURLHandle, CURLOPT_SSL_VERIFYPEER, false);        
curl_setopt($cURLHandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($cURLHandle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cURLHandle, CURLOPT_POST, 1);
curl_setopt($cURLHandle, CURLOPT_POSTFIELDS, $content);
curl_setopt($cURLHandle, CURLOPT_SSLVERSION , 3);
curl_setopt($cURLHandle, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($cURLHandle, CURLINFO_HEADER_OUT, false);
$fp = fopen('error.txt', 'w'); 
curl_setopt($cURLHandle, CURLOPT_STDERR, $fp);
curl_setopt($cURLHandle, CURLOPT_VERBOSE, true);        

$response = curl_exec($cURLHandle);

curl_error:string(17)“SSL connect error”

详细错误信息:

  • 关于connect()到login.microsoftonline.com端口443(#0)
  • 尝试23.97.148.36 ... *已连接
  • 已连接至login.microsoftonline.com(23.97.148.36)端口443(#0)
  • 警告:忽略ssl.verifyhost的值
  • NSS错误-5961
  • 关闭连接#0
  • SSL连接错误

cURL版本信息:

array(5) {
  [0]=>
  string(23) "POST /RST2.srf HTTP/1.1"
  [1]=>
  string(31) "Host: login.microsoftonline.com"
  [2]=>
  string(22) "Connection: Keep-Alive"
  [3]=>
  string(49) "Content-type: application/soap+xml; charset=UTF-8"
  [4]=>
  string(20) "Content-length: 3083"
}

如果我需要提供更多,请告诉我任何帮助将不胜感激! 有关NSS错误-5961的任何信息对我猜是有帮助的。

1 个答案:

答案 0 :(得分:1)

我怀疑这可能是您的POST和主机值的问题。您已成功连接到login.microsoftonline.com,但我认为下一步是您的组织。

我暂时还没玩过这些东西,但是我看起来像这样的价值: - POST /Organization.svc 托管yourorganisation.api.crm5.dynamics.com

显然你需要改变你的组织&#34;部分和&#34; crm5&#34;匹配您的地区。

几年前我做过一个连接,据我所知,仍然有效。 http://crmtroubleshoot.blogspot.com.au/2013/07/dynamics-crm-2011-php-and-soap-using.html