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

cn.net.wanmo.common.restful.body.Req Maven / Gradle / Ivy

There is a newer version: 1.3.9
Show newest version
package cn.net.wanmo.common.restful.body;

import cn.net.wanmo.common.http.pojo.Uploader;
import cn.net.wanmo.common.util.DateUtil;
import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.util.Map;

/**
 * 请求体
 */
@Deprecated
public abstract class Req implements Serializable {
    /**
     * 是否需要加密
     */
    protected boolean encrypt;
    /**
     * 加密所需的参数
     */
    protected Map encryptParams;
    /**
     * 请求体
     */
    protected String body;
    /**
     * 上传文件
     */
    protected Uploader uploader;
    /**
     * 请求时间(单位:毫秒)
     */
    protected Long reqTime;

    /**
     * 默认请求体无需加密
     */
    public Req() {
        this.encrypt = false;
        reqTime = DateUtil.nowLong();
    }

    public boolean isEncrypt() {
        return encrypt;
    }

    public void setEncrypt(boolean encrypt) {
        this.encrypt = encrypt;
    }

    public Map getEncryptParams() {
        return encryptParams;
    }

    public void setEncryptParams(Map encryptParams) {
        this.encryptParams = encryptParams;
    }

    public String getBody() {
        return body;
    }

    /**
     * 设置请求体,如果需要加密,需重写 encryptBody(body) 进行加密处理
     *
     * @param body
     */
    public void setBody(String body) {
        this.body = body;

        if (isEncrypt()) {
            this.body = encryptBody(body);
        }
    }

    /**
     * 将请求体加密
* 构造上加密后的可用的请求体 * * @param body 待加密数据 * @return 加密后的数据 */ public String encryptBody(String body) { this.body = body; return body; } public Uploader getUploader() { return uploader; } public void setUploader(Uploader uploader) { this.uploader = uploader; } public Long getReqTime() { return reqTime; } public void setReqTime(Long reqTime) { this.reqTime = reqTime; } public String toJSONString() { return JSON.toJSONString(this); } @Override public String toString() { return toJSONString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy