package org.jeecg.modules.wps.util;

import cn.com.ctop.common.module.file.FileUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Configuration
public class WpsUtil {

    public static final String domain = "https://wwo.wps.cn/office/";
    public static final String appid = "aba9d3b0553f4eb4a69980b26927dc7a";
    public static final String appsecret = "017d85f689d54d05a7a2ad2187f9e645";
    public static final String downloadHost = "";
    public static final String localDir = "";
    public String getWpsUrl(Map<String,String> values,String fileType,String fileId){
        String keyValueStr = SignatureUtil.getKeyValueStr(values);
        String signature = SignatureUtil.getSignature(values, appsecret);
        String fileTypeCode = FileUtil.getFileTypeCode(fileType);

        return domain + fileTypeCode + "/" + fileId + "?"
                + keyValueStr + "_w_signature=" + signature;
    }

    public String getTemplateWpsUrl(String fileType,String userId){
        Map<String,String> values = new HashMap<>();
        values.put("_w_appid", appid);
        values.put("_w_userid", userId);
        String keyValueStr = SignatureUtil.getKeyValueStr(values);
        String signature = SignatureUtil.getSignature(values, appsecret);
        String fileTypeCode = FileUtil.getTypeCode(fileType);

        return domain + fileTypeCode + "/new/0" + "?"
                + keyValueStr + "_w_signature=" + signature;
    }

}
