You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
8.8 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
class PEISApiController extends Controller
{
public static $request;
public static function Api($url_code, $code)
{
//正式
$env=config('app.globals.Env');
if($env=='pro') { //如果是正式环境
//思信测试环境H5正式环境
$url = 'http://220.174.210.111:8888';
$api['套餐详情查询'] = "{$url}/PEISCommon/QueryComboDetail?key=YmMxOGI2MDUxZmFh";
$api['自选项目查询'] = "{$url}/PEISCommon/QueryGroups?key=YmMxOGI2MDUxZmFh";
$api['套餐查询'] = "{$url}/PEISCommon/QueryCombos?key=YmMxOGI2MDUxZmFh";
$api['套餐项目检查'] = "{$url}/PEISCommon/CheckComboAndGroup?key=YmMxOGI2MDUxZmFh";
$api['个检预约'] = "{$url}/PEISCommon/PersonAppointment?key=YmMxOGI2MDUxZmFh";
$api['个检预约查询'] = "{$url}/PEISCommon/QueryPersonAppointment?key=YmMxOGI2MDUxZmFh";
$api['个检预约取消'] = "{$url}/PEISCommon/CancelPersonAppointment?key=YmMxOGI2MDUxZmFh";
$api['团检登记查询'] = "{$url}/PEISCommon/QueryUnitAppointmentReg?key=YmMxOGI2MDUxZmFh";
$api['团检预约'] = "{$url}/PEISCommon/UnitAppointment?key=YmMxOGI2MDUxZmFh";
$api['团检预约查询'] = "{$url}/PEISCommon/QueryUnitAppointment?key=YmMxOGI2MDUxZmFh";
$api['团检预约取消'] = "{$url}/PEISCommon/CancelUnitAppointment?key=YmMxOGI2MDUxZmFh";
$api['体检报告查询'] = "{$url}/PEISCommon/QueryExamReport?key=YmMxOGI2MDUxZmFh";
$api['预约时段修改'] = "{$url}/PEISCommon/ModifyAppointmentDTRange?key=YmMxOGI2MDUxZmFh";
$api['修改用户预约时间'] = "{$url}/ExtAPI/SetAppointmentMoment?key=YmMxOGI2MDUxZmFh&{$code}";
$api['分诊查询体检号'] = "{$url}/PEISCommon/QueryEventNo?key=YmMxOGI2MDUxZmFh";
$api['单位分组批次查询'] = "{$url}/PEISCommon/QueryBatchAndGroup?key=YmMxOGI2MDUxZmFh";
$api['报告时间计算'] = "{$url}/Home/CalcReportDays?eventNos={$code}";
$api['弃检接口'] = "{$url}/Home/AbandonCheck";
$api['检后签到'] = "{$url}/Home/PostExamSignIn?eventNo={$code}";
$api['个检预约设置套餐和项目信息'] = "{$url}/PEISCommon/PersonAppSetComboInfo?key=YmMxOGI2MDUxZmFh";
}
if($env=='dev') { //如果是测试环境
$url = 'https://dqgatjzx-wx.sixinyun.com';
$api['套餐详情查询'] = "{$url}/PEISCommon/QueryComboDetail/{$code}";
$api['自选项目查询'] = "{$url}/PEISCommon/QueryGroups/{$code}";
$api['套餐查询'] = "{$url}/PEISCommon/QueryCombos/{$code}";
$api['套餐项目检查'] = "{$url}/PEISCommon/CheckComboAndGroup/{$code}";
$api['个检预约'] = "{$url}/PEISCommon/PersonAppointment/{$code}";
$api['个检预约查询'] = "{$url}/PEISCommon/QueryPersonAppointment/{$code}";
$api['个检预约取消'] = "{$url}/PEISCommon/CancelPersonAppointment/{$code}";
$api['团检登记查询'] = "{$url}/PEISCommon/QueryUnitAppointmentReg/{$code}";
$api['团检预约'] = "{$url}/PEISCommon/UnitAppointment/{$code}";
$api['团检预约查询'] = "{$url}/PEISCommon/QueryUnitAppointment/{$code}";
$api['团检预约取消'] = "{$url}/PEISCommon/CancelUnitAppointment/{$code}";
$api['体检报告查询'] = "{$url}/PEISCommon/QueryExamReport/{$code}";
$api['预约时段修改'] = "{$url}/PEISCommon/ModifyAppointmentDTRange/{$code}";
$api['修改用户预约时间'] = "http://220.174.210.111:8888/ExtAPI/SetAppointmentMoment?key=YmMxOGI2MDUxZmFh&{$code}";
$api['分诊查询体检号'] = "{$url}/PEISCommon/QueryEventNo/{$code}";
$api['单位分组批次查询'] = "{$url}/PEISCommon/QueryBatchAndGroup/{$code}";
$api['报告时间计算'] = "{$url}/Home/CalcReportDays?eventNos={$code}";
$api['弃检接口'] = "{$url}/Home/AbandonCheck/{$code}";
$api['检后签到'] = "{$url}/Home/PostExamSignIn?eventNo={$code}";
}
return $api["{$url_code}"] ?? $url_code;
}
public static function Post($url_code, $hospital_id, $data, $print = false)
{
$hospital = DB::table('hospitals')->where(['id' => $hospital_id, 'status' => 1, 'is_del' => 0])->first();
if (!$hospital) return \Yz::echoError1('医院不存在或不可用');
$code = $hospital->code;
$url = self::Api($url_code, $code);
self::RequestLog($url, $data, $code, $url_code);
$data_string = json_encode($data, JSON_UNESCAPED_UNICODE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string)
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$res_string = curl_exec($ch);
curl_close($ch);
$str_len = mb_strlen($res_string, 'utf-8');
$str_size = $str_len / 1024;
$save_res = $res_string;
if ($str_size > 10) $save_res = '{"data":"Row size too large"}';
self::$request->response_data = $save_res;
self::$request->save();
if (!json_decode($res_string, true)) {
throw new HttpResponseException( \Yz::echoError1("体检系统提示:".$res_string));
}
$res = json_decode($res_string, true);
if ($res['ResultCode'] != 0){
throw new HttpResponseException( \Yz::echoError1("体检系统提示:". $res['ResultContent']));
}
return [
'code' => $res['ResultCode'],
'message' => $res['ResultContent'],
'data' => $res['Records']
];
}
public static function Post2($url_code,$url, $hospital_id, $data)
{
$hospital = DB::table('hospitals')->where(['id' => $hospital_id, 'status' => 1, 'is_del' => 0])->first();
if (!$hospital) return \Yz::echoError1('医院不存在或不可用');
$code = $hospital->code;
self::RequestLog($url, $data, $code, $url_code);
$data_string = json_encode($data, JSON_UNESCAPED_UNICODE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string)
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$res_string = curl_exec($ch);
curl_close($ch);
$str_len = mb_strlen($res_string, 'utf-8');
$str_size = $str_len / 1024;
$save_res = $res_string;
if ($str_size > 10) $save_res = '{"data":"Row size too large"}';
self::$request->response_data = $save_res;
self::$request->save();
return $res_string;
}
public static function Get($url,$code,$mark)
{
self::RequestLog($url, [], $code,$mark);
$response = Http::get($url);
if ($response->successful()) {
$res = $response->json();
self::$request->response_data = json_encode($res, JSON_UNESCAPED_UNICODE);
self::$request->save();
return $res;
} else {
$status = $response->status();
// 获取响应体作为字符串
$body = $response->body();
self::$request->response_data = $body;
self::$request->save();
throw new HttpResponseException(\Yz::echoError1("调用".$mark."接口失败:" . $status . "body:" . $body));
}
}
public static function RequestLog($url, $post_data, $code, $mark)
{
self::CheckTableName();
foreach ($post_data as $key => $post_datum) {
$str_len = mb_strlen(json_encode($post_datum, JSON_UNESCAPED_UNICODE), 'utf-8');
$str_size = $str_len / 1024;
if ($str_size > 10) {
$post_data["$key"] = 'Row size too large';
}
}
$post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE);
self::$request->code = $code;
self::$request->mark = $mark;
self::$request->post_data = $post_data == '[]' ? '{}' : $post_data;
self::$request->request_url = $url;
self::$request->save();
}
public static function CheckTableName()
{
$table_name = 'zz_peis_log_' . date('ym');
$table_count = DB::select('select count(1) as c from information_schema.TABLES where table_schema = ? and table_name = ?', [env('DB_DATABASE'), $table_name])[0];
if ($table_count->c === 0) {
Schema::create($table_name, function (Blueprint $table) {
$table->id();
$table->string('code', 50)->index();
$table->string('mark', 50)->index();
$table->text('post_data');
$table->text('response_data')->nullable();
$table->string('request_url', 2000);
$table->timestamps();
});
}
self::$request = new \App\Models\PEISLog();
self::$request->setTable($table_name);
}
}