curl:get,post 以及SoapClien访问webservice数据


一。curl get模式

public function close_order()
{

$url="http://192.168.2.50:7777/U8API.asmx?op=InsertSo=".$ordersn;
    $getinfo = $this->httpGet($url);
return $getinfo;
}
    public function httpGet($url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }

二。curl post模式

public function insert_order()
{
$data['cSOCode']='20171105455555';//订单号
$data['dDate']='2017-11-01'; //下单日期
$data['cCusCode']='';//客户编码
$data['Details']=array(
array('cInvCode'=>'B03602','iQuantity'=>12,'iTaxUnitPrice'=>7000)
);
$string=json_encode($data);
$getinfo = $this->httpPost($string);
return $getinfo;
}
    public function httpPost($data) {
        $postUrl = 'http://192.168.2.50:7777/U8API.asmx/InsertSo';
        $postData = array(
            'strJson'=>$data
        );
        $postData = http_build_query($postData);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $postUrl);
        curl_setopt($curl, CURLOPT_USERAGENT,'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15');
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        $r = curl_exec($curl);
        curl_close($curl);
        return $r;
    }

三。SoapClient模式

public function insert_order()
{
$data['cSOCode']='20171105455555';//订单号
$data['dDate']='2017-11-01'; //下单日期
$data['cCusCode']='';//客户编码
$data['Details']=array(
array('cInvCode'=>'B03602','iQuantity'=>12,'iTaxUnitPrice'=>7000)
);
$string=json_encode($data);
$getinfo = $this->closeOrderToErp($string);
return $getinfo;
}
    public function closeOrderToErp($data)
    {

        $client = new \SoapClient("http://erpapi.chengmei.com:7777/U8API.asmx?wsdl");
        $client->soap_defencoding = "utf-8";
        $client->decode_utf8 = false;
        $client->xml_encoding = "utf-8";
        $result = $client->__Call('UpdateSo', array(
            array(
                'cCode' => $data
            )
        ));
        $list = (array)$result;
        return json_decode($list['UpdateSoResult'], true);
    }

 

 

 

posted on 2017-11-02 13:55  长不大的菜鸟  阅读(701)  评论(0编辑  收藏  举报

导航