| | |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | @Component |
| | | @Slf4j |
| | | public class TideUtils { |
| | | private final static String appId = "1151162645026439168"; |
| | | |
| | | private final static String appSecret = "t1BsMDgwODIwMjUxMTUwMjc3NzMdNi"; |
| | | public static String APP_ID; |
| | | public static String APP_SECRET; |
| | | |
| | | |
| | | @Value("${inspur.appId}") |
| | | private String appId; |
| | | |
| | | @Value("${inspur.appSecret}") |
| | | private String appSecret; |
| | | |
| | | @Value("${inspur.appId}") |
| | | public void setAppId(String appId) { |
| | | TideUtils.APP_ID = appId; |
| | | } |
| | | |
| | | @Value("${inspur.appSecret}") |
| | | public void setAppSecret(String appSecret) { |
| | | TideUtils.APP_SECRET = appSecret; |
| | | } |
| | | |
| | | // 内网地址 |
| | | private final static String ip = "http://10.136.0.8:8083"; |
| | |
| | | xSignSplicingTogether = "x-random=" + xRandom + "&x-time=" + xTime; |
| | | } |
| | | // 配置加密方式与密钥 |
| | | HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, appSecret.getBytes()); |
| | | HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, APP_SECRET.getBytes()); |
| | | // 得出x-sign |
| | | String xSign = hMac.digestHex(xSignSplicingTogether); |
| | | HashMap<String, String> result = new HashMap<>(); |
| | | result.put("x-time", xTime); |
| | | result.put("x-random", xRandom); |
| | | result.put("x-sign", xSign); |
| | | result.put("appKey", appId); |
| | | result.put("appKey", APP_ID); |
| | | return result; |
| | | } |
| | | |
| | |
| | | xSignSplicingTogether = "x-random=" + xRandom + "&x-time=" + xTime; |
| | | } |
| | | // x-sign 加密 |
| | | HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, appSecret.getBytes()); |
| | | HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, APP_SECRET.getBytes()); |
| | | String xSign = hMac.digestHex(xSignSplicingTogether); |
| | | HashMap<String, String> result = new HashMap<>(); |
| | | result.put("x-time", xTime); |
| | | result.put("x-random", xRandom); |
| | | result.put("x-sign", xSign); |
| | | result.put("appKey", appId); |
| | | result.put("appKey", APP_ID); |
| | | return result; |
| | | } |
| | | |
| | |
| | | String url = ip + "/cpn/extral/applicationCode/appAuthCheck"; |
| | | JSONObject json = new JSONObject(); |
| | | json.put("code", code); |
| | | json.put("appID", appId); |
| | | json.put("appSecret", appSecret); |
| | | json.put("appID", APP_ID); |
| | | json.put("appSecret", APP_SECRET); |
| | | HashMap<String, String> header = getPostHeader(json.toString()); |
| | | String body = HttpRequest.post(url) |
| | | .headerMap(header, false) |
| | |
| | | public static JSONObject getUserInfo(String token) { |
| | | String url = ip + "/cpn/api/extral/applicationCode/getUserInfoByToken"; |
| | | JSONObject json = new JSONObject(); |
| | | json.put("appID", appId); |
| | | json.put("appID", APP_ID); |
| | | HashMap<String, String> header = getPostHeader(json.toString()); |
| | | header.put("Authorization", token); |
| | | String body = HttpRequest.post(url) |