1、后端实现测速网获取ip信息接口,暂时无效
This commit is contained in:
parent
9517158900
commit
059c89a086
|
|
@ -17,10 +17,6 @@
|
|||
v-model="weatherVisible">
|
||||
<table style="text-align: center" v-loading="loading">
|
||||
<td v-for="(cast,index) in forecastWeatherData.casts" width="100px">
|
||||
<tr>{{cast.dayweather}}</tr>
|
||||
<tr>
|
||||
{{cast.nighttemp+"℃~"+cast.daytemp+"℃"}}
|
||||
</tr>
|
||||
<tr v-if="index===0">
|
||||
今天
|
||||
</tr>
|
||||
|
|
@ -33,7 +29,10 @@
|
|||
<tr v-if="index===3">
|
||||
大后天
|
||||
</tr>
|
||||
|
||||
<tr>{{cast.dayweather}}</tr>
|
||||
<tr>
|
||||
{{cast.nighttemp+"℃~"+cast.daytemp+"℃"}}
|
||||
</tr>
|
||||
<tr v-if="cast.week==='1'">
|
||||
星期一
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
<template>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "index"
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
|
@ -44,8 +44,12 @@ public class ApiConst {
|
|||
|
||||
public static final String ROLL_IP = "ROLL-IP信息";
|
||||
|
||||
public static final String SPEED_TEST_IP = "测速网-IP信息";
|
||||
|
||||
public static final String GAODE_WEATHER = "高德-天气预报";
|
||||
|
||||
public static final String ROLL_HOLIDAYS = "ROLL-节假日";
|
||||
|
||||
|
||||
//-------------------url------------------------------
|
||||
|
||||
|
|
@ -83,12 +87,18 @@ public class ApiConst {
|
|||
|
||||
public static final String ROLL_IP_URL = "https://www.mxnzp.com/api/ip/aim_ip";
|
||||
|
||||
public static final String SPEED_TEST_IP_URL = "https://api-v3-ipv6.speedtest.cn/ip";
|
||||
|
||||
/**
|
||||
* 接口文档:
|
||||
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo
|
||||
* 接口文档:https://lbs.amap.com/api/webservice/guide/api/weatherinfo
|
||||
*/
|
||||
public static final String GAODE_WEATHER_URL = "https://restapi.amap.com/v3/weather/weatherInfo";
|
||||
|
||||
/**
|
||||
* 接口文档:https://www.mxnzp.com/doc/detail?id=1
|
||||
*/
|
||||
public static final String ROLL_HOLIDAYS_URL = "https://www.mxnzp.com/api/holiday/recent/list";
|
||||
|
||||
|
||||
//-----------------------api请求参数常量-----------------------------
|
||||
|
||||
|
|
@ -109,6 +119,12 @@ public class ApiConst {
|
|||
* roll平台返回值code成功参数
|
||||
*/
|
||||
public static final Integer ROLL_CODE_SUCCESS = 1;
|
||||
/**
|
||||
* speedtest平台返回值code成功参数
|
||||
*/
|
||||
public static final Integer SPEED_TEST_CODE_SUCCESS = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 高德返回值infocode
|
||||
|
|
@ -121,11 +137,11 @@ public class ApiConst {
|
|||
/**
|
||||
* 高德返回值lives名称(需要的天气参数) (实时天气数据)
|
||||
*/
|
||||
public static final String LIVES= "lives";
|
||||
public static final String LIVES = "lives";
|
||||
/**
|
||||
* 高德返回值forecasts名称(预报天气数据)
|
||||
*/
|
||||
public static final String FORECASTS= "forecasts";
|
||||
public static final String FORECASTS = "forecasts";
|
||||
|
||||
|
||||
//---------------------自定义相关请求响应常量----------------------------
|
||||
|
|
@ -136,4 +152,9 @@ public class ApiConst {
|
|||
public static final String DEMOTE_ERROR = "error";
|
||||
|
||||
|
||||
//--------------------其他常量------------------------------
|
||||
|
||||
public static final String LOCAL_IP = "127.0.0.1";
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.xjs.apitools.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* api小工具控制器
|
||||
* @author xiejs
|
||||
* @since 2022-01-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("apitools")
|
||||
@Api(tags = "业务模块-API小工具")
|
||||
@Log4j2
|
||||
public class ApiToolsController {
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.xjs.apitools.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 节假日api 实体
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-17
|
||||
*/
|
||||
@Data
|
||||
public class ApiHoliday implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 节日日期
|
||||
*/
|
||||
private String date;
|
||||
|
||||
/**
|
||||
* 节日农历日期
|
||||
*/
|
||||
private String lunarDate;
|
||||
|
||||
/**
|
||||
* 节日名称
|
||||
*/
|
||||
private String holidayName;
|
||||
|
||||
/**
|
||||
* 距离今日的天数,已经过的节日为负数
|
||||
*/
|
||||
private Integer residueDays;
|
||||
|
||||
/**
|
||||
* 是否是农历节日
|
||||
*/
|
||||
private Boolean lunarHoliday;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.xjs.apitools.factory;
|
||||
|
||||
|
||||
/**
|
||||
* api工具工厂接口
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-17
|
||||
*/
|
||||
public interface ApiToolsFactory<T, R> {
|
||||
|
||||
|
||||
/**
|
||||
* 获取api数据工厂方法 (无参)
|
||||
*
|
||||
* @return T
|
||||
*/
|
||||
default T ApiData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取api数据工厂方法 (有参)
|
||||
*
|
||||
* @param req 请求参数
|
||||
* @return T
|
||||
*/
|
||||
default T ApiData(R req) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.xjs.apitools.factory.impl;
|
||||
|
||||
import com.xjs.apitools.domain.ApiHoliday;
|
||||
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||
import com.xjs.config.RollProperties;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* roll平台获取节假日api工厂实现
|
||||
* @author xiejs
|
||||
* @since 2022-01-17
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class RollHolidayFactory implements ApiToolsFactory<ApiHoliday,Object> {
|
||||
|
||||
@Autowired
|
||||
private RollProperties rollProperties;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ApiHoliday ApiData() {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.xjs.common.client.api.speedtest;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xjs.annotation.ApiLog;
|
||||
import com.xjs.common.client.factory.SpeedTestIPFeignFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import static com.xjs.consts.ApiConst.SPEED_TEST_IP;
|
||||
import static com.xjs.consts.ApiConst.SPEED_TEST_IP_URL;
|
||||
|
||||
/**
|
||||
* https://myplugin.speedtest.cn/#/ 测速网
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-17
|
||||
*/
|
||||
@FeignClient(name = "speedTestIP", url = SPEED_TEST_IP_URL,fallbackFactory = SpeedTestIPFeignFactory.class)
|
||||
public interface SpeedTestIPFeignClient {
|
||||
|
||||
@GetMapping()
|
||||
@ApiLog(name = SPEED_TEST_IP,
|
||||
url = SPEED_TEST_IP_URL,
|
||||
method = "Get")
|
||||
JSONObject IpApi(@RequestParam("ipv4") String requestBody);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.xjs.common.client.factory;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.common.client.api.speedtest.SpeedTestIPFeignClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-17
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class SpeedTestIPFeignFactory implements FallbackFactory<SpeedTestIPFeignClient> {
|
||||
@Override
|
||||
public SpeedTestIPFeignClient create(Throwable cause) {
|
||||
log.error("api模块 测速网 IP服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -12,8 +12,9 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.xjs.consts.ApiConst.*;
|
||||
import static com.xjs.consts.RedisConst.IP_INFO;
|
||||
|
||||
/**
|
||||
|
|
@ -36,11 +37,8 @@ public class RollIPFactory implements IPFactory<IPInfoVo> {
|
|||
@Override
|
||||
public IPInfoVo IpApi() {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
try {
|
||||
requestBody.setIp(IPUtils.getV4IP());
|
||||
} catch (Exception e) {
|
||||
requestBody.setIp("127.0.0.1");
|
||||
}
|
||||
String ip = Optional.ofNullable(IPUtils.getV4IP()).orElse(LOCAL_IP);
|
||||
requestBody.setIp(ip);
|
||||
requestBody.setApp_id(rollProperties.getApp_id());
|
||||
requestBody.setApp_secret(rollProperties.getApp_secret());
|
||||
JSONObject jsonObject = rollIPFeignClient.IpApi(requestBody);
|
||||
|
|
@ -49,9 +47,9 @@ public class RollIPFactory implements IPFactory<IPInfoVo> {
|
|||
return data.toJavaObject(IPInfoVo.class);
|
||||
} else {
|
||||
log.error("天行全网热搜服务调用成功,但返回异常");
|
||||
if (redisService.hasKey(IP_INFO)){
|
||||
if (redisService.hasKey(IP_INFO)) {
|
||||
return (IPInfoVo) redisService.getCacheObject(IP_INFO);
|
||||
}else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package com.xjs.weather.factory.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xjs.common.client.api.speedtest.SpeedTestIPFeignClient;
|
||||
import com.xjs.utils.IPUtils;
|
||||
import com.xjs.weather.domain.IPInfoVo;
|
||||
import com.xjs.weather.factory.IPFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.xjs.consts.ApiConst.*;
|
||||
|
||||
/**
|
||||
* 测速网 IP信息查询API工厂实现 (主要获取ipv6)
|
||||
* @author xiejs
|
||||
* @since 2022-01-17
|
||||
*/
|
||||
@Component
|
||||
public class SpeedTestIPFactory implements IPFactory<IPInfoVo> {
|
||||
|
||||
@Autowired
|
||||
private SpeedTestIPFeignClient speedTestIPFeignClient;
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public IPInfoVo IpApi() {
|
||||
String v4IP = IPUtils.getV4IP();
|
||||
String ip = Optional.ofNullable(v4IP).orElse(LOCAL_IP);
|
||||
JSONObject jsonObject = speedTestIPFeignClient.IpApi(ip);
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == SPEED_TEST_CODE_SUCCESS.intValue()) {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
IPInfoVo ipInfoVo = new IPInfoVo();
|
||||
ipInfoVo.setCity(data.getString("city"));
|
||||
ipInfoVo.setIp(data.getString("ip"));
|
||||
ipInfoVo.setIsp(data.getString("isp"));
|
||||
ipInfoVo.setProvince(data.getString("province"));
|
||||
System.out.println("json!!!"+data.toJSONString());
|
||||
return ipInfoVo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ import com.xjs.copywriting.service.CopyWritingService;
|
|||
import com.xjs.oneenglish.domain.ApiEnglish;
|
||||
import com.xjs.oneenglish.domain.RequestBody;
|
||||
import com.xjs.oneenglish.factory.impl.TianXingOneEnglishFactory;
|
||||
import com.xjs.weather.domain.IPInfoVo;
|
||||
import com.xjs.weather.factory.impl.SpeedTestIPFactory;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
|
|
@ -34,6 +36,9 @@ class TianXingOneEnglishFactoryTest {
|
|||
@Autowired
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
@Autowired
|
||||
private SpeedTestIPFactory speedTestIPFactory;
|
||||
|
||||
@Test
|
||||
void getOneEnglish() {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
|
|
@ -42,6 +47,11 @@ class TianXingOneEnglishFactoryTest {
|
|||
System.out.println(oneEnglish);
|
||||
}
|
||||
|
||||
@Test
|
||||
void ip() {
|
||||
IPInfoVo ipInfoVo = speedTestIPFactory.IpApi();
|
||||
System.out.println(ipInfoVo.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void insert() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue