新增添加用户签章配置
This commit is contained in:
@@ -5,7 +5,11 @@ import (
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
"hospital-admin-api/config"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -54,3 +58,108 @@ func GetOssSign(dir string) (*GetOssSignResponse, error) {
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// CreateClient 创建客户端
|
||||
func CreateClient() (*oss.Client, error) {
|
||||
// 创建OSSClient实例。
|
||||
client, err := oss.New(config.C.Oss.OssEndpoint, config.C.Oss.OssAccessKey, config.C.Oss.OssAccessKeySecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// GetCusTomObjectToRAM 下载自定义风格文件到内存
|
||||
func GetCusTomObjectToRAM(filename string, style string) (string, error) {
|
||||
if style == "" {
|
||||
style = "image/resize"
|
||||
}
|
||||
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 下载文件到流。
|
||||
body, err := bucket.GetObject(filename, oss.Process(style))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
defer func(body io.ReadCloser) {
|
||||
_ = body.Close()
|
||||
}(body)
|
||||
|
||||
data, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// GetObjectToRAM 下载文件到内存
|
||||
func GetObjectToRAM(filename string) (string, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 下载文件到流。
|
||||
body, err := bucket.GetObject(filename)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
defer func(body io.ReadCloser) {
|
||||
_ = body.Close()
|
||||
}(body)
|
||||
|
||||
data, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// GetObjectToLocal 下载文件到本地
|
||||
func GetObjectToLocal(filename, local string) (bool, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 下载文件到本地文件,并保存到指定的本地路径中。如果指定的本地文件存在会覆盖,不存在则新建。
|
||||
// 如果未指定本地路径,则下载后的文件默认保存到示例程序所属项目对应本地路径中。
|
||||
// 依次填写Object完整路径(例如exampledir/exampleobject.txt)和本地文件的完整路径(例如D:\\localpath\\examplefile.txt)。Object完整路径中不能包含Bucket名称。
|
||||
err = bucket.GetObjectToFile(filename, local)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ type RemoveCloudCertRequest struct {
|
||||
|
||||
// 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格式
|
||||
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:"signParam"` // 签章配置,JSON
|
||||
SealImg string `json:"sealImg"` // 签章图片,base64格式
|
||||
SealType string `json:"sealType"`
|
||||
SignTemplate string `json:"signTemplate"`
|
||||
}
|
||||
|
||||
+42
-36
@@ -352,39 +352,45 @@ func RemoveCloudCert(d *RemoveCloudCertRequest) (bool, error) {
|
||||
}
|
||||
|
||||
// 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
|
||||
// }
|
||||
func AddUserSignConfig(d *AddUserSignConfigRequest) (bool, error) {
|
||||
if d == nil {
|
||||
return false, errors.New("获取云证书失败")
|
||||
}
|
||||
|
||||
// 获取签名
|
||||
requestDataMap := make(map[string]interface{})
|
||||
requestDataMap["userId"] = d.UserId
|
||||
requestDataMap["configKey"] = d.UserId
|
||||
requestDataMap["keypairType"] = "3"
|
||||
requestDataMap["certSn"] = d.CertSn
|
||||
requestDataMap["signType"] = "4"
|
||||
requestDataMap["signParam"] = d.SignParam
|
||||
requestDataMap["sealImg"] = d.SealImg
|
||||
requestDataMap["sealType"] = "4"
|
||||
requestDataMap["signTemplate"] = "0"
|
||||
signature := GenerateSignature(requestDataMap)
|
||||
if signature == "" {
|
||||
return false, errors.New("云证书签名错误")
|
||||
}
|
||||
|
||||
formData := url.Values{}
|
||||
formData.Set("userId", d.UserId)
|
||||
formData.Set("configKey", d.UserId)
|
||||
formData.Set("keypairType", "3")
|
||||
formData.Set("certSn", d.CertSn)
|
||||
formData.Set("signType", "4")
|
||||
formData.Set("signParam", d.SignParam)
|
||||
formData.Set("sealImg", d.SealImg)
|
||||
formData.Set("sealType", "4")
|
||||
formData.Set("signTemplate", "0")
|
||||
|
||||
// 构建请求 URL
|
||||
requestUrl := config.C.CaOnline.CaOnlineApiUrl + "/signature-server/api/open/signature/userSignConfig"
|
||||
|
||||
_, err := postRequest(requestUrl, formData, signature)
|
||||
if err != nil {
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user