|
@@ -434,6 +434,42 @@ class MayCurServerService extends Service
|
|
return [true, $return];
|
|
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){
|
|
public function post_helper($url, $data, $header = [], $timeout = 20){
|
|
Log::channel('apiMcLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
|
|
Log::channel('apiMcLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
|
|
|
|
|
|
@@ -502,4 +538,42 @@ class MayCurServerService extends Service
|
|
|
|
|
|
return [true, $return];
|
|
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];
|
|
|
|
+ }
|
|
}
|
|
}
|