提交 24b39ef1 authored 作者: zjm's avatar zjm

111

上级 ff8afbbf
......@@ -3,19 +3,17 @@ package com.tykj.zlbapp.subject.service.impl;
import com.tykj.zlbapp.contants.AppConstants;
import com.tykj.zlbapp.subject.service.ZlbAppAuthService;
import com.tykj.zlbapp.util.HeadUtil;
import com.tykj.zlbapp.util.HttpClientUtil;
import com.tykj.zlbapp.util.MD5Util;
import org.apache.coyote.Constants;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @author zsp
......@@ -35,17 +33,17 @@ public class ZlbAppAuthServiceImpl implements ZlbAppAuthService {
//1 构造header
HttpHeaders headers = HeadUtil.getHeader();
//请求body为x-www-form-urlencoded方式
Map<String, Object> params=new HashMap<>();
MultiValueMap<String,Object> params = new LinkedMultiValueMap<>();
//servicecode 就是ak
params.put("servicecode",AppConstants.IRS_AK);
params.put("method","ticketValidation");
params.add("servicecode",AppConstants.IRS_AK);
params.add("method","ticketValidation");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
String format = simpleDateFormat.format(new Date());
params.put("time",format);
params.put("sign", MD5Util.getInstance().getMD5(AppConstants.IRS_AK+AppConstants.IRS_SK+format));
params.put("st",ticket);
params.put("content-type","application/x-www-form-urlencoded");
HttpEntity httpEntity=new HttpEntity<>(params,headers);
params.add("time",format);
params.add("sign", MD5Util.getInstance().getMD5(AppConstants.IRS_AK+AppConstants.IRS_SK+format));
params.add("st",ticket);
HttpEntity<MultiValueMap<String, Object>> httpEntity=new HttpEntity<>(params,headers);
String body = restTemplate.postForEntity(AppConstants.ACCESS_TOKEN_URL, httpEntity, String.class).getBody();
return body;
......
......@@ -20,7 +20,7 @@ public class HeadUtil {
headers.add(AppConstants.X_BG_HMAC_ALGORITHM, map.get("X-BG-HMAC-ALGORITHM"));
headers.add(AppConstants.X_BG_HMAC_SIGNATURE, map.get("X-BG-HMAC-SIGNATURE"));
headers.add(AppConstants.X_BG_DATE_TIME, map.get("X-BG-DATE-TIME"));
// headers.set("contentType","application/x-www-form-urlencoded");
headers.add("content-type","application/x-www-form-urlencoded");
return headers;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论