苍穹开发中OpenAPI的建议原创
4人赞赏了该文章
928次浏览
编辑于2021年11月25日 10:46:38
总所周知,外部系统要调用苍穹API接口,需要注册第三方应用,先在开放平台注册,生成第三方应用的appId和appsecret,然后通过接口获取应用令牌和访问令牌。后续每次请求中,客户端将访问令牌放在请求中发送给服务器,便可正常调用API服务。
在认证方式中选择需要的认证方式,如AccessToken认证、摘要加密认证和JWT加密认证.
在AccessToken加密认证的openApi调用中,可以用以下方式编写DTO(具体字段可能随苍穹版本升级而变化,详见苍穹开发文档)
通过以下对象,可以尽量避免对JSON字符串的操作.
public class CosmicAppToken { public String app_token; public Boolean success; public String error_desc; public Long expire_time; public String error_code; public String getApp_token() { return app_token; } public void setApp_token(String app_token) { this.app_token = app_token; } public Boolean getSuccess() { return success; } public void setSuccess(Boolean success) { this.success = success; } public String getError_desc() { return error_desc; } public void setError_desc(String error_desc) { this.error_desc = error_desc; } public Long getExpire_time() { return expire_time; } public void setExpire_time(Long expire_time) { this.expire_time = expire_time; } public String getError_code() { return error_code; } public void setError_code(String error_code) { this.error_code = error_code; } }
public class CosmicAccessToken { public String accessToken; public Boolean success; public String errorDesc; public Long expireTime; public String errorCode; public String getAccessToken() { return accessToken; } public void setAccessToken(String accessToken) { this.accessToken = accessToken; } public Boolean getSuccess() { return success; } public void setSuccess(Boolean success) { this.success = success; } public String getErrorDesc() { return errorDesc; } public void setErrorDesc(String errorDesc) { this.errorDesc = errorDesc; } public Long getExpireTime() { return expireTime; } public void setExpireTime(Long expireTime) { this.expireTime = expireTime; } public String getErrorCode() { return errorCode; } public void setErrorCode(String errorCode) { this.errorCode = errorCode; } }
public class CosmicApiDataResponse<T> { public T data; public String message; public String errorCode; public boolean success; public T getData() { return data; } public void setData(T data) { this.data = data; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getErrorCode() { return errorCode; } public void setErrorCode(String errorCode) { this.errorCode = errorCode; } public boolean isSuccess() { return success; } public void setSuccess(boolean success) { this.success = success; } }
public class CosmicApiResponse <T>{ public T data; public String state; public T getData() { return data; } public void setData(T data) { this.data = data; } public String getState() { return state; } public void setState(String state) { this.state = state; } }
赞 4
4人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!