This commit is contained in:
suyl
2021-08-17 15:01:15 +08:00
parent 682b2ba536
commit f4b2e65790

View File

@@ -218,6 +218,8 @@ func (a *API) GetCallbackMsg(formMap map[string]interface{}, bodyData []byte) (m
if descryptMsg, err = a.Decrypt(formMap["signature"].(string), formMap["timestamp"].(string), formMap["nonce"].(string), encrypt); err == nil {
baseapi.SugarLogger.Debugf("dingding GetCallbackMsg descryptMsg:%s", descryptMsg)
err = utils.UnmarshalUseNumber([]byte(descryptMsg), &msgMap)
} else {
fmt.Println("err ", err)
}
}
return msgMap, a.Err2CallbackResponse(err)
@@ -226,14 +228,8 @@ func (a *API) GetCallbackMsg(formMap map[string]interface{}, bodyData []byte) (m
}
func NewDingTalkCrypto(token, encodingAESKey, suiteKey string) *DingTalkCrypto {
bkey, err := base64.StdEncoding.DecodeString(encodingAESKey + "=")
if err != nil {
fmt.Println("111111111111111", err)
}
block, err := aes.NewCipher(bkey)
if err != nil {
fmt.Println("22222222222222222", err)
}
bkey, _ := base64.StdEncoding.DecodeString(encodingAESKey + "=")
block, _ := aes.NewCipher(bkey)
c := &DingTalkCrypto{
Token: token,
EncodingAESKey: encodingAESKey,
@@ -254,26 +250,17 @@ func (c *DingTalkCrypto) GetDecryptMsg(signature, timestamp, nonce, secretMsg st
if len(decode) < aes.BlockSize {
return "", errors.New("ERROR: 密文太短")
}
fmt.Println("1")
blockMode := cipher.NewCBCDecrypter(c.Block, c.BKey[:c.Block.BlockSize()])
fmt.Println("2")
plantText := make([]byte, len(decode))
fmt.Println("3")
blockMode.CryptBlocks(plantText, decode)
fmt.Println("4")
plantText = pkCS7UnPadding(plantText)
fmt.Println("5")
size := binary.BigEndian.Uint32(plantText[16:20])
fmt.Println("6")
plantText = plantText[20:]
fmt.Println("7")
corpID := plantText[size:]
fmt.Println("8")
fmt.Println("222222222222222222222222222222222222", string(plantText[:size]))
if string(corpID) != c.SuiteKey {
fmt.Println("9")
return "", errors.New("ERROR: CorpID匹配不正确")
}
fmt.Println("222222222222222222222222222222222222")
return string(plantText[:size]), nil
}