首页 新闻 赞助 找找看

PHP调用web service数据接口

0
悬赏园豆:50 [已关闭问题] 关闭于 2016-11-23 09:28

近期开发一个项目,需要网站与线下crm系统数据同步,因此需要PHP调用crm接口,但是这个接口不是常用的API接口,而是web service,以前没接触过,现在需要用到了,搞了一段时间,没搞出来,距离项目交单期越来越近,故之到博客园向各路大神虚心求教。

目前需要写一个demo来调用接口

接口的网址是:http://222.221.248.166

大概是看这个的:http://222.221.248.166/PosWebService.asmx?op=GetCardBuyList

写了一下,不成功。估计是xml没有传过去,所以提示“object(stdClass)#2 (2) { ["GetCardBuyListResult"]=> bool(false) ["msg"]=> string(35) "登录BFCRM的用户代码不存在" }”。

我是这样写的,但是就是提示不成功

ini_set("soap.wsdl_cache_enabled", "0");
header("content-type:text/html;charset=utf-8");
header("SOAPAction:http://tempuri.org/GetCardBuyList");
$url = 'http://222.221.248.166/PosWebService.asmx?WSDL';
$uri = 'http://tempuri.org/';
try{
 
$string = "<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
  <soap:Header>
    <CrmSoapHeader xmlns='http://tempuri.org/'>
      <UserId>用户名,这里是用户名,不敢泄露,忘大神理解</UserId>
      <Password>密码</Password>
    </CrmSoapHeader>
  </soap:Header>
  <soap:Body>
    <GetCardBuyList xmlns='http://tempuri.org/'>
      <vipId>20000003</vipId>
      <strStartDate>2014-01-01</strStartDate>
      <strEndDate>2015-05-10</strEndDate>
    </GetCardBuyList>
  </soap:Body>
</soap:Envelope>";
/**************************************************************/
$client = new SoapClient($url, array('trace'=>true,'exceptions'=>true));
 


//Body of the Soap Header. 
// $headerbody = array(
//     'CrmSoapHeader'=>array(
//         'UserId'=>'NYCRM', 
//      'Password'=>'Nydc123Crm'
//     )
// ); 

//Create Soap Header.        
// $header = new SOAPHeader($uri, 'CrmSoapHeader', $headerbody);        
        
//set the Headers of Soap Client. 
// $client->__setSoapHeaders($header); 

$ret = $client->__soapCall('GetCardBuyList',array($string));
var_dump($ret);
} catch (SOAPFault $e) {
    print $e;
}
鱼塘总裁的主页 鱼塘总裁 | 初学一级 | 园豆:179
提问于:2015-05-22 09:08
< >
分享
所有回答(1)
0
试一下吧.没有验证!



<?php


$client = new SoapClient("http://222.221.248.166/PosWebService.asmx?WSDL");

$userId='';
$password='';
$headerbody = array('UserId' => $userId, 
'Password' => $password); 
$header = new SOAPHeader('http://tempuri.org', 'CrmSoapHeader', $headerbody); 
$client->__setSoapHeaders($header);
//参数值
$vipId= '20000003';
$strStartDate= '2014-01-01';
$strEndDate= '2015-05-10';
$param = array('vipId' => $vipId,'strStartDate' =>$strStartDate,'strEndDate' => $strEndDate);
$arr = $client->__soapCall(GetCardBuyList,array('parameters' => $param));
//$arr = $client->ServiceMethod($param);

print_r($arr);
?>
www.710.so | 园豆:234 (菜鸟二级) | 2015-05-25 16:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册