fix wechat pay
This commit is contained in:
parent
f5b3eaca07
commit
031ba733f5
@ -96,9 +96,48 @@ func (l *WechatPayCallbackLogic) handleQueryOrderPayment(w http.ResponseWriter,
|
||||
}
|
||||
|
||||
if order.Status == "paid" {
|
||||
if asyncErr := l.svcCtx.AsynqService.SendQueryTask(order.Id); asyncErr != nil {
|
||||
logx.Errorf("异步任务调度失败: %v", asyncErr)
|
||||
return asyncErr
|
||||
redisKey := fmt.Sprintf(types.QueryCacheKey, order.UserId, order.OrderNo)
|
||||
cache, cacheErr := l.svcCtx.Redis.Get(redisKey)
|
||||
if cacheErr != nil {
|
||||
return fmt.Errorf("获取缓存内容失败: %+v", cacheErr)
|
||||
}
|
||||
var data types.QueryCacheLoad
|
||||
err := json.Unmarshal([]byte(cache), &data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("解析缓存内容失败: %+v", err)
|
||||
}
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return fmt.Errorf("获取AES密钥失败: %+v", decodeErr)
|
||||
}
|
||||
decryptData, aesdecryptErr := crypto.AesDecrypt(data.Params, key)
|
||||
if aesdecryptErr != nil {
|
||||
return fmt.Errorf("解密参数失败: %+v", aesdecryptErr)
|
||||
}
|
||||
var paramsMap map[string]string
|
||||
if err := json.Unmarshal([]byte(decryptData), ¶msMap); err != nil {
|
||||
return fmt.Errorf("解析参数失败: %+v", err)
|
||||
}
|
||||
encryptName, err := crypto.AesEncrypt([]byte(paramsMap["name"]), key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("生成订单, 加密姓名失败: %+v", err)
|
||||
}
|
||||
encryptIdcard, err := crypto.AesEncrypt([]byte(paramsMap["id_card"]), key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("生成订单, 加密身份证号失败: %+v", err)
|
||||
}
|
||||
_, err = l.svcCtx.AuthorizationModel.Insert(l.ctx, nil, &model.Authorization{
|
||||
OrderId: order.Id,
|
||||
UserId: order.UserId,
|
||||
TargetName: encryptName,
|
||||
TargetIdcard: encryptIdcard,
|
||||
GrantType: model.GrantTypeFace,
|
||||
Status: model.AuthorizationStatusPending,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("微信支付回调,插入授权信息失败: %+v", err)
|
||||
return fmt.Errorf("插入授权信息失败: %+v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,9 @@ import (
|
||||
|
||||
func TestAesEcbMobileEncryption(t *testing.T) {
|
||||
// 测试手机号加密
|
||||
mobile := "13800138000"
|
||||
key := []byte("1234567890abcdef") // 16字节AES-128密钥
|
||||
mobile := "15008098853"
|
||||
|
||||
keyStr := hex.EncodeToString(key)
|
||||
keyStr := "ff83609b2b24fc73196aac3d3dfb874f"
|
||||
// 测试加密
|
||||
encrypted, err := EncryptMobile(mobile, keyStr)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user