Code Monkey home page Code Monkey logo

wacai-gateway-sdk's Introduction

OpenApi Gateway SDK

特性

  • 基于filter模式进行扩展,可以选择性使用加签,验签,加密等功能,也可以添加自己的过滤器实现。
  • 内置了okhttp进行http请求,同时也支持替换其他http客户端。
  • 内置了本地监控,对流量,耗时,成功率进行统计。

用法

maven依赖:

<dependency>
	<groupId>com.wacai</groupId>
	<artifactId>wacai-gtateway-sdk</artifactId>
	<version>1.0.0</version>
</dependency>

一个简单的例子:

NeptuneConfig config = Neptune.config()
		.host("http://neptune-server.middleware.k2.test.wacai.info")
		.appKey("******")//替换为实际的appKey
		.appSecret("("******") //替换为实际的appSecret
		.build();

NeptuneClient client = Neptune.client(config);
ApiRequest request = new ApiRequest("message.api.push", "1.0");
String json = "{\"content\":\"mytest\"}";
request.setData(json.getBytes());
ApiResponse respone = client.invoke(request);

System.out.println(respone.getCode());
System.out.println(new String(respone.getData()));

"message.api.push" 是我在server端添加好的 api,以上代码输出:

code:200
response:{"id":0,"header":{},"content":"mytest","offset":0}

加签

默认使用 MAC 算法加签,如果使用其他加密算法,可以如下配置进行修改:

NeptuneConfig config = Neptune.config()
		.signature(Signatures.RSA.getName())
		.publicKey("设置公钥"))
		.build();

验签

可以对API返回的数据进行延签, 默认不开启验签,如要开启通过如下配置:

NeptuneConfig config = Neptune.config()
		.verifier(Signatures.MAC.getName())
		.build();
NeptuneClient client = Neptune.client(config);		
//省略后续调用代码

加解密

默认不会加密数据,可以通过配置打开数据加密功能:

NeptuneConfig config = Neptune.config()
		.encryptor(Encryptors.DES.getName())
		.build();
NeptuneClient client = Neptune.client(config);		

异常处理

如调用失败,NeptuneClient 会抛出 NeptuneException,使用方需要捕获该异常。

wacai-gateway-sdk's People

Contributors

jiangyunpeng avatar

Watchers

Jason Cao avatar Darcy Shen avatar  avatar l.xie avatar xiaozhao1795 avatar Sucre avatar

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.