项目中使用到了调用三方厂商webService接口。他的接口类似为http://haha.cn:86/BaseInfoService.svc?wsdl,在这里我注意到了“wsdl“以前从来没有过这种接口的经验,起初想用CURL调用,但是一直失败,后来想到了php扩展soap
以下为我的代码:
function SendLeads($data){ ???????header(‘Content-Type:text/html; charset=utf-8‘);//设置编码方式UTF-8 ???????ini_set(‘soap.wsdl_cache_enabled‘,‘0‘);//关闭缓存 ???????$url = ‘http://ddmp.audi-online.cn:86/BaseInfoService.svc?wsdl‘; ???????$client = new \SoapClient($url); ???????//dump($client);die; ???????$para = array( ???????????‘Key‘=>$this->User_Key, ???????????//‘RequestType‘=>array( ???????????// ???‘Type‘=>0, ???????????// ???‘MaxID‘=>‘‘, ???????????// ???‘MaxTime‘=>‘‘, ???????????//), ???????????‘RequestObjectList‘=>array( ???????????????array( ???????????????????‘ADDRESS‘=>null, ???????????????????‘BIRTHDAY‘=>null, ???????????????????‘BUSINESS_PHONE‘=>null, ???????????????????‘BUY_PLAN_TIME_CODE‘=>‘0‘, ???????????????????‘CAR_COLOR‘=>null, ???????????????????‘PROVINCE‘=>$data[‘province‘], ?//省份 ???????????????????‘CITY‘=>$data[‘city‘],//城市 ???????????????????‘FK_DEALER_ID‘=>$data[‘dealer_name‘], //经销商编号 ???????????????????‘COMMENTS‘=>null, ???????????????????‘CONTACT_METHOD‘=>null, ???????????????????‘CUSTOMER_NAME‘=>$data[‘name‘], ???????????????????‘GENDER‘=>null, ???????????????????‘INDUSTRY‘=>null, ???????????????????‘LEAD_TYPE‘=>$this->Leadtype, //渠道标识 ???????????????????‘MEDIA_LEAD_ID‘=>$this->User_Key.‘xingy‘.rand(1000000000,9999999999), ???????????????????‘MOBILE‘=>$data[‘mobile‘], ???????????????????‘MODEL‘=>‘‘, ?//意向车型 ???????????????????‘ORDER_TIME‘=>date(‘Y-m-d H:i:s‘,time()), ?//下单时间 ???????????????????‘PHONE‘=>null, ???????????????????‘PROFESSION‘=>null, ???????????????????‘SERIES‘=>‘15‘, //车系 ???????????????????‘USER_KEY‘=>$this->User_Key, ???????????????????‘SMART_CODE‘=>‘3513‘)));//设置参数(参数格式为第三方要求的格式) 参数为数组方式传递空数组用array 参数之间用,分隔。 key value形式 => 为指向值 ???????$jsonData = json_encode($para); //转json ???????$date = array(‘inputParam‘=>$jsonData); ???????$result = $client->SendLeads($date); ???????$array = get_object_vars($result); ???????$str = $array[‘SendLeadsResult‘]; ???????$arr = json_decode($str,true); ???????if($arr[‘Success‘]==‘1‘ && $arr[‘Message‘]==‘执行成功‘){ ???????????return json_encode([‘code‘=>1,‘msg‘=>‘执行成功‘]); ???????}else{ ???????????return json_encode([‘code‘=>0,‘msg‘=>‘执行失败‘]); ???????} ???}
这里大家可能会遇到一种问题就是在本地调试是成功的,但是上传到服务器就会报错(504),通过和接口提供方沟通发现我们的服务器在出去之前是有防火墙限制的,于是要了他们的端口号,在我们服务器开了相关接口,搞定了!!!希望对大家有帮助,有不足的地方请大家评论指正!谢谢!!
php调用webservice接口
原文地址:http://www.cnblogs.com/qichao123/p/7591456.html