package com.zhongshu.card.server.core.util;

import com.github.microservice.types.payment.PaymentType;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author TRX
 * @date 2024/7/3
 */
public class PaymentUtil {

    // 微信付款码开头
    public static List<String> wxStartList = List.of("10", "11", "12", "13", "14", "15");

    // 支付宝付款码开头
    public static List<String> zfbStartList = List.of("25", "26", "27", "28", "29", "30");

    /**
     * 根据B扫C 扫码内容判断是支付宝 还是微信支付
     *
     * @param qr
     * @return
     */
    public static PaymentType getPaymentTypeByQr(String qr) {
        PaymentType paymentType = null;
        if (StringUtils.isNotEmpty(qr)) {
            if (qr.indexOf("userId") > 0) {
                return PaymentType.UserWallet;
            }
            int len = qr.length();
            for (String str : wxStartList) {
                if (qr.startsWith(str) && len == 18) {
                    return PaymentType.WxQrCode;
                }
            }

            for (String str : zfbStartList) {
                if (qr.startsWith(str)) {
                    return PaymentType.ZfbQrCode;
                }
            }
        }
        return paymentType;
    }

}
