package com.ruoyi.app.omgpay;

import com.ruoyi.system.utils.JwtUtil;
import org.springframework.stereotype.Component;

@Component
public class OmgPaymentTokenUserResolver {
    public Long requireUserId(String token) {
        try {
            String userId = new JwtUtil().getusid(token);
            if (userId == null || userId.isBlank()) {
                throw new OmgPaymentBusinessException(OmgPaymentErrorCode.AUTH_REQUIRED);
            }
            return Long.valueOf(userId);
        } catch (OmgPaymentBusinessException error) {
            throw error;
        } catch (Exception error) {
            throw new OmgPaymentBusinessException(OmgPaymentErrorCode.AUTH_REQUIRED);
        }
    }
}
