package com.tsf.demo.provider.controller; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.HexUtil; import cn.hutool.crypto.digest.DigestUtil; import com.tsf.demo.provider.common.siyuan.BeanSortUtil; import com.tsf.demo.provider.common.siyuan.CommonReq; import com.tsf.demo.provider.common.siyuan.Testa; import io.swagger.annotations.Api; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.http.*; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.alibaba.fastjson.*; import org.springframework.web.client.RestTemplate; @RestController @CrossOrigin @RequestMapping("/siYuanCard") @Api(value = "思源电子卡接口", tags = "思源电子卡接口") public class SiYuanController { public static void main(String[] args) { //获取思源卡中心sign String url = "http://test-t600.systoon.com/platform-card/api/cardType/getCardTypeList"; String appSecret= "925f6792-cdde-49c1-93c1-e161459b93ee"; String appId = "1001153"; String signType = "MD5"; Long timestamp = System.currentTimeMillis(); String version = "1.0.0"; JSONObject jsonObjectParam = new JSONObject(); jsonObjectParam.put("appKey","\""+appId+"\""); //jsonObjectParam.put("toonType","102"); String toSignStr = "appKey=\""+appId+"\"&"+ "appSecret=\""+appSecret+"\"&"+ "data=\""+jsonObjectParam.toJSONString()+"\"&"+ "timestamp=\""+System.currentTimeMillis()+"\"&"+ "version=\""+version+"\""; String sign = DigestUtils.md5Hex(toSignStr).toUpperCase(); //获取思源卡中心sign结束 //利用sign测试接口 //拼接请求体 JSONObject jsonObject = new JSONObject(); jsonObject.put("appKey",appId); jsonObject.put("timestamp",timestamp); jsonObject.put("sign",sign); jsonObject.put("version","1.0.0"); String httpUrl = "http://test-t600.systoon.com/platform-card/api/cardType/getCardTypeList"; RestTemplate client = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.add("lpToken","obEOvw6wodEQV_W4pI4_-6sX1YOA"); headers.add("toonType","102"); headers.setContentType(MediaType.APPLICATION_JSON_UTF8); HttpEntity requestEntity = new HttpEntity(jsonObject,headers); ResponseEntity exchange = null; exchange = client.exchange(httpUrl, HttpMethod.POST, requestEntity, Object.class); System.out.println(exchange.getBody()); //利用sign测试接口结束 } }