代码拉取完成,页面将自动刷新
同步操作将从 slacrey/api-wrap 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
compile 'com.seelyn:api-wrap-boot:{version}'
<dependency>
<groupId>com.seelyn</groupId>
<artifactId>api-wrap-boot</artifactId>
<version>{version}</version>
</dependency>
@SpringBootApplication
@EnableApiWrap
public class WrapWebApplication {
public static void main(String[] args) {
SpringApplication.run(WrapWebApplication.class, args);
}
}
@ApiWrap
@PostMapping(value = "/web")
public WrapRequest<DefaultWrapData> web(@RequestBody WrapRequest<DefaultWrapData> request) {
return request;
}
@ApiWrap(value=CustomWrapHandler.class)
CustomWrapHandler类需要实现WrapHandler接口
public class WrapRequest<T extends WrapData> {
private String appKey;
private String signature;
private long timestamp;
private int nonce;
private T data;
//setter getter省略....
}
import com.seelyn.apiwrap.WrapData;
import com.seelyn.apiwrap.annotation.SignIgnore;
public class DefaultWrapData extends WrapData {
// SignIgnore 注解标识标识忽略属性用于签名
@SignIgnore
private String name;
private String url;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
@Autoware
private WrapStore wrapStore;
// 存储密钥
wrapStore.putSecret(appKey, appSecret);
#===========api wrap===========
# app密钥,若用户没有自定义,则使用此
api.wrap.secret=testjjhdsa
# 单位秒,请求时间和服务器时间不能超过300秒
api.wrap.legal-time=300
# 若没有redis配置,wrapStore为本地存储
# 若配置了redis,则wrapStore为redis存储
#===========api wrap redis=============
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.database=0
compile 'com.seelyn:api-wrap-client:{version}'
<dependency>
<groupId>com.seelyn</groupId>
<artifactId>api-wrap-client</artifactId>
<version>{version}</version>
</dependency>
DefaultWrapData WrapData = new DefaultWrapData();
WrapClient wrapClient = WrapClient.create(appKey, appSecret);
WrapRequest<DefaultWrapData> request = wrapClient.wrap(WrapData)
// request 为带签名信息的对象
@Service
class CustomWrapStore extends RedisWrapStore {
}
这样继承RedisWrapStore类或者实现WrapStore接口,可自定义包裹存储接口。系统自动使用你自定义的WrapStore
// 自定义WrapHandler, 使用@Component注入到spring中管理
@Component
public class CustomWrapHandler implements WrapHandler {
@Override
public String getAppSecret(String appKey) {
return null;
}
@Override
public String getSignature(String appKey, WrapRequest<WrapData> request) {
return null;
}
@Override
public void isLegalTime(long timestamp) {
}
@Override
public void isReplayAttack(String appKey, long timestamp, int nonce, String signature) {
}
}
// ApiWrap中指定CustomWrapHandler.class类,则系统会根据此类型从Spring中获取对应的实例
@ApiWrap(value = CustomWrapHandler.class)
@PostMapping(value = "/web")
public WrapRequest<DefaultWrapData> custom(@RequestBody WrapRequest<DefaultWrapData> request) {
return request;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。