邮编查询
parent
2bab7b1fbe
commit
56c5bb26fd
|
@ -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:Postcode
|
||||||
|
* @Date:2024/8/25 11:04
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Postcode {
|
||||||
|
private String postcode;
|
||||||
|
private Integer page;
|
||||||
|
private Integer pagesize;
|
||||||
|
private String dtype;
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import com.muyu.common.core.web.controller.BaseController;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
import com.muyu.domain.Birthday;
|
import com.muyu.domain.Birthday;
|
||||||
import com.muyu.domain.Market;
|
import com.muyu.domain.Market;
|
||||||
|
import com.muyu.domain.Postcode;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -80,5 +81,12 @@ public class MarketController extends BaseController {
|
||||||
public Result getBirthday(@RequestBody Birthday birthday){
|
public Result getBirthday(@RequestBody Birthday birthday){
|
||||||
return marketService.getBirthday(birthday);
|
return marketService.getBirthday(birthday);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 邮编查询
|
||||||
|
*/
|
||||||
|
@PostMapping("getPostcode")
|
||||||
|
public Result getPostcode(@RequestBody Postcode postcode){
|
||||||
|
return marketService.getPostcode(postcode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.domain.Birthday;
|
import com.muyu.domain.Birthday;
|
||||||
import com.muyu.domain.Market;
|
import com.muyu.domain.Market;
|
||||||
|
import com.muyu.domain.Postcode;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -26,4 +27,6 @@ public interface MarketService extends IService<Market> {
|
||||||
Result getWeather();
|
Result getWeather();
|
||||||
|
|
||||||
Result getBirthday(Birthday birthday);
|
Result getBirthday(Birthday birthday);
|
||||||
|
|
||||||
|
Result getPostcode(Postcode postcode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.domain.Birthday;
|
import com.muyu.domain.Birthday;
|
||||||
import com.muyu.domain.Market;
|
import com.muyu.domain.Market;
|
||||||
import com.muyu.domain.PhonePlace;
|
import com.muyu.domain.PhonePlace;
|
||||||
|
import com.muyu.domain.Postcode;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
@ -106,4 +107,12 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
||||||
StringBuffer stringBuffer = BirthdayHelper.queryBirthday(birthday);
|
StringBuffer stringBuffer = BirthdayHelper.queryBirthday(birthday);
|
||||||
return Result.success(stringBuffer);
|
return Result.success(stringBuffer);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 邮编查询
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result getPostcode(Postcode postcode) {
|
||||||
|
StringBuffer stringBuffer = PostcodeInquire.queryPostcode(postcode);
|
||||||
|
return Result.success(stringBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.stream.Collectors;
|
||||||
* @Project:cloud-mart
|
* @Project:cloud-mart
|
||||||
* @name:BirthdayHelper
|
* @name:BirthdayHelper
|
||||||
* @Date:2024/8/24 19:36
|
* @Date:2024/8/24 19:36
|
||||||
|
* 生辰助手
|
||||||
*/
|
*/
|
||||||
public class BirthdayHelper {
|
public class BirthdayHelper {
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import static com.muyu.cloud.mart.config.IPLocation.params;
|
||||||
* @Project:cloud-mart
|
* @Project:cloud-mart
|
||||||
* @name:Headlines
|
* @name:Headlines
|
||||||
* @Date:2024/8/24 18:39
|
* @Date:2024/8/24 18:39
|
||||||
|
* 新闻头条
|
||||||
*/
|
*/
|
||||||
public class Headlines {
|
public class Headlines {
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.stream.Collectors;
|
||||||
* @Project:cloud-mart
|
* @Project:cloud-mart
|
||||||
* @name:IPLocation
|
* @name:IPLocation
|
||||||
* @Date:2024/8/23 20:54
|
* @Date:2024/8/23 20:54
|
||||||
|
* IP查询归属地
|
||||||
*/
|
*/
|
||||||
public class IPLocation {
|
public class IPLocation {
|
||||||
public static StringBuffer queryIPLocation(String ip){
|
public static StringBuffer queryIPLocation(String ip){
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.cloud.mart.utils;
|
package com.muyu.cloud.mart.utils;
|
||||||
|
|
||||||
|
import com.muyu.domain.Postcode;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
@ -18,16 +20,17 @@ import java.util.stream.Collectors;
|
||||||
*/
|
*/
|
||||||
public class PostcodeInquire {
|
public class PostcodeInquire {
|
||||||
|
|
||||||
public static StringBuffer queryPostcode(){
|
public static StringBuffer queryPostcode(Postcode postcode){
|
||||||
String apiKey = "0cabcd31c150369d8afb2c8b7e41a2c0";
|
String apiKey = "0cabcd31c150369d8afb2c8b7e41a2c0";
|
||||||
String apiUrl = "http://v.juhe.cn/postcode/query";
|
String apiUrl = "http://v.juhe.cn/postcode/query";
|
||||||
|
|
||||||
HashMap<String, String> map = new HashMap<>();
|
HashMap<String, String> map = new HashMap<>();
|
||||||
map.put("key", apiKey);
|
map.put("key", apiKey);
|
||||||
map.put("postcode", "xxx");
|
map.put("postcode", postcode.getPostcode());//邮编,如:215001
|
||||||
map.put("page", "20");
|
postcode.setPostcode(map.put("postcode", postcode.getPostcode()));
|
||||||
map.put("pagesize", "");
|
map.put("page", String.valueOf(postcode.getPage()));//页数,默认1
|
||||||
map.put("dtype", "json");
|
map.put("pagesize", "");//每页返回,默认:20,最大不超过50
|
||||||
|
map.put("dtype", "json");//返回数据的格式,xml或json,默认json
|
||||||
try {
|
try {
|
||||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
||||||
* @Project:cloud-mart
|
* @Project:cloud-mart
|
||||||
* @name:Weather
|
* @name:Weather
|
||||||
* @Date:2024/8/24 18:51
|
* @Date:2024/8/24 18:51
|
||||||
|
* 气象预警
|
||||||
*/
|
*/
|
||||||
public class Weather {
|
public class Weather {
|
||||||
public static StringBuffer queryWeather() {
|
public static StringBuffer queryWeather() {
|
||||||
|
|
Loading…
Reference in New Issue