Pu Zhibing
2024-12-20 cfa99810755c521a096388234fbed8dc820cba24
修改菜单功能
4个文件已修改
4个文件已添加
341 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/RegionClientFallbackFactory.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/RegionClient.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/SMSUtil.java 178 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/tencentMap/TencentMapUtil.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/ExpressDeliveryUtil.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/RegionController.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/RegionClientFallbackFactory.java
New file
@@ -0,0 +1,22 @@
package com.ruoyi.other.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.Region;
import com.ruoyi.other.api.feignClient.RegionClient;
import org.springframework.cloud.openfeign.FallbackFactory;
/**
 * @author zhibing.pu
 * @Date 2024/12/19 10:02
 */
public class RegionClientFallbackFactory implements FallbackFactory<RegionClient>  {
    @Override
    public RegionClient create(Throwable cause) {
        return new RegionClient() {
            @Override
            public R<Region> getRegionBiCode(String code) {
                return R.fail("根据城市编号查询行政区域数据失败:" + cause.getMessage());
            }
        };
    }
}
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/RegionClient.java
New file
@@ -0,0 +1,26 @@
package com.ruoyi.other.api.feignClient;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.Region;
import com.ruoyi.other.api.factory.RegionClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * @author zhibing.pu
 * @Date 2024/12/19 10:01
 */
@FeignClient(contextId = "RegionClient", value = ServiceNameConstants.OTHER_SERVICE, fallbackFactory = RegionClientFallbackFactory.class)
public interface RegionClient {
    /**
     * 根据城市编号查询行政区域数据
     * @param code
     * @return
     */
    @PostMapping("/region/getRegionBiCode")
    R<Region> getRegionBiCode(@RequestParam("code") String code);
}
ruoyi-api/ruoyi-api-other/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -16,3 +16,4 @@
com.ruoyi.other.api.factory.PointSettingClientFallbackFactory
com.ruoyi.other.api.factory.VipGoodClientFallbackFactory
com.ruoyi.other.api.factory.VipSettingClientFallbackFactory
com.ruoyi.other.api.factory.RegionClientFallbackFactory
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java
@@ -15,6 +15,8 @@
import com.ruoyi.account.service.AppUserShopService;
import com.ruoyi.account.service.UserChangeLogService;
import com.ruoyi.account.service.UserPointService;
import com.ruoyi.account.util.SMSUtil;
import com.ruoyi.account.util.tencentMap.TencentMapUtil;
import com.ruoyi.account.util.weChat.EnvVersion;
import com.ruoyi.account.util.weChat.WXCore;
import com.ruoyi.account.util.weChat.WeChatUtil;
@@ -24,9 +26,11 @@
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.PointSetting;
import com.ruoyi.other.api.domain.Region;
import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.api.feignClient.PointSettingClient;
import com.ruoyi.other.api.feignClient.RegionClient;
import com.ruoyi.other.api.feignClient.ShopClient;
import com.ruoyi.other.api.feignClient.VipSettingClient;
import com.ruoyi.system.api.domain.SysUser;
@@ -96,6 +100,9 @@
    @Autowired
    private AppUserMapper appUserMapper;
    @Resource
    private RegionClient regionClient;
    /**
     * 小程序一键登录
@@ -155,11 +162,10 @@
     */
    @Override
    public R<LoginVo> mobileLogin(MobileLogin mobileLogin) {
        //校验验证码  TODO 待完善
//        String code = redisService.getCacheObject(mobileLogin.getPhone());
//        if(null == code || !code.equals(mobileLogin.getCode())){
//            return R.fail("验证码错误");
//        }
        String code = redisService.getCacheObject(mobileLogin.getPhone());
        if(null == code || !code.equals(mobileLogin.getCode())){
            return R.fail("验证码错误");
        }
        
        //查询用户是否注册,没有注册则跳转到注册页面
        AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, mobileLogin.getPhone()).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0));
@@ -198,7 +204,7 @@
     */
    @Override
    public R getSMSCode(SMSCode smsCode) {
        //校验验证码获取评率(1分钟5次)
        //校验验证码获取频率(1分钟5次)
        String key = smsCode.getType() + "&" + smsCode.getPhone();
        Map<String, Object> cacheMap = redisService.getCacheMap(key);
        if(null != cacheMap){
@@ -226,7 +232,7 @@
        for (int i = 0; i < 6; i++) {
            code += Double.valueOf(Math.random() * 10).intValue();
        }
        //发送短信 todo 待对接短信
        SMSUtil.sendSms("[\"" + code + "\"]", smsCode.getPhone(), "8824121211029", "39533d100b2b4aee8ed198aa49fe99dd");
        return R.ok();
    }
    
@@ -238,12 +244,11 @@
     */
    @Override
    public R<LoginVo> registerAccount(RegisterAccount registerAccount) {
        //  TODO 待完善
        //校验验证码
//        String code = redisService.getCacheObject(registerAccount.getPhone());
//        if(null == code || !code.equals(registerAccount.getCode())){
//            return R.fail("验证码错误");
//        }
        String code = redisService.getCacheObject(registerAccount.getPhone());
        if(null == code || !code.equals(registerAccount.getCode())){
            return R.fail("验证码错误");
        }
        //使用jscode获取微信openid
        Map<String, Object> map = weChatUtil.code2Session(registerAccount.getJscode());
        Integer errcode = Integer.valueOf(map.get("errcode").toString());
@@ -318,13 +323,19 @@
            appUser.setChangePromoter(0);
            appUser.setLongitude(registerAccount.getLongitude());
            appUser.setLatitude(registerAccount.getLatitude());
            //调用地图获取省市区数据  TODO 待完善
//            appUser.setProvince();
//            appUser.setProvinceCode();
//            appUser.setCity();
//            appUser.setCityCode();
//            appUser.setDistrict();
//            appUser.setDistrictCode();
            //调用地图获取省市区数据
            String citycode = TencentMapUtil.inverseGeographicalAnalysis(registerAccount.getLongitude(), registerAccount.getLatitude(), false);
            if(null != citycode){
                Region region = regionClient.getRegionBiCode(citycode).getData();
                appUser.setDistrict(region.getName());
                appUser.setDistrictCode(citycode);
                region = regionClient.getRegionBiCode(citycode.substring(0, 3) + "00").getData();
                appUser.setCity(region.getName());
                appUser.setCityCode(region.getCode());
                region = regionClient.getRegionBiCode(citycode.substring(0, 2) + "0000").getData();
                appUser.setProvince(region.getName());
                appUser.setProvinceCode(region.getCode());
            }
            this.save(appUser);
            //增加积分变动记录
            if(getRegisPoint1 > 0){
@@ -529,12 +540,14 @@
    @Override
    public List<NearbyReferrerVo> getNearbyReferrer(NearbyReferrer nearbyReferrer) {
        //使用地图获取省市区数据
        String longitude = nearbyReferrer.getLongitude();
        String latitude = nearbyReferrer.getLatitude();
        String cityCode = "510100"; // TODO 待完善
        String citycode = TencentMapUtil.inverseGeographicalAnalysis(nearbyReferrer.getLongitude(), nearbyReferrer.getLatitude(), false);
        if(null != citycode){
            String cityCode = citycode.substring(0, 3) + "00";
        List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(cityCode, nearbyReferrer);
        return list;
    }
        return null;
    }
    @Override
    public List<AppUser> getUserAncestorList(Long id, List<AppUser> list) {
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/SMSUtil.java
New file
@@ -0,0 +1,178 @@
package com.ruoyi.account.util;
import com.obs.services.ObsClient;
import com.obs.services.model.ObjectMetadata;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @author zhibing.pu
 * @Date 2024/12/19 9:11
 */
public class SMSUtil {
    //无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值
    private static final String WSSE_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\"";
    //无需修改,用于格式化鉴权头域,给"Authorization"参数赋值
    private static final String AUTH_HEADER_VALUE = "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\"";
    /**
     * 调用短信
     * @param code  入参
     * @param phone 接收短信手机号
     * @param sender 国内短信签名通道号或国际/港澳台短信通道号
     * @param templateId  模板ID
     * @throws Exception
     */
    public static void sendSms(String code,String phone,String sender,String templateId) {
        try {
            //必填,请参考"开发准备"获取如下数据,替换为实际值
            String url = "https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1"; //APP接入地址+接口访问URI
            String appKey = "wnFcPPf6B7EwrVCzGE5uRcwM8tmP"; //APP_Key
            String appSecret = "Dw905FxIxX3CzYBeEO7htBRdqDB2"; //APP_Secret
            //条件必填,国内短信关注,当templateId指定的模板类型为通用模板时生效且必填,必须是已审核通过的,与模板类型一致的签名名称
            //国际/港澳台短信不用关注该参数
            String signature = "岐济生健康数字家园"; //签名名称
            //必填,全局号码格式(包含国家码),示例:+8615123456789,多个号码之间用英文逗号分隔
            String receiver = "+86" + phone; //短信接收人号码
            //选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告
            String statusCallBack = "";
            /**
             * 选填,使用无变量模板时请赋空值 String templateParas = "";
             * 单变量模板示例:模板内容为"您的验证码是${NUM_6}"时,templateParas可填写为"[\"369751\"]"
             * 双变量模板示例:模板内容为"您有${NUM_2}件快递请到${TXT_20}领取"时,templateParas可填写为"[\"3\",\"人民公园正门\"]"
             * ${DATE}${TIME}变量不允许取值为空,${TXT_20}变量可以使用英文空格或点号替代空值,${NUM_6}变量可以使用0替代空值
             * 查看更多模板和变量规范:产品介绍>模板和变量规范
             */
            String templateParas = code; //模板变量
            //请求Body,不携带签名名称时,signature请填null
            String body = buildRequestBody(sender, receiver, templateId, templateParas, statusCallBack, signature);
            if (null == body || body.isEmpty()) {
                System.out.println("body is null.");
                return;
            }
            //请求Headers中的X-WSSE参数值
            String wsseHeader = buildWsseHeader(appKey, appSecret);
            if (null == wsseHeader || wsseHeader.isEmpty()) {
                System.out.println("wsse header is null.");
                return;
            }
            //如果JDK版本低于1.8,可使用如下代码
            //为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题
            //CloseableHttpClient client = HttpClients.custom()
            //        .setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
            //            @Override
            //            public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
            //                return true;
            //            }
            //        }).build()).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
            //如果JDK版本是1.8,可使用如下代码
            //为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题
            CloseableHttpClient client = HttpClients.custom()
                    .setSSLContext(new SSLContextBuilder().loadTrustMaterial(null,
                            (x509CertChain, authType) -> true).build())
                    .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                    .build();
            HttpResponse response = client.execute(RequestBuilder.create("POST")//请求方法POST
                    .setUri(url)
                    .addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded")
                    .addHeader(HttpHeaders.AUTHORIZATION, AUTH_HEADER_VALUE)
                    .addHeader("X-WSSE", wsseHeader)
                    .setEntity(new StringEntity(body)).build());
            System.out.println(response.toString()); //打印响应头域信息
            System.out.println(EntityUtils.toString(response.getEntity())); //打印响应消息实体
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 构造请求Body体
     * @param sender
     * @param receiver
     * @param templateId
     * @param templateParas
     * @param statusCallbackUrl
     * @param signature | 签名名称,使用国内短信通用模板时填写
     * @return
     */
    static String buildRequestBody(String sender, String receiver, String templateId, String templateParas,
                                   String statusCallbackUrl, String signature) {
        if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty()
                || templateId.isEmpty()) {
            System.out.println("buildRequestBody(): sender, receiver or templateId is null.");
            return null;
        }
        List<NameValuePair> keyValues = new ArrayList<NameValuePair>();
        keyValues.add(new BasicNameValuePair("from", sender));
        keyValues.add(new BasicNameValuePair("to", receiver));
        keyValues.add(new BasicNameValuePair("templateId", templateId));
        if (null != templateParas && !templateParas.isEmpty()) {
            keyValues.add(new BasicNameValuePair("templateParas", templateParas));
        }
        if (null != statusCallbackUrl && !statusCallbackUrl.isEmpty()) {
            keyValues.add(new BasicNameValuePair("statusCallback", statusCallbackUrl));
        }
        if (null != signature && !signature.isEmpty()) {
            keyValues.add(new BasicNameValuePair("signature", signature));
        }
        return URLEncodedUtils.format(keyValues, Charset.forName("UTF-8"));
    }
    /**
     * 构造X-WSSE参数值
     * @param appKey
     * @param appSecret
     * @return
     */
    static String buildWsseHeader(String appKey, String appSecret) {
        if (null == appKey || null == appSecret || appKey.isEmpty() || appSecret.isEmpty()) {
            System.out.println("buildWsseHeader(): appKey or appSecret is null.");
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        String time = sdf.format(new Date()); //Created
        String nonce = UUID.randomUUID().toString().replace("-", ""); //Nonce
        byte[] passwordDigest = DigestUtils.sha256(nonce + time + appSecret);
        String hexDigest = Hex.encodeHexString(passwordDigest);
        //如果JDK版本是1.8,请加载原生Base64类,并使用如下代码
        String passwordDigestBase64Str = Base64.getEncoder().encodeToString(hexDigest.getBytes()); //PasswordDigest
        //如果JDK版本低于1.8,请加载三方库提供Base64类,并使用如下代码
        //String passwordDigestBase64Str = Base64.encodeBase64String(hexDigest.getBytes(Charset.forName("utf-8"))); //PasswordDigest
        //若passwordDigestBase64Str中包含换行符,请执行如下代码进行修正
        //passwordDigestBase64Str = passwordDigestBase64Str.replaceAll("[\\s*\t\n\r]", "");
        return String.format(WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time);
    }
}
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/tencentMap/TencentMapUtil.java
New file
@@ -0,0 +1,40 @@
package com.ruoyi.account.util.tencentMap;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
/**
 * 腾讯地图
 * @author zhibing.pu
 * @Date 2024/12/19 9:37
 */
@Slf4j
public class TencentMapUtil {
    private static String key = "NH7BZ-XNW6Z-IKUX7-TL3H2-UN6RO-KKFHQ";
    /**
     * 根据经纬度获取行政区划代码
     * @param lon   经度
     * @param lat   纬度
     * @param poi   是否返回周边poi
     * @return
     */
    public static String inverseGeographicalAnalysis(String lon, String lat, boolean poi){
        HttpRequest get = HttpUtil.createGet("https://apis.map.qq.com/ws/geocoder/v1/?location=" + lat + "," + lon + "&key=" + key + "&get_poi=" + (poi ? 1 : 0));
        HttpResponse execute = get.execute();
        JSONObject jsonObject = JSON.parseObject(execute.body());
        Integer status = jsonObject.getInteger("status");
        if(0 != status){
            log.error(jsonObject.getString("message"));
            return null;
        }
        JSONObject result = jsonObject.getJSONObject("result");
        JSONObject ad_info = result.getJSONObject("ad_info");
        return ad_info.getString("adcode");
    }
}
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/ExpressDeliveryUtil.java
@@ -42,6 +42,7 @@
    public static QueryKD100Vo kd100QueryTrack(String com, String num){
        QueryTrackReq queryTrackReq = new QueryTrackReq();
        QueryTrackParam queryTrackParam = new QueryTrackParam();
//        queryTrackParam.setCom(CompanyConstant.YD);
        queryTrackParam.setCom(com);
        queryTrackParam.setNum(num);
        String param = new Gson().toJson(queryTrackParam);
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/RegionController.java
@@ -7,10 +7,7 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@@ -32,4 +29,15 @@
                .eq(Region::getParentId, parentId)));
    }
    /**
     * 根据城市编号获取数据
     * @param code
     * @return
     */
    @PostMapping("/getRegionBiCode")
    public R<Region> getRegionBiCode(@RequestParam("code") String code){
        Region one = regionService.getOne(new LambdaQueryWrapper<Region>().eq(Region::getCode, code));
        return R.ok(one);
    }
}