更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+4 -23
View File
@@ -16,30 +16,22 @@ import (
"strings"
)
// =============================================================
// 微信被动消息:签名校验 / 安全模式 AES 加解密 / XML 解析与回复构造
// 规范参考:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Message_encryption_and_decryption_instructions.html
// =============================================================
// pkcs7BlockSize 微信官方填充块大小(注意不是 16,是 32)
const pkcs7BlockSize = 32
// InboundMessage 接收到的消息/事件(已解密后的 XML 内容)
type InboundMessage struct {
XMLName xml.Name `xml:"xml"`
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime int64 `xml:"CreateTime"`
MsgType string `xml:"MsgType"` // text / image / event ...
MsgType string `xml:"MsgType"`
Content string `xml:"Content"`
Event string `xml:"Event"` // subscribe / unsubscribe / SCAN / CLICK ...
EventKey string `xml:"EventKey"` // qrscene_<scene> 或 <scene>
Event string `xml:"Event"`
EventKey string `xml:"EventKey"`
Ticket string `xml:"Ticket"`
MsgID int64 `xml:"MsgId"`
Encrypt string `xml:"Encrypt"` // 安全模式下外层 XML 携带的密文
Encrypt string `xml:"Encrypt"`
}
// ParseInboundXML 解析(明文/已解密的)消息 XML
func ParseInboundXML(raw string) (*InboundMessage, error) {
var msg InboundMessage
if err := xml.Unmarshal([]byte(raw), &msg); err != nil {
@@ -48,7 +40,6 @@ func ParseInboundXML(raw string) (*InboundMessage, error) {
return &msg, nil
}
// CheckSignature 明文模式签名校验:sha1(sort(token, timestamp, nonce))
func CheckSignature(token, timestamp, nonce, signature string) bool {
if token == "" || signature == "" {
return false
@@ -59,7 +50,6 @@ func CheckSignature(token, timestamp, nonce, signature string) bool {
return hex.EncodeToString(sum[:]) == signature
}
// CheckMsgSignature 安全/兼容模式签名校验:sha1(sort(token, timestamp, nonce, encrypt))
func CheckMsgSignature(token, timestamp, nonce, encrypt, msgSignature string) bool {
if token == "" || msgSignature == "" {
return false
@@ -70,7 +60,6 @@ func CheckMsgSignature(token, timestamp, nonce, encrypt, msgSignature string) bo
return hex.EncodeToString(sum[:]) == msgSignature
}
// MsgSignature 计算安全模式消息签名(回复加密时使用)
func MsgSignature(token, timestamp, nonce, encrypt string) string {
arr := []string{token, timestamp, nonce, encrypt}
sort.Strings(arr)
@@ -78,8 +67,6 @@ func MsgSignature(token, timestamp, nonce, encrypt string) string {
return hex.EncodeToString(sum[:])
}
// ============================ AES 加解密 ============================
func decodeAESKey(encodingAESKey string) ([]byte, error) {
key := strings.TrimSpace(encodingAESKey)
if len(key) != 43 {
@@ -88,7 +75,6 @@ func decodeAESKey(encodingAESKey string) ([]byte, error) {
return base64.StdEncoding.DecodeString(key + "=")
}
// DecryptMessage 安全模式消息解密,返回明文 XML;appID 非空时会校验一致性
func DecryptMessage(aesKey, appID, encryptBase64 string) (string, error) {
key, err := decodeAESKey(aesKey)
if err != nil {
@@ -127,7 +113,6 @@ func DecryptMessage(aesKey, appID, encryptBase64 string) (string, error) {
return msg, nil
}
// EncryptMessage 安全模式消息加密,返回 base64 密文
func EncryptMessage(aesKey, appID, msg string) (string, error) {
key, err := decodeAESKey(aesKey)
if err != nil {
@@ -187,9 +172,6 @@ func pkcs7Unpad(data []byte) ([]byte, error) {
return data[:len(data)-pad], nil
}
// ============================ 被动回复构造 ============================
// BuildTextReply 构造文本消息回复 XML(明文模式直接返回)
func BuildTextReply(toUser, fromUser, content string, timestamp int64) string {
esc := func(s string) string {
return strings.NewReplacer(
@@ -201,7 +183,6 @@ func BuildTextReply(toUser, fromUser, content string, timestamp int64) string {
esc(toUser), esc(fromUser), timestamp, esc(content))
}
// BuildEncryptedReply 安全模式回复:对明文回复加密并组装外层 XML
func BuildEncryptedReply(cfg *Config, plainReply, timestamp, nonce string) (string, error) {
encrypt, err := EncryptMessage(cfg.AESKey, cfg.AppID, plainReply)
if err != nil {