java对接拉卡拉

代码贴入 直接使用


import com.lkl.laop.sdk.Config;
import com.lkl.laop.sdk.LKLSDK;
import com.lkl.laop.sdk.exception.SDKException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "lakala")
public class LakalaConfig {

    private String appId = "OP*****84";

    private String serialNo = "018d*****faa";

    private String priKeyPath = "D:\***\api_private_key.pem";

    private String lklCerPath = "D:\***\lkl-apigw-v1.cer";

    private String lklNotifyCerPath = "D:\***\lkl-apigw-v1.cer";

    private String serverUrl = "https://s2.lakala.com/";

    @Bean
    public void initLkl() {
        try {
            LKLSDK.init(new Config(appId, serialNo, priKeyPath, lklCerPath, lklNotifyCerPath, serverUrl));
        } catch (SDKException e) {
            throw new RuntimeException(e);
        }
    }
}


@Slf4j
@Component
public class LakalaPayUtil {

    private static LakalaConfig lakalaConfig = SpringUtils.getBean(LakalaConfig.class);

    public static String createOrder(PayInfoDto payInfoDto) throws Exception {
        V3CcssCounterOrderSpecialCreateRequest req = new V3CcssCounterOrderSpecialCreateRequest();
        req.setMerchantNo("82250304812015E");
        req.setOutOrderNo(payInfoDto.getOrderNo());
        req.setTotalAmount(payInfoDto.getRealPayMoney().multiply(BigDecimal.valueOf(100)).longValue());
        req.setOrderEfficientTime("20250531111111");
        req.setOrderInfo(payInfoDto.getGoodsName());
        req.setSupportRefund(1);
        String counterParam = "{\"pay_mode\":\"ALIPAY\"}";
        req.setCounterParam(counterParam);
        String response = LKLSDK.httpPost(req);
        log.info("拉卡拉创建订单返回:{}", response);
        return response;
    }
}

mvn install:install-file -Dfile=D:\www\lkl-java-sdk-1.0.7.jar -DgroupId=com.lkl.laop.sdk -DartifactId=lkl-laop-java-sdk -Dversion=1.0.7 -Dpackaging=jar

导入maven

<dependency>
    <groupId>com.lkl.laop.sdk</groupId>
    <artifactId>lkl-laop-java-sdk</artifactId>
    <version>1.0.7</version>
</dependency>

如果是srpingboot3需要这个
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
</dependency>
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐