mitao
2024-04-22 28a19584dca02f05fe0b8be9ab426b586efead6e
营销员管理-身份证图片放大
1个文件已修改
1个文件已添加
265 ■■■■■ 已修改文件
meiya-admin/src/main/webapp/static/js/common/Feng.js 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
meiya-rest/src/test/java/com/sinata/juhe/TelecomTest.java 166 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
meiya-admin/src/main/webapp/static/js/common/Feng.js
@@ -321,6 +321,105 @@
            content: '<img src="' + $(image).attr("src") + '" height="100%" width="100%" />'
        });
    },
    lookBigImg: function (obj) {
        console.log("进入")
        console.log(obj)
        // 设置图片路径
        var imgUrl = obj;
        if (imgUrl != "") {
            imgUrl = imgUrl;// 设置图片路径
        } else {
            imgUrl = Feng.ctxPath + '/static/img/NoPIC.png';// 默认无图
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['80%', '100%'],
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true, //点击空白区域关闭弹出层
            content: '<div id="zoomableImageContainer" style="height: 100%; width: 100%; overflow: hidden; display: flex; justify-content: center; align-items: center; position: relative;"><img id="zoomableImage" src="'
                + imgUrl
                + '" style="max-width: none; max-height: none; position: absolute;"></div>',
            success: function (layero, index) {
                // 获取图片容器和图片元素
                var zoomableImageContainer = document.getElementById(
                    'zoomableImageContainer');
                var zoomableImage = document.getElementById('zoomableImage');
                var imageWidth = zoomableImage.naturalWidth;
                var imageHeight = zoomableImage.naturalHeight;
                var containerWidth = zoomableImageContainer.offsetWidth;
                var containerHeight = zoomableImageContainer.offsetHeight;
                var isDragging = false; // 标记是否正在拖动
                var startX, startY; // 记录拖动起始位置
                zoomableImageContainer.addEventListener('wheel',
                    function (event) {
                        event.preventDefault();
                        var delta = Math.sign(-event.deltaY); // 获取滚动方向,1表示向上滚动,-1表示向下滚动
                        var currentWidth = zoomableImage.offsetWidth;
                        var currentHeight = zoomableImage.offsetHeight;
                        var step = 0.1; // 缩放步长
                        var newWidth = currentWidth + delta * step
                            * currentWidth;
                        var aspectRatio = zoomableImage.naturalWidth
                            / zoomableImage.naturalHeight;
                        var newHeight = newWidth / aspectRatio;
                        zoomableImage.style.width = newWidth + 'px';
                        zoomableImage.style.height = newHeight + 'px';
                    });
                zoomableImageContainer.addEventListener('mousedown',
                    function (event) {
                        if (event.button === 0) { // 判断是否为鼠标左键点击
                            event.preventDefault();
                            isDragging = true;
                            startX = event.clientX - zoomableImage.offsetLeft;
                            startY = event.clientY - zoomableImage.offsetTop;
                        }
                    });
                zoomableImageContainer.addEventListener('mousemove',
                    function (event) {
                        if (isDragging) {
                            event.preventDefault();
                            var offsetX = event.clientX - startX;
                            var offsetY = event.clientY - startY;
                            var maxX = zoomableImage.offsetWidth
                                - containerWidth;
                            var maxY = zoomableImage.offsetHeight
                                - containerHeight;
                            offsetX = Math.min(Math.max(offsetX, -maxX), 0);
                            offsetY = Math.min(Math.max(offsetY, -maxY), 0);
                            zoomableImage.style.left = offsetX + 'px';
                            zoomableImage.style.top = offsetY + 'px';
                        }
                    });
                zoomableImageContainer.addEventListener('mousemove',
                    function (event) {
                        if (isDragging) {
                            var mouseX = event.clientX;
                            var mouseY = event.clientY;
                            var newLeft = mouseX - startX;
                            var newTop = mouseY - startY;
                            // 确保图片不会移出容器范围
                            if (newLeft >= 0 && newLeft
                                + zoomableImage.offsetWidth <= containerWidth) {
                                zoomableImage.style.left = newLeft + 'px';
                            }
                            if (newTop >= 0 && newTop
                                + zoomableImage.offsetHeight
                                <= containerHeight) {
                                zoomableImage.style.top = newTop + 'px';
                            }
                        }
                    });
                zoomableImageContainer.addEventListener('mouseup',
                    function (event) {
                        if (event.button === 0) {
                            isDragging = false;
                        }
                    });
            }
        });
    },
    /**
     * 单选框-取值
     */
meiya-rest/src/test/java/com/sinata/juhe/TelecomTest.java
New file
@@ -0,0 +1,166 @@
package com.sinata.juhe;
import com.alipay.api.internal.util.file.IOUtils;
import com.sinata.rest.core.juhe.SecurityAESTool;
import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
/**
 * @author mitao
 * @date 2024/4/1
 */
public class TelecomTest {
    //设置超时时间为5秒
    public static RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build();
    // 配置您申请的KEY,在个人中心->我的数据,接口名称上方查看
    public static final String APPKEY = "";
    //明文查询地址
    public static String query_url = "https://v.juhe.cn/telecom/query?key=" + APPKEY;
    //加密查询地址
    public static String queryEncry_url = "https://v.juhe.cn/telecom/queryEncry?key=" + APPKEY;
    public static void main(String[] args) {
        // ----------------------三网手机实名制认证-----------------------------------------------------------------------
        // int queryType = 1;// 1:普通查询 2:加密查询
        // String realname = "";// 姓名
        // String idcard = "";// 身份证
        //String mobile="" // 手机号
        // int type = 1;// 是否显示手机运营商 1:显示 0:不显示(默认)
        //int showid = 1 //是否显示聚合订单账号 1:显示 0:不显示(默认)
        //int province = 1 //是否显示号码归属地 1:显示 0:不显示(默认)
        //int detail = 1 //是否买显示匹配详情码 1:显示 0:不显示(默认)
        // Map<String, Object> params = new HashMap<>();
        // params.put("realname", realname);
        // params.put("idcard", idcard);
        // ----------------------身份证实名查询(加密版)-----------------------------------------------------------------------
        String realname = "张三";// 姓名
        String idcard = "32072119970602561X";// 身份证
        String mobile = "18283820718";// 手机号
        String openid = "JH1ad5c53745350580f7c24ca4b09717de";// 个人中心查询
        String key = MD5(openid).substring(0, 16);//取前16位作为加密密钥
        int queryType = 2;// 加密版本
        realname = SecurityAESTool.encrypt(realname, key);//加密姓名
        idcard = SecurityAESTool.encrypt(idcard, key);//加密身份证
        mobile = SecurityAESTool.encrypt(mobile, key);//
        Map<String, Object> params = new HashMap<>();//组合参数
        params.put("realname", realname);
        params.put("idcard", idcard);
        params.put("mobile", mobile);
        //请求接口
        String result = null;
        try {
            result = queryResult(params, queryType);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        //打印结果
        System.out.println(result);
    }
    /**
     * 请求接口查询数据
     * @param params 参数
     * @param type 类型,1明文查询(默认),2加密版
     * @return 结果
     * @throws Exception
     */
    public static String queryResult(Map<String, Object> params, int queryType) throws Exception {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        String result = null;
        String url = query_url;
        switch (queryType) {
            case 2:
                url = queryEncry_url;
                break;
        }
        try {
            url = new StringBuffer(url).append("&").append(urlencode(params)).toString();
            HttpGet httpget = new HttpGet(url);
            httpget.setConfig(config);
            response = httpClient.execute(httpget);
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
                result = IOUtils.toString(resEntity.getContent(), "UTF-8");
            }
            EntityUtils.consume(resEntity);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            response.close();
            httpClient.close();
        }
        return result;
    }
    // 将map型转为请求参数型
    public static String urlencode(Map<String, ?> data) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, ?> i : data.entrySet()) {
            try {
                sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        String result = sb.toString();
        result = result.substring(0, result.lastIndexOf("&"));
        return result;
    }
    /**
     * md5加密
     * @param data
     * @return 加密结果
     */
    public static String MD5(String data) {
        StringBuffer md5str = new StringBuffer();
        byte[] input = data.getBytes();
        try {
            // 创建一个提供信息摘要算法的对象,初始化为md5算法对象
            MessageDigest md = MessageDigest.getInstance("MD5");
            // 计算后获得字节数组
            byte[] buff = md.digest(input);
            // 把数组每一字节换成16进制连成md5字符串
            int digital;
            for (int i = 0; i < buff.length; i++) {
                digital = buff[i];
                if (digital < 0) {
                    digital += 256;
                }
                if (digital < 16) {
                    md5str.append("0");
                }
                md5str.append(Integer.toHexString(digital));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return md5str.toString();
    }
}