소스 검색

每刻 接口

cqp 4 달 전
부모
커밋
5c5089e1ec
3개의 변경된 파일81개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 0
      app/Http/Controllers/Api/MayCurController.php
  2. 74 0
      app/Service/MayCurServerService.php
  3. 2 1
      routes/maycur.php

+ 5 - 0
app/Http/Controllers/Api/MayCurController.php

@@ -48,4 +48,9 @@ class MayCurController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function saveOaData(Request $request){
+        $data = (new MayCurServerService())->saveOaData($request->all(),$request->header());
+        return $data;
+    }
 }

+ 74 - 0
app/Service/MayCurServerService.php

@@ -434,6 +434,42 @@ class MayCurServerService extends Service
         return [true, $return];
     }
 
+    //保存到oa
+    public function saveOaData($data, $header){
+        $return = [
+            'status' => 'error',
+            'success' => false,
+            'message' => "",
+            'data' => null,
+        ];
+
+        //失败
+        if(empty($data)) {
+            $return['message'] = '请求参数不能为空';
+            return $return;
+        }
+
+        $url = "https://gzy.qingyaokeji.com/api/module-data/voucher_oa_pay/voucher_oa_pay/diy/save_oa_data";
+        $post = $data;
+        $auth = $header['authorization'][0] ?? "";
+        $header = array_merge(['Content-Type:application/json'], ['Authorization: ' . $auth]);
+        list($status, $result) = $this->post_helper1($url,$post, $header);
+        if(! $status) {
+            //失败
+            $return['message'] = $result;
+            return $return;
+        }
+
+        if(isset($result['message']) && isset($result['type']) && $result['type'] === 'errorVm') {
+            //失败
+            $return['message'] = $result['description'];
+            return $return;
+        }
+        if(isset($result['success']) && $result['success'] == true) return $result;
+
+        return $result;
+    }
+
     public function post_helper($url, $data, $header = [], $timeout = 20){
         Log::channel('apiMcLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
 
@@ -502,4 +538,42 @@ class MayCurServerService extends Service
 
         return [true, $return];
     }
+
+    public function post_helper1($url, $data, $header = [], $timeout = 20){
+        Log::channel('apiMcLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
+
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_ENCODING, '');
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+
+        if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+        $r = curl_exec($ch);
+
+        if ($r === false) {
+            // 获取错误号
+            $errorNumber = curl_errno($ch);
+            // 获取错误信息
+            $errorMessage = curl_error($ch);
+            $message = "cURL Error #{$errorNumber}: {$errorMessage}";
+
+            Log::channel('apiMcLog')->info('每刻POST结果', ["message" => $message]);
+            return [false, $message];
+        }
+        // 获取HTTP状态码
+        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+        curl_close($ch);
+        if($httpCode == 401) return [false, '登陆凭证错误,请检查'];
+
+        $return = json_decode($r, true);
+        Log::channel('apiMcLog')->info('每刻POST结果', ["message" => $return]);
+
+        return [true, $return];
+    }
 }

+ 2 - 1
routes/maycur.php

@@ -20,4 +20,5 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
 //Route::any('getToken', 'Api\MayCurController@getToken');
 Route::any('reimburse', 'Api\MayCurController@reimburse');
 Route::any('loan', 'Api\MayCurController@loan');
-Route::any('voucher', 'Api\MayCurController@voucher');
+Route::any('voucher', 'Api\MayCurController@voucher');
+Route::any('saveOaData', 'Api\MayCurController@saveOaData');