package com.yonge.toolset.payment.original.ali.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.huifu.adapay.Adapay;
import com.huifu.adapay.model.MerConfig;
import com.yonge.toolset.payment.adapay.constant.AdapayConstant;
import com.yonge.toolset.payment.base.enums.OpenEnum;
import com.yonge.toolset.payment.base.enums.PaymentClientEnum;
import com.yonge.toolset.payment.core.service.SysConfigPaymentService;
import com.yonge.toolset.payment.original.ali.constant.AlipayConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: liweifan
 * @Data: 2022/5/12 10:12
 */
@Configuration
public class AlipayConfiguration {
    @Autowired
    private SysConfigPaymentService configPaymentService;

    /***
     * 支付宝APP支付Bean
     * @author liweifan
     * @updateTime 2022/5/12 14:16
     * @return: com.alipay.api.AlipayClient
     */
    @Bean(name = "studentAlipayClient")
    public AlipayClient studentAlipayClient() {
        AlipayClient alipayClient = new DefaultAlipayClient(
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, AlipayConstant.ALI_URL).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.STUDENT, AlipayConstant.ALI_APPID).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.STUDENT, AlipayConstant.ALI_APP_PRIVATE_KEY).getParamValue(),
                "json", "UTF-8",
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.STUDENT, AlipayConstant.ALI_ALIPAY_PUBLIC_KEY).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.STUDENT, AlipayConstant.ALI_SIGN_TYPE).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.STUDENT, AlipayConstant.ALI_CONTENT_SIGN_KEY).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.STUDENT, AlipayConstant.ALI_CONTENT_SIGN_TYPE).getParamValue()
        );
        return alipayClient;
    }

    @Bean(name = "teacherAlipayClient")
    public AlipayClient teacherAlipayClient() {
        AlipayClient alipayClient = new DefaultAlipayClient(
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, AlipayConstant.ALI_URL).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.TEACHER, AlipayConstant.ALI_APPID).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.TEACHER, AlipayConstant.ALI_APP_PRIVATE_KEY).getParamValue(),
                "json", "UTF-8",
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.TEACHER, AlipayConstant.ALI_ALIPAY_PUBLIC_KEY).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.TEACHER, AlipayConstant.ALI_SIGN_TYPE).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.TEACHER, AlipayConstant.ALI_CONTENT_SIGN_KEY).getParamValue(),
                configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, PaymentClientEnum.TEACHER, AlipayConstant.ALI_CONTENT_SIGN_TYPE).getParamValue()
        );
        return alipayClient;
    }

}
