新的应用平台采用国密SM4算法进行加解密
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
6.8 KiB

1 year ago
package common
import (
"appNewPlatform/generalmethod"
"appNewPlatform/utils"
"appNewPlatform/utils/formatoutput"
1 year ago
"fmt"
"image"
"image/draw"
"image/jpeg"
"image/png"
"os"
1 year ago
1 year ago
svg "github.com/ajstarks/svgo"
1 year ago
"github.com/gin-gonic/gin"
)
/*
*
@ 作者: 秦东
@ 时间: 2024-10-03 13:57:49
@ 功能: 实验函数
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) Index(c *gin.Context) {
sendMap := generalmethod.MapOut[string]()
token, _ := utils.ReleaseToken("300450")
sendMap["token"] = token
sendMap["tokenStr"], sendMap["claims"], sendMap["err"] = utils.ParseToken(token)
formatoutput.Result(0, sendMap, c)
}
func (a *ApiMethod) JieXiJwt(c *gin.Context) {
strinf := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiIzMDA0NTAiLCJVVUlEIjoiMzUwNTc2MDg1NzI2OTI4ODk2IiwiZXhwIjoxNzQwMDE1ODUyLCJpYXQiOjE3Mzk0MTEwNTIsImlzcyI6ImFkbWluIiwic3ViIjoiQXBwSnd0VG9rZW4ifQ.UZQSs6ScQ5lskaPgCs7eB1B9AW9G8O9iHmDTQYKssFY"
aa, b, d := utils.ParseToken(strinf)
sendMap := make(map[string]interface{})
sendMap["token"] = aa
sendMap["cla"] = b
sendMap["err"] = d
formatoutput.Result(0, sendMap, c)
1 year ago
}
1 year ago
/*
*{"conversationId":"3d24a4a6-fa93-4770-8dd6-69fa3545afbd","source":"instruct"}
1 year ago
@ 作者: 秦东
@ 时间: 2024-11-08 15:20:28
@ 功能: 实验图片改变格式
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) JpgToSvg(c *gin.Context) {
}
/*
*
@ 作者: 秦东
@ 时间: 2024-11-08 15:21:29
@ 功能: 将图像转换为SVG
@ 参数
#inputImagePath 来源
#outputSVGPath 目标
@ 返回值
#
@ 方法原型
#
*/
func ImageToSVG(inputImagePath, outputSVGPath string) error {
// 打开输入图像文件
inputFile, err := os.Open(inputImagePath)
if err != nil {
return fmt.Errorf("无法打开输入图像文件: %v", err)
}
defer inputFile.Close()
// 解码图像
var img image.Image
var config image.Config
if inputImagePath[len(inputImagePath)-3:] == "png" {
img, err = png.Decode(inputFile)
} else if inputImagePath[len(inputImagePath)-3:] == "jpg" {
img, err = jpeg.Decode(inputFile)
} else {
return fmt.Errorf("不支持的图像格式")
}
if err != nil {
return fmt.Errorf("无法解码图像: %v", err)
}
// 创建一个空白的RGBA图像,大小与原始图像相同
rgba := image.NewRGBA(image.Rect(0, 0, config.Width, config.Height))
draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, draw.Src)
// 创建SVG文件
outputFile, err := os.Create(outputSVGPath)
if err != nil {
return fmt.Errorf("无法创建SVG文件: %v", err)
}
defer outputFile.Close()
// 初始化SVG绘制上下文
svg := svg.New(outputFile)
svg.Start(config.Width, config.Height)
// 遍历图像的每个像素,将其绘制到SVG中
for y := 0; y < config.Height; y++ {
for x := 0; x < config.Width; x++ {
r, g, b, a := rgba.At(x, y).RGBA()
svg.Rect(x, y, 1, 1, fmt.Sprintf("fill:rgba(%d,%d,%d,%f)", r>>8, g>>8, b>>8, float64(a)/65535))
}
}
svg.End()
return nil
}
/*
*
@ 作者: 秦东
@ 时间: 2024-11-08 16:24:10
@ 功能:
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
// func ImgToSvg(inputImagePath, outputSVGPath string) {
// // 打开输入的 PNG 图像文件
// inputFile, err := os.Open("input.png")
// if err != nil {
// log.Fatalf("无法打开输入图像文件: %v", err)
// }
// defer inputFile.Close()
// // 解码 PNG 图像
// img, err := png.Decode(inputFile)
// if err != nil {
// log.Fatalf("无法解码 PNG 图像: %v", err)
// }
// // 获取图像的边界
// bounds := img.Bounds()
// width, height := bounds.Max.X, bounds.Max.Y
// // 将图像转换为 RGBA 格式
// rgbaImg := image.NewRGBA(bounds)
// draw.Draw(rgbaImg, bounds, img, image.Point{0, 0}, draw.Src)
// // 使用 go-libimagequant 进行图像量化
// quantizer := imagequant.NewQuantizer()
// defer quantizer.Close()
// // 配置量化参数(可选,这里使用默认参数)
// quantizer.SetMaxColors(256)
// quantizer.SetMinQuality(75)
// // 对图像进行量化
// result, err := quantizer.Quantize(rgbaImg)
// if err != nil {
// log.Fatalf("图像量化失败: %v", err)
// }
// defer result.Close()
// // 创建新的图像,使用量化后的颜色
// quantizedImg := image.NewPaletted(bounds, result.Palette())
// for y := 0; y < height; y++ {
// for x := 0; x < width; x++ {
// index := result.Image().At(x, y).(color.NRGBA).R
// quantizedImg.Set(x, y, result.Palette()[int(index)])
// }
// }
// // 保存量化后的图像为新的 PNG 文件
// outputFile, err := os.Create("output.png")
// if err != nil {
// log.Fatalf("无法创建输出图像文件: %v", err)
// }
// defer outputFile.Close()
// if err := png.Encode(outputFile, quantizedImg); err != nil {
// log.Fatalf("无法保存输出图像文件: %v", err)
// }
// log.Println("图像量化完成,已保存为 output.png")
// }
/*
*
@ 作者: 秦东
@ 时间: 2024-11-09 08:20:56
@ 功能:
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func JpgPngToSvg(inputPAgth, outputPath string) {
// imgFile, err := os.Open(inputPAgth)
// if err != nil {
// log.Fatalf("Error opening image: %v", err)
// }
// defer imgFile.Close()
// img, _, err := image.Decode(imgFile)
// if err != nil {
// log.Fatalf("Error decoding image: %v", err)
// }
// // 创建一个新的SVG画布
// dc := gg.NewContext(img.Bounds().Dx(), img.Bounds().Dy())
// // 将图片绘制到SVG上下文
// dc.DrawImage(img, 0, 0)
// // 将SVG内容写入文件
// var buf bytes.Buffer
// if err := gg.RenderToSVG(&buf, dc.Image().Bounds(), dc.Image(), nil); err != nil { //+
// log.Fatalf("Error rendering to SVG: %v", err) //+
// } //+
// svgFile, err := os.Create("output.svg")
// if err != nil {
// log.Fatalf("Error creating SVG file: %v", err)
// }
// defer svgFile.Close()
// if _, err := io.Copy(svgFile, &buf); err != nil {
// log.Fatalf("Error writing SVG file: %v", err)
// }
// fmt.Println("Image converted to SVG successfully.")
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-07 09:03:07
@ 功能: 访问webservice接口
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) VisitWebserviceInterface(c *gin.Context) {
urlVal_1 := "http://36.134.44.40:9080/ormrpc/services/EASLogin?wsdl"
urlVal_2 := "http://36.134.44.40:9080/ormrpc/services/WSTestFacade?wsdl"
val_1 := generalmethod.CurlGet(urlVal_1)
val_2 := generalmethod.CurlGet(urlVal_2)
sendMap := generalmethod.MapOut[string]()
sendMap["val_1"] = string(val_1)
sendMap["val_2"] = string(val_2)
fmt.Println("======================val_1=======Start===================================")
fmt.Println(string(val_1))
fmt.Println("======================val_2=======Start===================================")
fmt.Println(string(val_2))
fmt.Println("======================val_2=======END===================================")
// formatoutput.Result(0, sendMap, c)
// c.Writer(string(val_1))
c.String(200, string(val_1))
}