package com.tax.user.service.safe.impl;



import com.yxcheng.token.common.enumutil.ResultEnum;
import com.yxcheng.token.common.model.CrRpcResult;
import com.yxcheng.token.common.model.RestfulApi;
import com.tax.user.service.safe.RestFulCheckI;
import net.sf.json.JSONObject;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * Created by 曹小红 on 2017-04-11.
 */
@Order(1)
@Component
public class RestFulCheckParamsImpl implements RestFulCheckI {


    @Override
    public boolean checkData(String data, RestfulApi apiModel, CrRpcResult<String> rpcResult) {
        try {
            JSONObject json = JSONObject.fromObject(data);
            apiModel.setAccessKeyID(String.valueOf(json.get("accessKeyID")));
            apiModel.setTimeStamp(String.valueOf(json.get("timeStamp")));
            apiModel.setSignatureNonce(String.valueOf(json.get("signatureNonce")));
            apiModel.setVersion(String.valueOf(json.get("version")));
            apiModel.setSignature(String.valueOf(json.get("signature")));
            apiModel.setData(String.valueOf(json.get("Data")));

            if(apiModel.isHaveNull()) {
                rpcResult.errorResponse(ResultEnum.param_error);
            } else {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            rpcResult.errorResponse(ResultEnum.param_error);
        }
        return false;
    }
}
