|  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.FebsResponse; | 
|---|
|  |  |  | import cc.mrbird.febs.common.exception.FebsException; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.LoginUserUtil; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.RedisUtils; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.conversion.MallAddressInfoConversion; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.AddressInfoDto; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.ApiIdentifyAddressDto; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallAddressInfo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallMember; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.MallAddressInfoMapper; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IApiMallAddressInfoService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.AddressInfoVo; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.util.WechatConfigure; | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.json.JSONObject; | 
|---|
|  |  |  | import cn.hutool.json.JSONUtil; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import okhttp3.*; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @RequiredArgsConstructor | 
|---|
|  |  |  | public class ApiMallAddressInfoServiceImpl extends ServiceImpl<MallAddressInfoMapper, MallAddressInfo> implements IApiMallAddressInfoService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisUtils redisUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<AddressInfoVo> findAddressInfoList() { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.baseMapper.updateIsDefault(MallAddressInfo.IS_DEFAULT_Y, member.getId(), id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse identifyAddress(ApiIdentifyAddressDto identifyAddressDto) { | 
|---|
|  |  |  | MediaType mediaType = MediaType.parse("application/json"); | 
|---|
|  |  |  | RequestBody body = RequestBody.create(mediaType, JSONUtil.toJsonStr(identifyAddressDto)); | 
|---|
|  |  |  | Request request = new Request.Builder() | 
|---|
|  |  |  | .url("https://aip.baidubce.com/rpc/2.0/nlp/v1/address?access_token=" + redisUtils.get(WechatConfigure.BAIDU_ACCESS_TOKEN_REDIS_KEY).toString()) | 
|---|
|  |  |  | .method("POST", body) | 
|---|
|  |  |  | .addHeader("Content-Type", "application/json") | 
|---|
|  |  |  | .addHeader("Accept", "application/json") | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  | String data = ""; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Response response = HTTP_CLIENT.newCall(request).execute(); | 
|---|
|  |  |  | data = response.body().string(); | 
|---|
|  |  |  | if (data.contains("error_code")) { | 
|---|
|  |  |  | JSONObject jsonObject = JSONUtil.parseObj(data); | 
|---|
|  |  |  | return new FebsResponse().fail().message("地址识别错误编码:"+jsonObject.get("error_code").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new FebsResponse().success().data(data); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|