完善功能
parent
1a8b630969
commit
5440472fed
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\API;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Services\Admin\YeWu\HealthCheckupService;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class UpLoadController extends Controller
|
||||||
|
{
|
||||||
|
public function UpFile(){
|
||||||
|
$file=request('file');
|
||||||
|
|
||||||
|
if ($file->isValid()) {
|
||||||
|
// $s=app()->make(HealthCheckupService::class);
|
||||||
|
// $save=$s->SaveFile(['file'=>$file]);
|
||||||
|
$date = date("Ymd");
|
||||||
|
$save = $file->store('public/H5Upload/'.$date);
|
||||||
|
|
||||||
|
return \Yz::Return(true,'上传成功',$save);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
return \Yz::echoError1('获取文件失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\API;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use App\Lib\XTSign;
|
||||||
|
use JWT;
|
||||||
|
use App\Services\Login\LoginService;
|
||||||
|
class XTSignController extends Controller
|
||||||
|
{
|
||||||
|
//添加签名任务展示二维码
|
||||||
|
public function addSignJob(){
|
||||||
|
//添加任务签名
|
||||||
|
$data=[
|
||||||
|
// "userId"=>"b24d281af0b7f2bc3a49c90cf1853cd2e59569c982cb10970aa60a254bcc83f7",
|
||||||
|
"title"=>"用户身份确认签名",
|
||||||
|
"dataType"=>"DATA",
|
||||||
|
"algo"=>"SM3withSM2",
|
||||||
|
"description"=>"用户身份确认签名",
|
||||||
|
"expiryDate"=>"1440",
|
||||||
|
"data"=>"562+5ZCN5rWL6K+V5pWw5o2u",
|
||||||
|
"requireQrCode"=>"N",
|
||||||
|
"callBackUrl"=>"https://www.yanzai.vip/common/laravel/public/api/XTSignNotify"
|
||||||
|
];
|
||||||
|
return XTSign::XTRequest('addSignJob',$data);
|
||||||
|
|
||||||
|
}
|
||||||
|
//用户绑定协同签名id
|
||||||
|
public function bindUser(Request $request){
|
||||||
|
$userid = $request->get('userid');//中间件产生的参数
|
||||||
|
$pwd=request('pwd'); //密码
|
||||||
|
$signJobId=request('signJobId'); //签名任务 id
|
||||||
|
$cha=DB::table('xt_sign_notify')->where(['sign_job_id'=>$signJobId])->get();
|
||||||
|
if(count($cha)>0){
|
||||||
|
//解析证书信息
|
||||||
|
$data=[
|
||||||
|
"cert"=>$cha[0]->sign_cert
|
||||||
|
];
|
||||||
|
$certInfo= XTSign::XTRequest('getCertInfo',$data);
|
||||||
|
if($certInfo['status']){
|
||||||
|
$s=app()->make(LoginService::class);
|
||||||
|
$check=$s->CheckPwd(['userid'=>$userid,'password'=>$pwd]);
|
||||||
|
if($check['status']){
|
||||||
|
$u=DB::table('users')->where(['id'=>$userid])->update([
|
||||||
|
'xtsign_userid'=>$certInfo['data']['userId'],
|
||||||
|
'xtsign_username'=>$certInfo['data']['certCN']
|
||||||
|
]);
|
||||||
|
if($u){
|
||||||
|
return \Yz::Return(true,'绑定成功',[]);
|
||||||
|
}else{
|
||||||
|
return \Yz::echoError1("绑定失败");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return \Yz::echoError1("密码验证失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//检查协同签名回调状态
|
||||||
|
public function CheckNotify(){
|
||||||
|
|
||||||
|
$notifyType=request('notifyType'); //回调类型
|
||||||
|
|
||||||
|
$signJobId=request('signJobId'); //签名任务 id
|
||||||
|
$cha=DB::table('xt_sign_notify')->where(['sign_job_id'=>$signJobId])->get();
|
||||||
|
if(count($cha)>0){
|
||||||
|
//如果查到回调结果,判断回调结果,进行验签和查询证书详情获取用户信息
|
||||||
|
if($notifyType=='bind') { //绑定操作
|
||||||
|
return \Yz::Return(true,'扫码成功',[]);
|
||||||
|
}
|
||||||
|
//解析证书信息
|
||||||
|
$data=[
|
||||||
|
"cert"=>$cha[0]->sign_cert
|
||||||
|
];
|
||||||
|
$certInfo= XTSign::XTRequest('getCertInfo',$data);
|
||||||
|
if($certInfo['status']){
|
||||||
|
$query= DB::table('users')->where(['xtsign_userid'=>$certInfo['data']['userId'],'status'=>1])->get();
|
||||||
|
if(count($query)>0){
|
||||||
|
|
||||||
|
$jwt= new JWT();
|
||||||
|
$accessTimeout = $jwt -> GetGetSecretTimeOut();
|
||||||
|
$refreshTimeout = $jwt -> GetRefreshTokenTimeOut();
|
||||||
|
$access_token = $jwt->BuildJWT('yz','access',$query[0]->id,$query[0]->group,$accessTimeout);
|
||||||
|
$refresh_token = $jwt->BuildJWT('yz','refresh',$query[0]->id,'',$refreshTimeout);
|
||||||
|
if(!empty($arr['mian7'])){
|
||||||
|
$mian7_token = $jwt->BuildJWT('yz','mian7',$query[0]->id,'',$jwt -> GetMian7TokenTimeOut());
|
||||||
|
$result['mian7_token']=$mian7_token;
|
||||||
|
}
|
||||||
|
DB::table('users')->where(['id'=>$query[0]->id,'status'=>1])->update(['token'=>md5($refresh_token)]);
|
||||||
|
$result['token']=$access_token;
|
||||||
|
$result['refresh_token']=$refresh_token;
|
||||||
|
$result['status']='ok';
|
||||||
|
|
||||||
|
return \Yz::Return(true,'用户匹配成功',$result);
|
||||||
|
}else{
|
||||||
|
return \Yz::echoError1("扫码失败,未找到关联此用户的信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
// return \Yz::Return(true,'查到回调信息',$cha);
|
||||||
|
}else{
|
||||||
|
return \Yz::echoError1("暂未回调");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//协同签名回调
|
||||||
|
public function Notify(){
|
||||||
|
$signJobId=request('signJobId'); //签名任务 id
|
||||||
|
$status =request('status'); //签名任务状态
|
||||||
|
$msspId=request('msspId'); //用户唯一标识
|
||||||
|
$signResult =request('signResult'); //签名结果
|
||||||
|
$signCert =request('signCert'); //签名证书
|
||||||
|
$i=DB::table('xt_sign_notify')->insert([
|
||||||
|
'sign_job_id'=>$signJobId,
|
||||||
|
'status'=>$status,
|
||||||
|
'mssp_id'=>$msspId,
|
||||||
|
'sign_result'=>$signResult,
|
||||||
|
'sign_cert'=>$signCert
|
||||||
|
]);
|
||||||
|
if($i){
|
||||||
|
$rd=[
|
||||||
|
"status"=>200,
|
||||||
|
"message"=>"SUCCESS",
|
||||||
|
"data"=>[
|
||||||
|
"signJobId"=>$signJobId,
|
||||||
|
"status"=>$status
|
||||||
|
]
|
||||||
|
];
|
||||||
|
return $rd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Lib;
|
||||||
|
class HSM
|
||||||
|
{
|
||||||
|
protected static $baseurl="http://223.70.139.221:2018";
|
||||||
|
protected static $keyIndex=1;
|
||||||
|
protected static $encAlg="SM4/CBC/PKCS5Padding";
|
||||||
|
protected static $iv="31323334353637383132333435363738";
|
||||||
|
|
||||||
|
|
||||||
|
//加密
|
||||||
|
public static function HsmEncrypt($str){
|
||||||
|
$str = bin2hex($str);
|
||||||
|
$url= self::$baseurl."/api/hsm/sym/symEncryptInternalForKEK";
|
||||||
|
$data=[
|
||||||
|
"keyIndex"=>self::$keyIndex,
|
||||||
|
"encAlg"=>self::$encAlg,
|
||||||
|
"iv"=>self::$iv,
|
||||||
|
"plainData"=>$str
|
||||||
|
];
|
||||||
|
$data=json_encode($data);
|
||||||
|
$encryptStr=self::post($url,$data);
|
||||||
|
$r_data=json_decode($encryptStr, true);
|
||||||
|
// dd($r_data);
|
||||||
|
if($r_data['status']==0){
|
||||||
|
return ['encrypt_str'=>$r_data['body']['cipherData'],'status'=>true];
|
||||||
|
}else{
|
||||||
|
return ['status'=>false];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//解密
|
||||||
|
public static function HsmDecrypt($str){
|
||||||
|
$url= self::$baseurl."/api/hsm/sym/symDecryptInternalForKEK";
|
||||||
|
$data=[
|
||||||
|
"keyIndex"=>self::$keyIndex,
|
||||||
|
"encAlg"=>self::$encAlg,
|
||||||
|
"iv"=>self::$iv,
|
||||||
|
"cipherData"=>$str
|
||||||
|
];
|
||||||
|
$data=json_encode($data);
|
||||||
|
$encryptStr=self::post($url,$data);
|
||||||
|
$r_data=json_decode($encryptStr, true);
|
||||||
|
if($r_data['status']==0){
|
||||||
|
return ['decrypt_str'=>hex2bin($r_data['body']['plain']),'status'=>true];
|
||||||
|
}else{
|
||||||
|
return ['status'=>false];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function post($url, $data_string)
|
||||||
|
{
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($curl, CURLOPT_POST, true);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json; charset=utf-8',
|
||||||
|
'Content-Length: ' . strlen($data_string)
|
||||||
|
]);
|
||||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
|
||||||
|
$r = curl_exec($curl);
|
||||||
|
curl_close($curl);
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Lib;
|
||||||
|
class XTSign
|
||||||
|
{
|
||||||
|
const Appid="APP_7B3F36A14E99410A80B37AEF332E3247";
|
||||||
|
const Key="DLwiH46Esb8ccNTkuSSVAadNTWUfW0sc";
|
||||||
|
const BaseUrl="https://newcoss-dev.isignet.cn:10201";
|
||||||
|
const ApiList=[
|
||||||
|
'register'=>self::BaseUrl."/coss/service/v1/addUser", //注册
|
||||||
|
'getAuthCode'=>self::BaseUrl."/coss/service/v1/getAuthCode", //产生激活码
|
||||||
|
'addSignJob'=>self::BaseUrl."/coss/service/v1/addSignJob", //添加签名任务
|
||||||
|
'verifySignData'=>self::BaseUrl."/coss/service/v1/verifySignData", //验签接口 3.4.9.3
|
||||||
|
'getCertInfo'=>self::BaseUrl."/coss/service/v1/getCertInfo", //解析证书信息
|
||||||
|
];
|
||||||
|
|
||||||
|
//系统签名接口调用
|
||||||
|
public static function XTRequest($url,$data){
|
||||||
|
if(!isset(self::ApiList[$url])) return \Yz::echoError1("接口不存在");
|
||||||
|
$url= self::ApiList[$url];
|
||||||
|
$baseData=[
|
||||||
|
"version"=>"1.0",
|
||||||
|
"appId"=>self::Appid,
|
||||||
|
"signAlgo"=>"HMAC",
|
||||||
|
];
|
||||||
|
|
||||||
|
$data=array_merge($baseData, $data);
|
||||||
|
|
||||||
|
$sign=self::Sign($data);
|
||||||
|
$data= array_merge($data,['signature'=>$sign]);
|
||||||
|
// dd($data);
|
||||||
|
$data=json_encode($data);
|
||||||
|
$encryptStr=self::post($url,$data);
|
||||||
|
$r_data=json_decode($encryptStr, true);
|
||||||
|
if($r_data['status']==200){
|
||||||
|
return \Yz::Return(true,$r_data['message'],$r_data['data']);
|
||||||
|
}else{
|
||||||
|
return \Yz::echoError1($r_data['message']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//产生激活码
|
||||||
|
// public static function getAuthCode(){
|
||||||
|
// $url= self::$baseUrl."/coss/service/v1/getAuthCode";
|
||||||
|
// $data=[
|
||||||
|
// "version"=>"1.0",
|
||||||
|
// "appId"=>self::$appid,
|
||||||
|
// "signAlgo"=>"HMAC",
|
||||||
|
// "userId"=>"915b164cd8e883f7fb289e3bcf34ac68d971c7e1058f18bcb24ad33ec7a201e1",
|
||||||
|
// ];
|
||||||
|
// $sign=self::Sign($data);
|
||||||
|
// $data= array_merge($data,['signature'=>$sign]);
|
||||||
|
// // dd($data);
|
||||||
|
// $data=json_encode($data);
|
||||||
|
// $encryptStr=self::post($url,$data);
|
||||||
|
// $r_data=json_decode($encryptStr, true);
|
||||||
|
//
|
||||||
|
// return $r_data;
|
||||||
|
// }
|
||||||
|
public static function Sign($parameters){
|
||||||
|
// 定义 M 集合内的参数值
|
||||||
|
// $parameters = array(
|
||||||
|
// "key1" => "value1",
|
||||||
|
// "key2" => "value2",
|
||||||
|
// // ...
|
||||||
|
// );
|
||||||
|
|
||||||
|
// 按照参数名的 ASCII 码从小到大排序
|
||||||
|
ksort($parameters);
|
||||||
|
|
||||||
|
// 拼接参数为 URL 键值对字符串
|
||||||
|
$stringA = "";
|
||||||
|
foreach ($parameters as $key => $value) {
|
||||||
|
if ($value === "") {
|
||||||
|
// 参数值为空,进行相应的处理
|
||||||
|
// 比如跳过该参数或者抛出异常
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$stringA .= $key . "=" . $value . "&";
|
||||||
|
}
|
||||||
|
$stringA = rtrim($stringA, "&");
|
||||||
|
|
||||||
|
// HMAC 运算
|
||||||
|
$secretKey =self::Key;
|
||||||
|
$signature = base64_encode(hash_hmac("sha256", $stringA, $secretKey, true));
|
||||||
|
return $signature;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function post($url, $data_string)
|
||||||
|
{
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($curl, CURLOPT_POST, true);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json; charset=utf-8',
|
||||||
|
'Content-Length: ' . strlen($data_string)
|
||||||
|
]);
|
||||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
|
||||||
|
$r = curl_exec($curl);
|
||||||
|
curl_close($curl);
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue