InBoxSDK.java 1.86 KB
package com.yohoufo.inboxclient.sdk;

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.
 */
@Service
public class InBoxSDK {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UrlConstant urlConstant;

    private final Logger log = LoggerFactory.getLogger(InBoxSDK.class);

    /**
     * @param reqVO
     * reqVO中各个参数说明如下
     * reqVO.type:详见枚举类 InboxBusinessTypeEnum
     * reqVO.businessType:详见枚举类 InboxBusinessTypeEnum
     * reqVO.params:用于替换模板消息的参数,多个参数用美式逗号分隔,例如:10000,abcd
     *
     * @return
     */
    public InBoxResponse addInbox(InboxReqVO reqVO){
        log.info("addInbox with param is {}", reqVO);
        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;
    }
    
    public InBoxResponse addBatchInbox(InboxReqVO reqVO){
        log.info("addBatchInbox with param is {}", reqVO);
        InBoxResponse result = restTemplate.getForObject(urlConstant.getInboxAddBatchUrl()+"&uids={1}&type={2}&businessType={3}&params={4}",InBoxResponse.class,
                reqVO.getUids(),reqVO.getType(),reqVO.getBusinessType(),reqVO.getParams());
        log.info("addBatchInbox call result is {}",result);
        return result;
    }
}