package com.tax.token.thirdService.impl;

import com.tax.token.model.TkServer;
import com.tax.token.model.TkZoneInfo;
import com.yxcheng.token.utils.HttpHelper;
import com.yxcheng.token.utils.JSONHelper;
import com.yxcheng.token.utils.MD5Util;
import com.yxcheng.token.utils.ResponseContent;
import com.tax.token.model.TkToken;
import com.tax.token.thirdService.TokenThirdServiceI;
import org.apache.http.HttpException;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class GetTokenFromTaxBureau implements TokenThirdServiceI{

    @Override
    public Map<String, Object> invoke(String uuIdFlag, TkToken tokenEntity, TkZoneInfo tkZoneInfo, TkServer tkServer,boolean isFirst) throws IOException, HttpException {
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        String taxno = tokenEntity.getTaxno();
        String dqbm = tokenEntity.getZoneCode();

        ResponseContent ret = null;
        String force = "true";
        paramsMap.put("sh", taxno);
        paramsMap.put("dqbm", dqbm);
        paramsMap.put("force", force);
        paramsMap.put("username", tkServer.getUserName());
        paramsMap.put("sign", MD5Util.MD5Encode(taxno + dqbm + force + tkServer.getUserName() + tkServer.getPassword()));
        ret = HttpHelper.postEntity(tkServer.getReqUrl(), paramsMap);
        String retStr = ret.getContent();
        Map<String, Object> retMap = JSONHelper.parserToMap(retStr);
        return retMap;
    }
}
