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.
92 lines
3.5 KiB
PHP
92 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use SM4;
|
|
use Yo;
|
|
|
|
require_once __DIR__ . '/../../Libraries/SM4.php';
|
|
class XcxController extends Controller
|
|
{
|
|
public static $key='llDhjopdshYJdfjk';
|
|
public static $request;
|
|
public static $GetUserInfoUrl='https://api.gaobuyy.com:10010/cms-api/cms/patientInfo/getHealthCheckPatient';
|
|
public function GetUserInfo(Request $request){
|
|
$token = $request->post('token');
|
|
//$token='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiJhcHBfdXNlcjoxOTA3NjYwNzQ2NjkwMDkzMDU3Iiwicm5TdHIiOiJGTWw5SFhOVktJMFlJQUdTdUpYY2tVcFdDeDIwaXduYSIsImNsaWVudGlkIjoiNDI4YTgzMTBjZDQ0Mjc1N2FlNjk5ZGY1ZDg5NGYwNTEiLCJ0ZW5hbnRJZCI6IjAwMDAwMCIsInVzZXJJZCI6MTkwNzY2MDc0NjY5MDA5MzA1NywidXNlck5hbWUiOiJvUUFGYzdOTFR4a0E5YmpFTnBCYV9seW9vdkxZIn0.JeDw-NFZ_cRDQHwOSGEaGYcIK12BfnDTeiBLqUBaqNQ';
|
|
$url=env('APP_URL').'/casLogin';
|
|
$data = [];
|
|
self::RequestLog(self::$GetUserInfoUrl , $data, "获取用户信息", '小程序接口');
|
|
$response = Http::withHeaders([
|
|
'Authorization' => 'Bearer '.$token,
|
|
'clientid' => '428a8310cd442757ae699df5d894f051'
|
|
])->get(self::$GetUserInfoUrl,$data);
|
|
|
|
if (!$response->successful()) {
|
|
self::$request->response_data = "请求小程序接口失败";
|
|
self::$request->save();
|
|
return Yo::error_echo(200092);
|
|
}
|
|
$res=$response->json();
|
|
// 处理成功的响应
|
|
$res_string = json_encode($res, JSON_UNESCAPED_UNICODE);
|
|
|
|
$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(isset($res['data']['idCardNo'])){
|
|
$SM4= new SM4();
|
|
$res['data']['idCardNo'] = $SM4->decrypt(self::$key,$res['data']['idCardNo']);
|
|
return Yo::echo(['id_number' => $res['data']['idCardNo']]);
|
|
}else{
|
|
return Yo::error_echo(200093);
|
|
}
|
|
|
|
}
|
|
|
|
public static function RequestLog($url, $post_data, $mark, $code = 0)
|
|
{
|
|
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);
|
|
}
|
|
}
|