I have to implement form on a webpage, that sends data to Microsoft Dynamics CRM when submited. The data needs to be saved to a certain lead.
我必须在网页上实现表单,在提交时将数据发送到Microsoft Dynamics CRM。数据需要保存到某个特定的位置。
I have created simple PHP script that uses curl to communicate with CRM server but I always get 401
status code that indicates authorization has failed.
我创建了一个简单的PHP脚本,它使用curl与CRM服务器通信,但我总是得到401状态码,表明授权失败。
define('MS_CRM_URL', 'https://______.crm.dynamics.com/');
define('MS_CRM_USER', 'user@domain.com');
define('MS_CRM_PASS', 'password');
$method = '/api/data/v8.0/accounts?$select=name&$top=3';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, MS_CRM_URL . $method);
curl_setopt($ch, CURLOPT_USERPWD, MS_CRM_USER .':'. MS_CRM_PASS);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept' => 'application/json',
'OData-MaxVersion' => '4.0',
'OData-Version' => '4.0',
'Content-Type' => 'application/json',
));
$server_output = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$json = array();
if ((int)$status_code === 200) {
$json = json_decode($server_output);
}
echo '<pre>';
var_dump($status_code);
var_dump($json);
echo '</pre>';
The $method
var contents are taken from an example that I've found somewhere on Microsoft documentation site. The documentation was not very helpful to me.
$method var内容取自我在Microsoft文档站点上找到的一个示例。文件对我不是很有帮助。
2 个解决方案
#1
1
Have you seen this yet? http://jlattimer.blogspot.com/2015/02/soap-only-authentication-using-php.html
你见过这个吗?http://jlattimer.blogspot.com/2015/02/soap-only-authentication-using-php.html
Also, it looks like there's an ADAL library for PHP. https://github.com/jamesmcq/azure-activedirectory-library-for-php You should be able to authenticate using that.
而且,看起来有一个用于PHP的ADAL库。您应该能够使用它进行身份验证。
#2
0
You can do it using SOAP Authentication. I have same requirement where we need to send data to Dynamics 365 online from PHP website. I have achieved it using source code from below link :
您可以使用SOAP身份验证来实现它。我有同样的要求,我们需要从PHP网站向Dynamics 365在线发送数据。我通过以下链接的源代码实现了它:
https://bitbucket.org/nigelheap/msdynamicsphp-master
https://bitbucket.org/nigelheap/msdynamicsphp-master
#1
1
Have you seen this yet? http://jlattimer.blogspot.com/2015/02/soap-only-authentication-using-php.html
你见过这个吗?http://jlattimer.blogspot.com/2015/02/soap-only-authentication-using-php.html
Also, it looks like there's an ADAL library for PHP. https://github.com/jamesmcq/azure-activedirectory-library-for-php You should be able to authenticate using that.
而且,看起来有一个用于PHP的ADAL库。您应该能够使用它进行身份验证。
#2
0
You can do it using SOAP Authentication. I have same requirement where we need to send data to Dynamics 365 online from PHP website. I have achieved it using source code from below link :
您可以使用SOAP身份验证来实现它。我有同样的要求,我们需要从PHP网站向Dynamics 365在线发送数据。我通过以下链接的源代码实现了它:
https://bitbucket.org/nigelheap/msdynamicsphp-master
https://bitbucket.org/nigelheap/msdynamicsphp-master