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

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐