zoukankan      html  css  js  c++  java
  • Guzzle(第三方类库)

    Guzzle是一个PHP的HTTP客户端,用来轻而易举地发送请求,并集成到我们的WEB服务上。

    详情去看facepay 项目

     class Base
     {
         //protected $baseURL='http://150.1.1.75:8090/';
         protected $baseURL='http://150.138.1.33:8050/';
         protected $key='YG';
         protected $secret='123456';
         protected $signSecret = 'lbyg_domall';
         protected  function getJSON($url,$param){
             try{
                 $param['ObKey'] = $this->key;
                 $param['ObSecret'] = $this->secret;
                 $sign=$this->createSign($param);
    
                 $param['Sign']=$sign;
                 $httpClient = new Client(['base_uri'=>$this->baseURL]);
                 $result=$httpClient->request('GET',$url,[
                     'query' => $param
                 ])->getBody()->getContents();
                 $result=json_decode($result,true);
                 if(empty($result)||empty($result['State'])){
                     Log::error("数据中心接口{$url}调用未返回信息");
                 }
                 if($result['State']==-1){
                     Log::error("数据中心接口{$url}调用失败:".$result['Message'].',调用数据:'.GuzzleHttpjson_encode($param));
                 }
                 return $result;
             }catch (Exception $e){
                 Log::error("数据中心接口{$url}调用异常:".$e->getMessage());
                 return null;
             }
             return null;
         }
         protected  function postJSON($url='',$param=[]){
             try{
                 $query['ObKey'] = $this->key;
                 $query['ObSecret'] = $this->secret;
                 if($param){
                     $param = json_encode($param);
                     $param = base64_encode($param);
                 }
                 $query['Sign']=$this->createSign($param);
                 $httpClient = new Client(['base_uri'=>$this->baseURL]);
                 $start=microtime(true);
                 $result=$httpClient->request('POST',$url,[
                     'query' => $query,
                     'body' => $param
                 ])->getBody()->getContents();
                 $end = microtime(true);
                 $exeTime= round($end-$start,3);
                 Log::error("接口:$url,执行时间:$exeTime");
                 $result=json_decode($result,true);
                 if(empty($result)||empty($result['State'])){
                     Log::error("数据中心接口{$url}调用未返回信息");
                 }
                 if($result['State']==-1){
                     Log::error("数据中心接口{$url}调用失败:".$result['Message'].',调用数据:'.GuzzleHttpjson_encode($param));
                 }
                 return $result;
             }catch (Exception $e){
                 Log::error('数据中心接口调用异常:'.$e->getMessage());
                 return null;
             }
             return null;
    
         }
    
       
    
     }
    

      

  • 相关阅读:
    SpringBoot入门
    VUE 监听局部滚动 设置ICON的位置跟随
    手机端页面调试工具-vconsole使用
    js获取字符串字节的位数
    判断数据为[] {} /空数组或空对象
    Vue axios 上传图片
    Vue触发input选取文件点击事件
    腾讯地图添加多个Marker
    VUE-CLI 设置页面title
    小程序wxml文件引用方式
  • 原文地址:https://www.cnblogs.com/wangyuyanhello/p/10026049.html
Copyright © 2011-2022 走看看