新增云证书操作
This commit is contained in:
parent
dd4bbbb288
commit
f8825ecdd9
@ -4,7 +4,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/config"
|
||||
"hospital-admin-api/global"
|
||||
"strconv"
|
||||
)
|
||||
@ -34,16 +33,119 @@ func (r *UserCaCert) GetUserCloudCert(c *gin.Context) {
|
||||
}
|
||||
}()
|
||||
|
||||
if config.C.Env == "prod" {
|
||||
userCaCertService := service.UserCaCertService{}
|
||||
_, err = userCaCertService.GetUserCloudCert(tx, userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
userCaCertService := service.UserCaCertService{}
|
||||
_, err = userCaCertService.GetUserCloudCert(tx, userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// RenewUserCloudCert 更新云证书-个人-续约
|
||||
func (r *UserCaCert) RenewUserCloudCert(c *gin.Context) {
|
||||
id := c.Param("user_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
userId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
userCaCertService := service.UserCaCertService{}
|
||||
_, err = userCaCertService.RenewUserCloudCert(tx, userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// RemoveUserCloudCert 注销云证书-个人
|
||||
func (r *UserCaCert) RemoveUserCloudCert(c *gin.Context) {
|
||||
id := c.Param("user_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
userId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
userCaCertService := service.UserCaCertService{}
|
||||
_, err = userCaCertService.RemoveUserCloudCert(tx, userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// AddUserSignConfig 添加用户签章配置
|
||||
// func (r *UserCaCert) AddUserSignConfig(c *gin.Context) {
|
||||
// userCaCertRequest := requests.UserCaCertRequest{}
|
||||
// req := userCaCertRequest.AddUserSignConfig
|
||||
// if err := c.ShouldBind(&req); err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 参数验证
|
||||
// if err := global.Validate.Struct(req); err != nil {
|
||||
// responses.FailWithMessage(utils.Translate(err), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 业务处理
|
||||
// tx := global.Db.Begin()
|
||||
// defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// tx.Rollback()
|
||||
// }
|
||||
// }()
|
||||
//
|
||||
// userCaCertService := service.UserCaCertService{}
|
||||
// _, err := userCaCertService.AddUserSignConfig(tx, req)
|
||||
// if err != nil {
|
||||
// tx.Rollback()
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// tx.Commit()
|
||||
// responses.Ok(c)
|
||||
// }
|
||||
|
||||
11
api/requests/userCaCert.go
Normal file
11
api/requests/userCaCert.go
Normal file
@ -0,0 +1,11 @@
|
||||
package requests
|
||||
|
||||
type UserCaCertRequest struct {
|
||||
AddUserSignConfig // 添加用户签章配置
|
||||
}
|
||||
|
||||
// AddUserSignConfig 添加用户签章配置
|
||||
type AddUserSignConfig struct {
|
||||
Type int `json:"type" form:"type" validate:"required,oneof=1 2 3" label:"类型"` // 1:医院 2:医生 3:药师
|
||||
UserId string `json:"user_id" form:"user_id" label:"ID"` // 用户id,当type=2,3时需要
|
||||
}
|
||||
@ -547,14 +547,14 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
// 用户
|
||||
userGroup := certGroup.Group("/user")
|
||||
{
|
||||
// 更新云证书-个人
|
||||
userGroup.GET("/renew/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
// 更新云证书-个人-续约
|
||||
userGroup.PUT("/renew/:user_id", api.UserCaCert.RenewUserCloudCert)
|
||||
|
||||
// 注销云证书-个人
|
||||
userGroup.PUT("/remove/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
userGroup.PUT("/remove/:user_id", api.UserCaCert.RemoveUserCloudCert)
|
||||
|
||||
// 申请云证书-个人
|
||||
userGroup.GET("/:user_id", api.UserCaCert.GetUserCloudCert)
|
||||
userGroup.POST("/:user_id", api.UserCaCert.GetUserCloudCert)
|
||||
}
|
||||
|
||||
// 医院
|
||||
@ -574,10 +574,10 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
// 签章
|
||||
signGroup := caGroup.Group("/sign")
|
||||
{
|
||||
// 申请
|
||||
signGroup.GET("/renew/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
// 添加签章配置
|
||||
// signGroup.POST("", api.UserCaCert.AddUserSignConfig)
|
||||
|
||||
// 更新
|
||||
// 更新签章配置
|
||||
signGroup.GET("/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
@ -77,7 +76,6 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
|
||||
// 计算三天后的时间与当前时间的时间差
|
||||
timeDifference := threeDaysLater.Sub(time.Now())
|
||||
fmt.Println(timeDifference)
|
||||
|
||||
if timeDifference < 0 {
|
||||
return false, errors.New("订单已完成,无法取消")
|
||||
|
||||
@ -255,3 +255,309 @@ func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// RenewUserCloudCert 更新云证书-个人
|
||||
func (r *UserCaCertService) RenewUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
|
||||
// 检测是否存在云证书
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["type"] = 2
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
if userCaCert == nil {
|
||||
return false, errors.New("医生未申请云证书,无法操作")
|
||||
}
|
||||
|
||||
if userCaCert.IsLatest == 0 {
|
||||
return false, errors.New("医生云证书非最新,请执行更新")
|
||||
}
|
||||
|
||||
if !userCaCert.CertExpireTime.IsEmpty() {
|
||||
timeDifference := time.Time(userCaCert.CertExpireTime).Sub(time.Now())
|
||||
|
||||
if timeDifference > 60*24*time.Hour {
|
||||
return false, errors.New("云证书有效期大于60天,无法更新")
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
return false, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
// 医生
|
||||
if user.UserType == 2 {
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorByUserId(userId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return false, errors.New("医生数据错误")
|
||||
}
|
||||
|
||||
// 获取医生详情数据
|
||||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(userDoctor.DoctorId)
|
||||
if err != nil || userDoctorInfo == nil {
|
||||
return false, errors.New("医生详情数据错误")
|
||||
}
|
||||
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
return false, errors.New("请先通过身份认证")
|
||||
}
|
||||
|
||||
if userDoctor.MultiPointStatus != 1 {
|
||||
return false, errors.New("请先完成多点执业认证")
|
||||
}
|
||||
}
|
||||
|
||||
// 修改云证书
|
||||
cloudCertRequestData := &ca.RenewCloudCertRequest{
|
||||
EntityId: fmt.Sprintf("%d", userId),
|
||||
Pin: fmt.Sprintf("%d", userId),
|
||||
AuthType: "实人认证",
|
||||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
AuthResult: "认证通过",
|
||||
AuthNoticeType: "数字证书更新告知",
|
||||
}
|
||||
|
||||
cloudCertResponse, err := ca.RenewCloudCert(cloudCertRequestData)
|
||||
if err != nil || cloudCertResponse == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 修改ca监管证书表
|
||||
data := make(map[string]interface{})
|
||||
data["cert_base64"] = cloudCertResponse.CertBase64
|
||||
data["cert_chain_p7"] = cloudCertResponse.CertP7
|
||||
data["cert_serial_number"] = cloudCertResponse.CertSerialnumber
|
||||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("审核失败")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// RemoveUserCloudCert 注销云证书-个人
|
||||
func (r *UserCaCertService) RemoveUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
|
||||
// 检测是否存在云证书
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["type"] = 2
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
if userCaCert == nil {
|
||||
return false, errors.New("用户未申请云证书,无法操作")
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
return false, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
// 医生
|
||||
if user.UserType == 2 {
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorByUserId(userId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return false, errors.New("医生数据错误")
|
||||
}
|
||||
|
||||
// 获取医生详情数据
|
||||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(userDoctor.DoctorId)
|
||||
if err != nil || userDoctorInfo == nil {
|
||||
return false, errors.New("医生详情数据错误")
|
||||
}
|
||||
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
return false, errors.New("请先通过身份认证")
|
||||
}
|
||||
|
||||
if userDoctor.MultiPointStatus != 1 {
|
||||
return false, errors.New("请先完成多点执业认证")
|
||||
}
|
||||
}
|
||||
|
||||
// 注销云证书
|
||||
cloudCertRequestData := &ca.RemoveCloudCertRequest{
|
||||
EntityId: fmt.Sprintf("%d", userId),
|
||||
Pin: fmt.Sprintf("%d", userId),
|
||||
AuthType: "实人认证",
|
||||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
AuthResult: "认证通过",
|
||||
AuthNoticeType: "数字证书吊销告知",
|
||||
}
|
||||
|
||||
_, err = ca.RemoveCloudCert(cloudCertRequestData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 修改ca监管证书表-注销
|
||||
err = userCaCertDao.DeleteUserCaCertById(tx, userCaCert.CertId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("注销失败")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AddUserSignConfig 添加用户签章配置
|
||||
// func (r *UserCaCertService) AddUserSignConfig(tx *gorm.DB, req requests.AddUserSignConfig) (bool, error) {
|
||||
// userCaCertDao := dao.UserCaCert{}
|
||||
//
|
||||
// var entityId string // 唯一标识
|
||||
// var cardNum string // 身份证号/信用代码
|
||||
//
|
||||
// // 医院-固定
|
||||
// if req.Type == 1 {
|
||||
// entityId = "5345345461"
|
||||
// cardNum = "91510106MABTJY4K9R"
|
||||
// }
|
||||
//
|
||||
// // 医生
|
||||
// if req.Type == 2 {
|
||||
// if req.UserId == "" {
|
||||
// return false, errors.New("缺少用户标识")
|
||||
// }
|
||||
//
|
||||
// entityId = req.UserId
|
||||
//
|
||||
// // 将 id 转换为 int64 类型
|
||||
// userId, err := strconv.ParseInt(req.UserId, 10, 64)
|
||||
// if err != nil {
|
||||
// return false, errors.New("用户标识错误")
|
||||
// }
|
||||
//
|
||||
// // 获取医生数据
|
||||
// userDoctorDao := dao.UserDoctorDao{}
|
||||
// userDoctor, err := userDoctorDao.GetUserDoctorByUserId(userId)
|
||||
// if err != nil || userDoctor == nil {
|
||||
// return false, errors.New("医生数据错误")
|
||||
// }
|
||||
//
|
||||
// // 获取医生详情数据
|
||||
// userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
// userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(userDoctor.DoctorId)
|
||||
// if err != nil || userDoctorInfo == nil {
|
||||
// return false, errors.New("医生详情数据错误")
|
||||
// }
|
||||
//
|
||||
// if userDoctor.IdenAuthStatus != 1 {
|
||||
// return false, errors.New("请先通过身份认证")
|
||||
// }
|
||||
//
|
||||
// if userDoctor.MultiPointStatus != 1 {
|
||||
// return false, errors.New("请先完成多点执业认证")
|
||||
// }
|
||||
//
|
||||
// cardNum = userDoctorInfo.CardNum
|
||||
// }
|
||||
//
|
||||
// // 药师
|
||||
// if req.Type == 3 {
|
||||
// if req.UserId == "" {
|
||||
// return false, errors.New("缺少用户标识")
|
||||
// }
|
||||
//
|
||||
// entityId = req.UserId
|
||||
//
|
||||
// // 将 id 转换为 int64 类型
|
||||
// userId, err := strconv.ParseInt(req.UserId, 10, 64)
|
||||
// if err != nil {
|
||||
// return false, errors.New("用户标识错误")
|
||||
// }
|
||||
//
|
||||
// // 获取药师详情数据
|
||||
// userPharmacistInfoDao := dao.UserPharmacistInfoDao{}
|
||||
// userPharmacistInfo, err := userPharmacistInfoDao.GetUserPharmacistInfoByUserId(userId)
|
||||
// if err != nil || userPharmacistInfo == nil {
|
||||
// return false, errors.New("药师详情数据错误")
|
||||
// }
|
||||
//
|
||||
// cardNum = userPharmacistInfo.CardNum
|
||||
// }
|
||||
//
|
||||
// // 检测是否存在云证书
|
||||
// maps := make(map[string]interface{})
|
||||
// maps["ca_pin"] = entityId
|
||||
// maps["type"] = 2
|
||||
// userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
// if userCaCert == nil {
|
||||
// return false, errors.New("医生未申请云证书,请申请后添加签章配置")
|
||||
// }
|
||||
//
|
||||
// // 处理签章图片
|
||||
// var signImage string // 签章图片,base64格式
|
||||
//
|
||||
// // 处理签章配置
|
||||
// var signParam string // 签章配置,JSON
|
||||
// fmt.Println(signParam)
|
||||
// var signParams []map[string]interface{}
|
||||
// if req.Type == 1 {
|
||||
// // 医院
|
||||
// signParam := map[string]interface{}{
|
||||
// "llx": "370",
|
||||
// "lly": "210",
|
||||
// "urx": "520",
|
||||
// "ury": "360",
|
||||
// "pageList": []int{1},
|
||||
// "sealImg": signImage, // 请替换为你的签名图像路径
|
||||
// }
|
||||
// signParams = append(signParams, signParam)
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // 申请云证书
|
||||
// cloudCertRequestData := &ca.AddUserSignConfigRequest{
|
||||
// UserId: entityId,
|
||||
// ConfigKey: entityId,
|
||||
// KeypairType: "3",
|
||||
// CertSn: cardNum,
|
||||
// SignType: "4",
|
||||
// SignParam: "",
|
||||
// SealImg: "",
|
||||
// SealType: "4",
|
||||
// SignTemplate: "0",
|
||||
// }
|
||||
//
|
||||
// cloudCertResponse, err := ca.AddCloudCert(cloudCertRequestData)
|
||||
// if err != nil || cloudCertResponse == nil {
|
||||
// return false, errors.New(err.Error())
|
||||
// }
|
||||
//
|
||||
// // 新增ca监管证书表
|
||||
// userCaCert = &model.UserCaCert{
|
||||
// UserId: &userId,
|
||||
// IsSystem: 0,
|
||||
// IsLatest: 1,
|
||||
// Type: 2,
|
||||
// CertBase64: cloudCertResponse.CertBase64,
|
||||
// CertChainP7: cloudCertResponse.CertP7,
|
||||
// CertSerialNumber: cloudCertResponse.CertSerialnumber,
|
||||
// CaPin: fmt.Sprintf("%d", userId),
|
||||
// IsSignConfig: 0,
|
||||
// SignConfig: "",
|
||||
// CertApplicationTime: model.LocalTime(time.Now()),
|
||||
// CertExpireTime: model.LocalTime(time.Now().AddDate(0, 0, 180)), // 180天以后的时间
|
||||
// }
|
||||
//
|
||||
// userCaCert, err = userCaCertDao.AddUserCaCert(tx, userCaCert)
|
||||
// if err != nil || userCaCert == nil {
|
||||
// return false, errors.New(err.Error())
|
||||
// }
|
||||
//
|
||||
// return true, nil
|
||||
// }
|
||||
|
||||
@ -23,19 +23,6 @@ type GetOssSignResponse struct {
|
||||
|
||||
// GetOssSign 获取oss签名
|
||||
func GetOssSign(dir string) (*GetOssSignResponse, error) {
|
||||
// Endpoint := config.C.Oss.OssEndpoint
|
||||
// accessKey := config.C.Oss.OssAccessKey
|
||||
// accessSecret := config.C.Oss.OssAccessKeySecret
|
||||
// client, err := oss.New(Endpoint, accessKey, accessSecret)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// bucket, err := client.Bucket(viper.GetString("aliyun.Bucket"))
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
|
||||
now := time.Now()
|
||||
expire := 30 // 设置该policy超时时间是30s,即这个policy过了这个有效时间,将不能访问。
|
||||
end := now.Add(time.Second * time.Duration(expire))
|
||||
|
||||
83
extend/ca/CaOnlineRequest.go
Normal file
83
extend/ca/CaOnlineRequest.go
Normal file
@ -0,0 +1,83 @@
|
||||
package ca
|
||||
|
||||
// EditCloudCertRequestData 修改云证书请求数据
|
||||
type EditCloudCertRequestData struct {
|
||||
EntityId string `json:"entityId"` // 用户唯一标识,由业务系统定义
|
||||
EntityType string `json:"entityType"` // 用户类型,可选值[Personal/Organizational]
|
||||
PersonalPhone string `json:"personalPhone"` // 联系人电话
|
||||
PersonalName string `json:"personalName"` // 个人姓名,类型为Personal时必填
|
||||
PersonalIdNumber string `json:"personalIdNumber"` // 个人证件号,类型为Personal时必填
|
||||
OrgName string `json:"orgName"` // 组织机构名称,信用代码类型为Organizational时必填
|
||||
OrgNumber string `json:"orgNumber"` // 组织机构代码,信用代码类型为Organizational时必填
|
||||
Pin string `json:"pin"` // 证书PIN码
|
||||
OrgDept string `json:"orgDept"` // 卫生证书:医院部门
|
||||
Province string `json:"province"` // 卫生证书:省、州
|
||||
Locality string `json:"locality"` // 卫生证书:城市
|
||||
AuthType string `json:"authType"` // 委托鉴证方式[实人认证、线下认证、其它方式认证]
|
||||
AuthTime string `json:"authTime"` // 委托鉴证时间(鉴证完成的时间戳)单位:秒
|
||||
AuthResult string `json:"authResult"` // 委托鉴证结果[认证通过]
|
||||
AuthNoticeType string `json:"authNoticeType"` // 委托鉴证告知类型[数字证书申请告知]
|
||||
}
|
||||
|
||||
// AddCloudCertRequest 新增云证书请求数据
|
||||
type AddCloudCertRequest struct {
|
||||
EntityId string `json:"entityId"` // 用户唯一标识,由业务系统定义
|
||||
EntityType string `json:"entityType"` // 用户类型,可选值[Personal/Organizational]
|
||||
PersonalPhone string `json:"personalPhone"` // 联系人电话
|
||||
PersonalName string `json:"personalName"` // 个人姓名,类型为Personal时必填
|
||||
PersonalIdNumber string `json:"personalIdNumber"` // 个人证件号,类型为Personal时必填
|
||||
OrgName string `json:"orgName"` // 组织机构名称,信用代码类型为Organizational时必填
|
||||
OrgNumber string `json:"orgNumber"` // 组织机构代码,信用代码类型为Organizational时必填
|
||||
Pin string `json:"pin"` // 证书PIN码
|
||||
OrgDept string `json:"orgDept"` // 卫生证书:医院部门
|
||||
Province string `json:"province"` // 卫生证书:省、州
|
||||
Locality string `json:"locality"` // 卫生证书:城市
|
||||
AuthType string `json:"authType"` // 委托鉴证方式[实人认证、线下认证、其它方式认证]
|
||||
AuthTime string `json:"authTime"` // 委托鉴证时间(鉴证完成的时间戳)单位:秒
|
||||
AuthResult string `json:"authResult"` // 委托鉴证结果[认证通过]
|
||||
AuthNoticeType string `json:"authNoticeType"` // 委托鉴证告知类型[数字证书申请告知]
|
||||
}
|
||||
|
||||
// GetUserSignConfigRequestData 获取用户签章图片
|
||||
type GetUserSignConfigRequestData struct {
|
||||
UserId string `json:"userId"` // 用户标识信息
|
||||
}
|
||||
|
||||
// DeleteUserSignConfigRequestData 删除签章配置
|
||||
type DeleteUserSignConfigRequestData struct {
|
||||
UserId string `json:"userId"` // 用户标识信息
|
||||
ConfigKey string `json:"configKey"` // 签章配置唯一标识
|
||||
}
|
||||
|
||||
// RenewCloudCertRequest 更新云证书请求数据
|
||||
type RenewCloudCertRequest struct {
|
||||
EntityId string `json:"entityId"` // 用户唯一标识,由业务系统定义
|
||||
Pin string `json:"pin"` // 证书PIN码
|
||||
AuthType string `json:"authType"` // 委托鉴证方式[实人认证、线下认证、其它方式认证]
|
||||
AuthTime string `json:"authTime"` // 委托鉴证时间(鉴证完成的时间戳)单位:秒
|
||||
AuthResult string `json:"authResult"` // 委托鉴证结果[认证通过]
|
||||
AuthNoticeType string `json:"authNoticeType"` // 委托鉴证告知类型[数字证书申请告知]
|
||||
}
|
||||
|
||||
// RemoveCloudCertRequest 更新云证书请求数据
|
||||
type RemoveCloudCertRequest struct {
|
||||
EntityId string `json:"entityId"` // 用户唯一标识,由业务系统定义
|
||||
Pin string `json:"pin"` // 证书PIN码
|
||||
AuthType string `json:"authType"` // 委托鉴证方式[实人认证、线下认证、其它方式认证]
|
||||
AuthTime string `json:"authTime"` // 委托鉴证时间(鉴证完成的时间戳)单位:秒
|
||||
AuthResult string `json:"authResult"` // 委托鉴证结果[认证通过]
|
||||
AuthNoticeType string `json:"authNoticeType"` // 委托鉴证告知类型[数字证书申请告知]
|
||||
}
|
||||
|
||||
// AddUserSignConfigRequest 添加用户签章配置
|
||||
type AddUserSignConfigRequest struct {
|
||||
UserId string `json:"userId"` // 用户标识信息(为云证书entityId)
|
||||
ConfigKey string `json:"configKey"` // 签章配置唯一标识,一张云证书配置一个
|
||||
KeypairType string `json:"keypairType"` // 秘钥类型(3云证书)
|
||||
CertSn string `json:"certSn"` // 证书序列号,使用医生身份证号即可
|
||||
SignType string `json:"signType"` // 签章方式(签章类型; 4客户端坐标签章;5客户端关键字签章;)
|
||||
SignParam string `json:"authNoticeType"` // 签章配置,JSON
|
||||
SealImg string `json:"sealImg"` // 签章图片,base64格式
|
||||
SealType string `json:"sealType"`
|
||||
SignTemplate string `json:"signTemplate"`
|
||||
}
|
||||
30
extend/ca/CaOnlineResponse.go
Normal file
30
extend/ca/CaOnlineResponse.go
Normal file
@ -0,0 +1,30 @@
|
||||
package ca
|
||||
|
||||
// EditCloudCertResponse 修改云证书返回数据
|
||||
type EditCloudCertResponse struct {
|
||||
CertBase64 string `json:"certBase64"` // 签名值证书
|
||||
CertP7 string `json:"certP7"` // 证书链
|
||||
CertSerialnumber string `json:"certSerialnumber"` // 证书序列号
|
||||
}
|
||||
|
||||
// AddCloudCertResponse 申请云证书返回数据
|
||||
type AddCloudCertResponse struct {
|
||||
CertBase64 string `json:"certBase64"` // 签名值证书
|
||||
CertP7 string `json:"certP7"` // 证书链
|
||||
CertSerialnumber string `json:"certSerialnumber"` // 证书序列号
|
||||
}
|
||||
|
||||
// GetUserSignConfigResponse 获取用户签章图片返回数据
|
||||
type GetUserSignConfigResponse struct {
|
||||
SealImg string `json:"sealImg"` // 印章图片
|
||||
SealType int `json:"sealType"` // 印章类型(1公章;2财务章;3个人章;4合同印章;5其他)
|
||||
AppId string `json:"appId"` // 应用appid
|
||||
Id string `json:"id"` // 印章唯一标识
|
||||
}
|
||||
|
||||
// RenewCloudCertResponse 更新云证书返回数据
|
||||
type RenewCloudCertResponse struct {
|
||||
CertBase64 string `json:"certBase64"` // 签名值证书
|
||||
CertP7 string `json:"certP7"` // 证书链
|
||||
CertSerialnumber string `json:"certSerialnumber"` // 证书序列号
|
||||
}
|
||||
@ -6,77 +6,6 @@ import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// EditCloudCertRequestData 修改云证书请求数据
|
||||
type EditCloudCertRequestData struct {
|
||||
EntityId string `json:"entityId"` // 用户唯一标识,由业务系统定义
|
||||
EntityType string `json:"entityType"` // 用户类型,可选值[Personal/Organizational]
|
||||
PersonalPhone string `json:"personalPhone"` // 联系人电话
|
||||
PersonalName string `json:"personalName"` // 个人姓名,类型为Personal时必填
|
||||
PersonalIdNumber string `json:"personalIdNumber"` // 个人证件号,类型为Personal时必填
|
||||
OrgName string `json:"orgName"` // 组织机构名称,信用代码类型为Organizational时必填
|
||||
OrgNumber string `json:"orgNumber"` // 组织机构代码,信用代码类型为Organizational时必填
|
||||
Pin string `json:"pin"` // 证书PIN码
|
||||
OrgDept string `json:"orgDept"` // 卫生证书:医院部门
|
||||
Province string `json:"province"` // 卫生证书:省、州
|
||||
Locality string `json:"locality"` // 卫生证书:城市
|
||||
AuthType string `json:"authType"` // 委托鉴证方式[实人认证、线下认证、其它方式认证]
|
||||
AuthTime string `json:"authTime"` // 委托鉴证时间(鉴证完成的时间戳)单位:秒
|
||||
AuthResult string `json:"authResult"` // 委托鉴证结果[认证通过]
|
||||
AuthNoticeType string `json:"authNoticeType"` // 委托鉴证告知类型[数字证书申请告知]
|
||||
}
|
||||
|
||||
// AddCloudCertRequest 新增云证书请求数据
|
||||
type AddCloudCertRequest struct {
|
||||
EntityId string `json:"entityId"` // 用户唯一标识,由业务系统定义
|
||||
EntityType string `json:"entityType"` // 用户类型,可选值[Personal/Organizational]
|
||||
PersonalPhone string `json:"personalPhone"` // 联系人电话
|
||||
PersonalName string `json:"personalName"` // 个人姓名,类型为Personal时必填
|
||||
PersonalIdNumber string `json:"personalIdNumber"` // 个人证件号,类型为Personal时必填
|
||||
OrgName string `json:"orgName"` // 组织机构名称,信用代码类型为Organizational时必填
|
||||
OrgNumber string `json:"orgNumber"` // 组织机构代码,信用代码类型为Organizational时必填
|
||||
Pin string `json:"pin"` // 证书PIN码
|
||||
OrgDept string `json:"orgDept"` // 卫生证书:医院部门
|
||||
Province string `json:"province"` // 卫生证书:省、州
|
||||
Locality string `json:"locality"` // 卫生证书:城市
|
||||
AuthType string `json:"authType"` // 委托鉴证方式[实人认证、线下认证、其它方式认证]
|
||||
AuthTime string `json:"authTime"` // 委托鉴证时间(鉴证完成的时间戳)单位:秒
|
||||
AuthResult string `json:"authResult"` // 委托鉴证结果[认证通过]
|
||||
AuthNoticeType string `json:"authNoticeType"` // 委托鉴证告知类型[数字证书申请告知]
|
||||
}
|
||||
|
||||
// GetUserSignConfigRequestData 获取用户签章图片
|
||||
type GetUserSignConfigRequestData struct {
|
||||
UserId string `json:"userId"` // 用户标识信息
|
||||
}
|
||||
|
||||
// DeleteUserSignConfigRequestData 删除签章配置
|
||||
type DeleteUserSignConfigRequestData struct {
|
||||
UserId string `json:"userId"` // 用户标识信息
|
||||
ConfigKey string `json:"configKey"` // 签章配置唯一标识
|
||||
}
|
||||
|
||||
// EditCloudCertResponse 修改云证书返回数据
|
||||
type EditCloudCertResponse struct {
|
||||
CertBase64 string `json:"certBase64"` // 签名值证书
|
||||
CertP7 string `json:"certP7"` // 证书链
|
||||
CertSerialnumber string `json:"certSerialnumber"` // 证书序列号
|
||||
}
|
||||
|
||||
// AddCloudCertResponse 申请云证书返回数据
|
||||
type AddCloudCertResponse struct {
|
||||
CertBase64 string `json:"certBase64"` // 签名值证书
|
||||
CertP7 string `json:"certP7"` // 证书链
|
||||
CertSerialnumber string `json:"certSerialnumber"` // 证书序列号
|
||||
}
|
||||
|
||||
// GetUserSignConfigResponse 获取用户签章图片返回数据
|
||||
type GetUserSignConfigResponse struct {
|
||||
SealImg string `json:"sealImg"` // 印章图片
|
||||
SealType int `json:"sealType"` // 印章类型(1公章;2财务章;3个人章;4合同印章;5其他)
|
||||
AppId string `json:"appId"` // 应用appid
|
||||
Id string `json:"id"` // 印章唯一标识
|
||||
}
|
||||
|
||||
// EditCloudCert 修改云证书
|
||||
func EditCloudCert(d *EditCloudCertRequestData) (*EditCloudCertResponse, error) {
|
||||
if d == nil {
|
||||
@ -325,3 +254,137 @@ func DeleteUserSignConfig(d *DeleteUserSignConfigRequestData) (bool, error) {
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// RenewCloudCert 更新云证书
|
||||
func RenewCloudCert(d *RenewCloudCertRequest) (*RenewCloudCertResponse, error) {
|
||||
if d == nil {
|
||||
return nil, errors.New("获取云证书失败")
|
||||
}
|
||||
|
||||
// 获取签名
|
||||
requestDataMap := make(map[string]interface{})
|
||||
requestDataMap["entityId"] = d.EntityId
|
||||
requestDataMap["pin"] = d.Pin
|
||||
requestDataMap["authType"] = d.AuthType
|
||||
requestDataMap["authTime"] = d.AuthTime
|
||||
requestDataMap["authResult"] = d.AuthResult
|
||||
requestDataMap["authNoticeType"] = d.AuthNoticeType
|
||||
signature := GenerateSignature(requestDataMap)
|
||||
if signature == "" {
|
||||
return nil, errors.New("云证书签名错误")
|
||||
}
|
||||
|
||||
formData := url.Values{}
|
||||
formData.Set("entityId", d.EntityId)
|
||||
formData.Set("pin", d.Pin)
|
||||
formData.Set("authType", d.AuthType)
|
||||
formData.Set("authTime", d.AuthTime)
|
||||
formData.Set("authResult", d.AuthResult)
|
||||
formData.Set("authNoticeType", d.AuthNoticeType)
|
||||
|
||||
// 构建请求 URL
|
||||
requestUrl := config.C.CaOnline.CaOnlineApiUrl + "/cloud-certificate-service/api/cloudCert/open/v2/cert/certRenew"
|
||||
|
||||
response, err := postRequest(requestUrl, formData, signature)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
certBase64, ok := response["certBase64"]
|
||||
if !ok {
|
||||
return nil, errors.New("返回数据错误")
|
||||
}
|
||||
|
||||
certP7, ok := response["certP7"]
|
||||
if !ok {
|
||||
return nil, errors.New("返回数据错误")
|
||||
}
|
||||
|
||||
certSerialnumber, ok := response["certSerialnumber"]
|
||||
if !ok {
|
||||
return nil, errors.New("返回数据错误")
|
||||
}
|
||||
|
||||
result := &RenewCloudCertResponse{
|
||||
CertBase64: certBase64.(string),
|
||||
CertP7: certP7.(string),
|
||||
CertSerialnumber: certSerialnumber.(string),
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RemoveCloudCert 注销云证书
|
||||
func RemoveCloudCert(d *RemoveCloudCertRequest) (bool, error) {
|
||||
if d == nil {
|
||||
return false, errors.New("获取云证书失败")
|
||||
}
|
||||
|
||||
// 获取签名
|
||||
requestDataMap := make(map[string]interface{})
|
||||
requestDataMap["entityId"] = d.EntityId
|
||||
requestDataMap["pin"] = d.Pin
|
||||
requestDataMap["authType"] = d.AuthType
|
||||
requestDataMap["authTime"] = d.AuthTime
|
||||
requestDataMap["authResult"] = d.AuthResult
|
||||
requestDataMap["authNoticeType"] = d.AuthNoticeType
|
||||
signature := GenerateSignature(requestDataMap)
|
||||
if signature == "" {
|
||||
return false, errors.New("云证书签名错误")
|
||||
}
|
||||
|
||||
formData := url.Values{}
|
||||
formData.Set("entityId", d.EntityId)
|
||||
formData.Set("pin", d.Pin)
|
||||
formData.Set("authType", d.AuthType)
|
||||
formData.Set("authTime", d.AuthTime)
|
||||
formData.Set("authResult", d.AuthResult)
|
||||
formData.Set("authNoticeType", d.AuthNoticeType)
|
||||
|
||||
// 构建请求 URL
|
||||
requestUrl := config.C.CaOnline.CaOnlineApiUrl + "/cloud-certificate-service/api/cloudCert/open/v2/cert/certRevoke"
|
||||
|
||||
_, err := postRequest(requestUrl, formData, signature)
|
||||
if err != nil {
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AddUserSignConfig 添加用户签章配置
|
||||
func AddUserSignConfig(d *AddUserSignConfigRequest) (bool, error) {
|
||||
if d == nil {
|
||||
return false, errors.New("获取云证书失败")
|
||||
}
|
||||
|
||||
// 获取签名
|
||||
requestDataMap := make(map[string]interface{})
|
||||
requestDataMap["entityId"] = d.EntityId
|
||||
requestDataMap["pin"] = d.Pin
|
||||
requestDataMap["authType"] = d.AuthType
|
||||
requestDataMap["authTime"] = d.AuthTime
|
||||
requestDataMap["authResult"] = d.AuthResult
|
||||
requestDataMap["authNoticeType"] = d.AuthNoticeType
|
||||
signature := GenerateSignature(requestDataMap)
|
||||
if signature == "" {
|
||||
return false, errors.New("云证书签名错误")
|
||||
}
|
||||
|
||||
formData := url.Values{}
|
||||
formData.Set("entityId", d.EntityId)
|
||||
formData.Set("pin", d.Pin)
|
||||
formData.Set("authType", d.AuthType)
|
||||
formData.Set("authTime", d.AuthTime)
|
||||
formData.Set("authResult", d.AuthResult)
|
||||
formData.Set("authNoticeType", d.AuthNoticeType)
|
||||
|
||||
// 构建请求 URL
|
||||
requestUrl := config.C.CaOnline.CaOnlineApiUrl + "/cloud-certificate-service/api/cloudCert/open/v2/cert/certRevoke"
|
||||
|
||||
_, err := postRequest(requestUrl, formData, signature)
|
||||
if err != nil {
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user