Compare commits
4 Commits
bc97dc7f89
...
6a324ff5e1
Author | SHA1 | Date |
---|---|---|
|
6a324ff5e1 | |
|
ef47644c0b | |
|
4ab69a8887 | |
|
92f0018697 |
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.domain
|
||||
* @Project:cloud-mart
|
||||
* @name:BirthdayHelper
|
||||
* @Date:2024/8/24 19:37
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Birthday {
|
||||
private String year;
|
||||
private String month;
|
||||
private String day;
|
||||
private String hour;
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.muyu.cloud.mart.service.MarketService;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.domain.Birthday;
|
||||
import com.muyu.domain.Market;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
@ -65,5 +66,19 @@ public class MarketController extends BaseController {
|
|||
public Result getHeadlines(){
|
||||
return marketService.getHeadlines();
|
||||
}
|
||||
/**
|
||||
* 气象预警
|
||||
*/
|
||||
@GetMapping("getWeather")
|
||||
public Result getWeather(){
|
||||
return marketService.getWeather();
|
||||
}
|
||||
/**
|
||||
* 生辰助手
|
||||
*/
|
||||
@PostMapping("getBirthday")
|
||||
public Result getBirthday(@RequestBody Birthday birthday){
|
||||
return marketService.getBirthday(birthday);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.cloud.mart.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.Birthday;
|
||||
import com.muyu.domain.Market;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -21,4 +22,8 @@ public interface MarketService extends IService<Market> {
|
|||
Result getIpPlace(String ip);
|
||||
|
||||
Result getHeadlines();
|
||||
|
||||
Result getWeather();
|
||||
|
||||
Result getBirthday(Birthday birthday);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package com.muyu.cloud.mart.service.impl;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.muyu.cloud.mart.utils.IPLocation;
|
||||
import com.muyu.cloud.mart.utils.MobileLocation;
|
||||
import com.muyu.cloud.mart.utils.*;
|
||||
import com.muyu.cloud.mart.mapper.MarketMapper;
|
||||
import com.muyu.cloud.mart.service.MarketService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.Birthday;
|
||||
import com.muyu.domain.Market;
|
||||
import com.muyu.domain.PhonePlace;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -78,7 +78,7 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
|||
*/
|
||||
@Override
|
||||
public Result getIpPlace(String ip) {
|
||||
StringBuffer stringBuffer = IPLocation.queryMobileLocation(ip);
|
||||
StringBuffer stringBuffer = IPLocation.queryIPLocation(ip);
|
||||
return Result.success(stringBuffer);
|
||||
}
|
||||
/**
|
||||
|
@ -87,28 +87,21 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
|||
*/
|
||||
@Override
|
||||
public Result getHeadlines() {
|
||||
String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b";
|
||||
String apiUrl = "http://v.juhe.cn/toutiao/index";
|
||||
StringBuffer stringBuffer = Headlines.queryHeadlines();
|
||||
return Result.success(stringBuffer);
|
||||
}
|
||||
/**
|
||||
* 气象预警
|
||||
*/
|
||||
@Override
|
||||
public Result getWeather() {
|
||||
StringBuffer stringBuffer = Weather.queryWeather();
|
||||
return Result.success(stringBuffer);
|
||||
}
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("key", apiKey);
|
||||
map.put("type", "top");
|
||||
map.put("page", "20");
|
||||
map.put("page_size", "");
|
||||
map.put("is_filter", "");
|
||||
try {
|
||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
System.out.println(response);
|
||||
return Result.success(response);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@Override
|
||||
public Result getBirthday(Birthday birthday) {
|
||||
StringBuffer stringBuffer = BirthdayHelper.queryBirthday(birthday);
|
||||
return Result.success(stringBuffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.cloud.mart.utils;
|
||||
|
||||
import com.muyu.domain.Birthday;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.utils
|
||||
* @Project:cloud-mart
|
||||
* @name:BirthdayHelper
|
||||
* @Date:2024/8/24 19:36
|
||||
*/
|
||||
public class BirthdayHelper {
|
||||
|
||||
public static StringBuffer queryBirthday(Birthday birthday){
|
||||
String apiKey = "9bbfc46233d4931c39207b090ed4b27c";
|
||||
String apiUrl = "http://apis.juhe.cn/birthEight/query";
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
map.put("key", apiKey);
|
||||
map.put("year", birthday.getYear());
|
||||
birthday.setYear(map.put("year", birthday.getYear()));
|
||||
map.put("month", birthday.getMonth());
|
||||
birthday.setMonth(map.put("month", birthday.getMonth()));
|
||||
map.put("day", birthday.getDay());
|
||||
birthday.setDay(map.put("day", birthday.getDay()));
|
||||
map.put("hour", birthday.getHour());
|
||||
birthday.setHour(map.put("hour", birthday.getHour()));
|
||||
try {
|
||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
System.out.println(response);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String params(Map<String, String> map) {
|
||||
return map.entrySet().stream()
|
||||
.map(entry -> {
|
||||
try {
|
||||
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return entry.getKey() + "=" + entry.getValue();
|
||||
}
|
||||
})
|
||||
.collect(Collectors.joining("&"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.cloud.mart.utils;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.muyu.cloud.mart.config.IPLocation.params;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.utils
|
||||
* @Project:cloud-mart
|
||||
* @name:Headlines
|
||||
* @Date:2024/8/24 18:39
|
||||
*/
|
||||
public class Headlines {
|
||||
|
||||
public static StringBuffer queryHeadlines(){
|
||||
String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b";
|
||||
String apiUrl = "http://v.juhe.cn/toutiao/index";
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("key", apiKey);
|
||||
map.put("type", "top");
|
||||
map.put("page", "20");
|
||||
map.put("page_size", "");
|
||||
map.put("is_filter", "");
|
||||
try {
|
||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
System.out.println(response);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ import java.util.stream.Collectors;
|
|||
* @Date:2024/8/23 20:54
|
||||
*/
|
||||
public class IPLocation {
|
||||
public static StringBuffer queryMobileLocation(String ip){
|
||||
public static StringBuffer queryIPLocation(String ip){
|
||||
String apiKey = "e84b7d13a9fb87b4ebcc9813e4518955";
|
||||
String apiUrl = "http://apis.juhe.cn/ip/ipNewV3";
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
|
|
@ -28,7 +28,7 @@ public class MobileLocation {
|
|||
|
||||
/**
|
||||
* 根据手机号码/手机号码前7位查询号码归属地
|
||||
* @param mobile
|
||||
* @param tel
|
||||
*/
|
||||
public static PhonePlace queryMobileLocation(String tel)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.muyu.cloud.mart.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.utils
|
||||
* @Project:cloud-mart
|
||||
* @name:Weather
|
||||
* @Date:2024/8/24 18:51
|
||||
*/
|
||||
public class Weather {
|
||||
public static StringBuffer queryWeather() {
|
||||
String apiKey = "80e78ee9adaded8b1f42ec9cbdf69ac9";
|
||||
String apiUrl = "https://apis.juhe.cn/fapig/alarm/citys";
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("key", apiKey);
|
||||
try {
|
||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
System.out.println(response);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
public static String params(Map<String, String> map) {
|
||||
return map.entrySet().stream()
|
||||
.map(entry -> {
|
||||
try {
|
||||
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return entry.getKey() + "=" + entry.getValue();
|
||||
}
|
||||
})
|
||||
.collect(Collectors.joining("&"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue