Authored by csgyoho

完善inboxsdk

... ... @@ -14,8 +14,23 @@
<dependencies>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-common</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.yohoufo.inboxclient.common;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import java.io.Serializable;
... ...
package com.yohoufo.inboxclient.common;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* Created by shengguo.cai on 2018/9/25.
*/
@Component
public class UrlConstant {
@Value("${inbox.baseurl}")
private String baseUrl;
public String getInboxAddUrl(){
return baseUrl+"&method=ufo.users.addInbox";
}
}
... ...
package com.yohoufo.inboxclient.model;
import org.apache.commons.lang3.StringUtils;
/**
* API 响应格式
* /**
* 响应为:
* <pre>
* {
* "code": 200,
* "message": "\u767b\u5f55\u6210\u529f",
* “alg": "SALT_MD5"
* "data": {
* "uid": "10216497",
* "passport": "18751986615",
* "session_key": "fa31d3a5d069c6c98cd8c38c3a5f89e6",
* "vip": 0
* },
* "md5": "fa5b07f95a0bf95c26ac50abf0024eed"
* }
* Created by chang@yoho.cn on 2015/11/3.
*/
public class InBoxResponse {
private static String DEFAULT_MSG = "操作成功";
private static int DEFAULT_CODE = 200;
private int code;
private String message;
private String md5;
//如果客户端判断有这个,则校验MD5
private String alg = "SALT_MD5";
private Object data;
public InBoxResponse() {
this(DEFAULT_CODE, DEFAULT_MSG, null);
}
public InBoxResponse(int code, String message, Object data) {
this.code = code;
if (StringUtils.isNotEmpty(message)) {
this.message = message;
}
this.data = data;
}
public String getAlg() {
return alg;
}
public void setAlg(String alg) {
this.alg = alg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}
... ...
package com.yohoufo.inboxclient.sdk;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.inboxclient.common.UrlConstant;
import com.yohoufo.inboxclient.model.InBoxResponse;
import com.yohoufo.inboxclient.model.InboxReqVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
/**
* Created by shengguo.cai on 2018/9/19.
... ... @@ -14,14 +15,16 @@ import org.springframework.stereotype.Service;
@Service
public class InBoxSDK {
@Autowired
private UfoServiceCaller serviceCaller;
private RestTemplate restTemplate;
@Autowired
private UrlConstant urlConstant;
private final Logger log = LoggerFactory.getLogger(InBoxSDK.class);
public ApiResponse addInbox(InboxReqVO reqVO){
public InBoxResponse addInbox(InboxReqVO reqVO){
log.info("addInbox with param is {}", reqVO);
ApiResponse result = serviceCaller.call("ufo.users.addInbox",ApiResponse.class,reqVO.getUid(),
reqVO.getType(),reqVO.getBusinessType(),reqVO.getParams());
InBoxResponse result = restTemplate.getForObject(urlConstant.getInboxAddUrl()+"&uid={1}&type={2}&businessType={3}&params={4}",InBoxResponse.class,
reqVO.getUid(),reqVO.getType(),reqVO.getBusinessType(),reqVO.getParams());
log.info("addInbox call result is {}",result);
return result;
}
... ...
... ... @@ -45,7 +45,8 @@ password.aes.key=yoho9646yoho9646
#用户uic服务地址
uic.service.url=http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
#消息盒子-baseurl
inbox.baseurl=http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/?debug=XYZ
#signature encrypt key salt
gateway.signature.key.salt=mQyMTMwZjlmZTZmYjY4UjkNmYwZGM0OTk0Y
trace.enabled=false
... ...
... ... @@ -26,6 +26,8 @@ web.context=ufo-gateway
#\u5bc6\u7801AES\u52a0\u5bc6\u5bc6\u94a5
password.aes.key=${password.aes.key}
uic.service.url=${uic.service.url}
#Ϣ-url
inbox.baseurl=${inbox.baseurl}
#signature encrypt key salt
gateway.signature.key.salt=${gateway.signature.key.salt}
... ...