Code Monkey home page Code Monkey logo

groupmeal-java-sdk's Introduction

Java SDK

源码目录结构

Java SDK主要目录结构

com.sankuai.groupmeal
       ├── base                                //基础相关
       │       └── http                        //http通信相关类
       │       └── util                        //工具类
       │       └── logger                      //日志
       │       └── constant                    //常量
       │       └── exception                   //异常相关
       │       └── GlobalConfig                //全局配置
       │       └── Credential                  //接入凭证
       ├── business                            //业务入口
       │       └── pay                         //支付

安装

使用 Maven:

<dependency>
    <groupId>com.sankuai.groupmeal</groupId>
    <artifactId>groupmeal-java-sdk</artifactId>
    <version>1.0.0</version>
</dependency>

运行环境

JDK 1.8 及以上

使用方法

支付成功回调

//打开全局日志开关,打开后会打印请求header、body信息,以及响应的header
GlobalConfig.printTraceSwitch(true);
//appId,appSecret 修改为自己的配置信息
String appId = "tcqd_demo03";
String appSecret = "7EptKX5BG6h6bNDE8gGxAkXvtyG8CUeY";
//环境,需要区分测试联调和线上环境
EnvType envType = EnvType.TEST;
//构造支付接口实例,最后单例
PayClient payClient = new PayClient(new Credential(appId, appSecret), envType);
//构造支付回调业务参数
PayCallbackParam param = new PayCallbackParam();
param.setTradeNo("604557080286524400");
param.setStatus(0);
param.setPaymentId("1");
param.setTotalAmount("1300");
param.setNotifyTime(System.currentTimeMillis() / 1000 + "");

PayCallbackResult result = payClient.payNotifyCallback(param);
System.out.println("result: " + JsonUtil.encode2UnderScore(result));
if (result.success()) {
    //回调成功处理逻辑
    System.out.println("回调成功");
    System.out.println("paymentId: " + result.getData());
}

switch (result.code()) {
    case PAY_CALL_FAIL:
        System.out.println("支付回调失败,无需重试,需要双方排查原因");
        break;
    case SIGN_NOT_MATCH:
        System.out.println("签名不匹配,需要排查");
        break;
    case UNKNOWN:
        System.out.println("未知异常,可以尝试间隔重试,设置最大重试次数");
        break;
}

详细使用文档

参考美团企业用餐开放平台

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.