package com.qs.mp.common;

import com.qs.mp.common.utils.http.MpHttpRequestUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.qs.mp.common.utils.RandomUtils;
import com.qs.mp.common.utils.http.OkHttpUtil;
import com.qs.mp.common.utils.sign.Md5Utils;

/**
 * @auther duota
 * @create 2021 2021/9/3 11:57 上午
 * @describe
 */
public class BaseControllerTest {

  protected String request(String url, String params) {
    return MpHttpRequestUtils.request(url, params);
  }

  protected String upload(String url, String params, String filePath, String fileName) {
    String nonce = RandomUtils.generateString(20);
    Date nowTime = new Date();
    String timestamp = String.valueOf(nowTime.getTime());

    String md5key = "3Jr8S1K18rcC1wAfv8";
    String l = params + "nonce" + timestamp + md5key;
    System.out.println("sign str:" + l);
    String sign = Md5Utils.hash(l);

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("x-zz-timestamp", timestamp);
    String token = "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1OTE3NTIwOTQsInVzZXJJZCI6IkU1TDNTUUs2NDlVSUhJVVpDRURLIiwibWdyQ3VsbElkcyI6WyJFNU05V1lRQlkySUs3OVgyQ1QwUyIsIkU1TURLVFowSU0xVFc3N0FXNFFFIiwiRTVPUVJHUkRQQURSMTRYUDYzVTgiLCJFNVFNQUpPSjQ5MkZDQ1M3TkJGSyIsIkU1VUZIRU80UVlWNzYzUVBZOURIIl0sIm93bmVyQ29sbElkIjoiRTVVRkhFTzRRWVY3NjNRUFk5REgifQ.DslDTpM2CELG9BqKr55flZLyS06I8V8RfY3CSUCm12uQAt1mHd3ImpzrXDpHcFdVpyf2_za_JFRVXJ7tv4MstQ"; // 本地登录状态
    if (!StringUtils.isBlank(token)) {
      headers.put("b2b-authorization", token);
    }
    String reqUrl = url + "sign=" + sign + "&nonce=" + nonce;
    //String reqUrl = url;
    try {
      //  return OkHttpUtil.upload(reqUrl, filePath, fileName, headers);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return "";

  }
}
