All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zopen.wechat.mp.dto.BaseResponse Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.zopen.wechat.mp.dto;

import com.zcj.util.UtilString;
import com.zopen.wechat.exception.WechatException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 微信公众号接口返回的基类
 *
 * @author [email protected]
 * @since 2019/8/26
 */
public class BaseResponse {

    private static final Logger logger = LoggerFactory.getLogger(BaseResponse.class);

    private Integer errcode;

    private String errmsg;

    public boolean success() {
        return errcode == null || errcode.equals(0);
    }

    public void valid(String message) {
        if (!success()) {
            StringBuilder sb = new StringBuilder();
            sb.append(UtilString.isNotBlank(message) ? message : "请求微信接口失败");
            sb.append("{ errcode:" + errcode + ",errmsg:" + errmsg + " }");
            String errorInfo = sb.toString();
            logger.error(errorInfo);
            throw new WechatException(errorInfo);
        }
    }

    public Integer getErrcode() {
        return errcode;
    }

    public void setErrcode(Integer errcode) {
        this.errcode = errcode;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy