package com.ruoyi.quartz.task;

import com.alibaba.druid.support.json.JSONUtils;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.domain.GtgsYwUser;
import com.ruoyi.system.domain.GtgsywPrintList;
import com.ruoyi.system.domain.QyInfoPritn;
import com.ruoyi.system.mapper.GtgsywMapper;
import com.ruoyi.system.service.GtgsywPrintListService;
import com.ruoyi.system.service.IGtgsYwUserService;
import com.ruoyi.system.service.IGtgsywService;
import com.ruoyi.system.service.IQyInfoPritnService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import sun.misc.BASE64Encoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {

    @Autowired
    private IGtgsywService gtgsywService;
    @Autowired
    private GtgsywMapper gtgsywMapper;
    @Autowired
    private IQyInfoPritnService qyInfoPritnService;
    @Autowired
    private IGtgsYwUserService gtgsYwUserService;
    @Autowired
    private GtgsywPrintListService gtgsywPrintListService;


    protected final Logger logger = LoggerFactory.getLogger(RyTask.class);


    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        System.out.println("执行无参方法");
    }

    public void downloadAllZip() throws IOException {

        Integer[] ids = gtgsywService.selectByflgDate();
        int num = 0;
        for (int i = 0; i < ids.length; i++) {
            String isSuccess = gtgsywService.creatZip(ids[i]);
            if (isSuccess == null) {
                num++;
            }
        }
        System.out.println("总共有" + ids.length + "个Zip,生成了" + num + "个Zip");

    }

    public void downloadSomeDays(String startTime, String endTime) throws IOException {

        Integer[] ids = gtgsywMapper.selectByflgDates(startTime, endTime);
        System.out.println(startTime + "到" + endTime + "总共有:" + ids.length + "个申请的");
        int num = 0;
        for (int i = 0; i < ids.length; i++) {
            String isSuccess = gtgsywService.creatZip(ids[i]);
            if (isSuccess == null) {
                num++;
            }
        }
        System.out.println("总共有" + ids.length + "个Zip,生成了" + num + "个Zip");

    }


    /**
     * 个体数据定时下载
     *
     * @param userName
     */
    public void gtPrintEveryDay(String userName, String shenHeUserName) {


        List<String> listTab = new ArrayList<>();
        listTab.add("02");
        //03代表变更
        listTab.add("03");
        int a = 0;
        GtgsYwUser gtgsYwUser = gtgsYwUserService.selectGtgsYwUserByRemark(userName);
        String userDetail = "&loginName=" + gtgsYwUser.getUsername() + "&password=" + gtgsYwUser.getPassword() + "&authId=" +
                gtgsYwUser.getAuthid() + "&loginDeptId=" + gtgsYwUser.getDetpid() + "&loginUserId=" + gtgsYwUser.getUserid();
        for (String lit : listTab) {
            List<String> listTabNum = new ArrayList<>();
            listTabNum.add("0");
            listTabNum.add("1");
            for (String lin : listTabNum) {
                Integer pageNo = 1;
                for (int n = 0; n < pageNo; n++) {
                    if (gtgsYwUser == null) {
                        System.out.println("无账号");
                        continue;
                    }
                    String data;
                    if ("0".equals(lin)) {
                        data = HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/getWindList", "pageNum=" + pageNo + "&appTypeId=" + lit + userDetail);
                    } else {
                        data = HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/getOnlineWindList", "pageNum=" + pageNo + "&appTypeId=" + lit + userDetail);
                    }
                    Map<String, Object> m = (Map<String, Object>) JSONUtils.parse(data);
                    List<Map<String, String>> l = (List<Map<String, String>>) m.get("data");
                    for (int i = 0; i < l.size(); i++) {
                        if (StringUtils.isEmpty(String.valueOf(l.get(i).get("appNo")))) {
                            System.out.println("无注册号");
                            continue;
                        }
                        String isBsid = gtgsywPrintListService.selectByAppNo(String.valueOf(l.get(i).get("appNo")));
                        if (StringUtils.isNotEmpty(isBsid)) {
                            System.out.println("已存在的数据");
                            continue;
                        }
                        String msg = "";
                        try {
                            msg = HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/getinfo", "appNo=" + URLEncoder.encode(String.valueOf(l.get(i).get("appNo")), "utf-8") + "&loginName=" +
                                    URLEncoder.encode(gtgsYwUser.getUsername(), "utf-8") + "&password=" + URLEncoder.encode(gtgsYwUser.getPassword(), "utf-8") + "&loginUserId=" +
                                    URLEncoder.encode(gtgsYwUser.getUserid(), "utf-8") + "&loginDeptId=" + URLEncoder.encode(gtgsYwUser.getDetpid(), "utf-8"));
                        } catch (Exception e) {
                            msg = "error: " + e.getMessage();
                            logger.error("error: " + e.getMessage());
                            System.out.println("发生错误：" + e.getMessage());
                            continue;
                        }
                        Map<String, String> getinfom = (Map<String, String>) JSONUtils.parse(msg);
                        GtgsywPrintList gpt = new GtgsywPrintList();
                        gpt.setXinyongcode(StringUtils.trim(getinfom.get("code")));
                        gpt.setJingyingren(StringUtils.trim(getinfom.get("master")));
                        gpt.setShenherenname(shenHeUserName);
                        gpt.setZwzh(StringUtils.trim(getinfom.get("name")));
                        gpt.setZuchengxingshi(StringUtils.trim(getinfom.get("formation")));
                        gpt.setJingyingchangsuo(StringUtils.trim(getinfom.get("address")));
                        gpt.setJingyingfanwei(StringUtils.trim(getinfom.get("range")));
                        gpt.setShenqingdate(String.valueOf(l.get(i).get("date")));
                        gpt.setZhucetime(DateUtils.parseDate(StringUtils.trim(getinfom.get("date"))));
                        gpt.setBsid(UUID.randomUUID().toString().replaceAll("-", ""));
                        gpt.setJingyingcard(StringUtils.trim(getinfom.get("cetfNoOperator")));
                        gpt.setXingbie(StringUtils.trim(getinfom.get("sexIdOperator")));
                        gpt.setJingyingcard(StringUtils.trim(getinfom.get("cetfNoOperator")));
                        gpt.setJiatingzhuzhi(StringUtils.trim(getinfom.get("addressOperator")));
                        gpt.setJingyingrenphone(StringUtils.trim(getinfom.get("phone")));
                        gpt.setIsprint(0);
                        gpt.setAppno(l.get(i).get("appNo"));
                        gpt.setIsprintF(0);
                        gpt.setSczttype("个体工商户");
                        gpt.setErweimabase64(getImg(StringUtils.trim(getinfom.get("code"))));
                        gpt.setUpdateTime(DateUtils.getNowDate());
                        gpt.setShenhedate(DateUtils.getNowDate());
                        gpt.setUpdatetime(DateUtils.getNowDate());
                        String maxZzcode = gtgsywService.selectMaxZzCode();
                        gpt.setZzcode(String.valueOf(Integer.parseInt(maxZzcode) + 1));
                        if (lin.equals("0")) {
                            if (lit.equals("02")) {
                                gpt.setShenqinglaiyuan("窗口数据下载(设立)");
                            } else {
                                gpt.setShenqinglaiyuan("窗口数据下载(变更)");
                            }
                        } else {
                            if (lit.equals("02")) {
                                gpt.setShenqinglaiyuan("全程电子化数据下载(设立)");
                            } else {
                                gpt.setShenqinglaiyuan("全程电子化数据下载(变更)");
                            }
                        }
                        Integer g = gtgsywPrintListService.insertSelective(gpt);
                        a += g;
                        //下载完数据之后,点击完成打印执照
                        if (g == 1) {
//                            HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/setPrint", "xinyongcode=" + gpt.getXinyongcode() + userDetail);
                        }
                    }
                }
            }
        }
        System.out.println("添加完成" + a + "条数据！");
    }

    /**
     * 企业数据定时下载
     *
     * @return
     */
    public void qyPrintEveryDay(String userName, String shenHeUserName) {

        List<String> listTab = new ArrayList<>();
        listTab.add("02");
        listTab.add("03");
        int a = 0;
        for (String lit : listTab) {
            List<String> listTabNum = new ArrayList<>();
            if (lit == "02") {
                listTabNum.add("tabs-3");
                listTabNum.add("tabs-4");
                listTabNum.add("tabs-7");
            } else {
                listTabNum.add("tabs-3");
                listTabNum.add("tabs-4");
                listTabNum.add("tabs-5");
            }
            for (String lin : listTabNum) {

                Integer pageNo = 1;
                for (int i = 0; i < pageNo; i++) {

                    GtgsYwUser gtgsYwUser = gtgsYwUserService.selectGtgsYwUserByRemark(userName);
                    if (gtgsYwUser == null) {
                        System.out.println("无账号");
                        continue;
                    }
                    String userDetwail = "&loginName=" + gtgsYwUser.getUsername() + "&password=" + gtgsYwUser.getPassword() + "&authId=" +
                            gtgsYwUser.getAuthid() + "&loginDeptId=" + gtgsYwUser.getDetpid() + "&loginUserId=" + gtgsYwUser.getUserid();
                    String data;
                    data = HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/sllb", "type=" + lin + "&appTypeId=" + lit + "&pageNo=" + pageNo + userDetwail);
//            data="{\"data\": [{\"sqh\": \"13012403202005280020\", \"qymc\": \"河北安邦供应链管理有限公司\", \"qylx\": \"内资公司\", \"djlx\": \"变更登记\", \"sqrq\": \"2020-05-28 14:01:45\", \"sljg\": \"栾城区市场监督管理局\", \"zt\": \"核准通过\"},{\"sqh\": \"13012403202005280020\", \"qymc\": \"河北安邦供应链管理有限公司\", \"qylx\": \"内资公司\", \"djlx\": \"变更登记\", \"sqrq\": \"2020-05-28 14:01:45\", \"sljg\": \"栾城区市场监督管理局\", \"zt\": \"核准通过\"}], \"page\": \"2\", \"code\": \"0\"}";
                    if (data.equals("")) {
                        System.out.println("列表无数据");
                        continue;
                    }
                    Map<String, Object> sllbresult = (Map<String, Object>) JSONUtils.parse(data);
                    System.out.println("Code:" + sllbresult.get("code"));
                    if (sllbresult.get("code").equals("302")) {
                        System.out.println("列表无数据");
                        continue;
                    }
                    pageNo = Integer.parseInt(sllbresult.get("page") + "");
                    List<Map<String, String>> l = (List<Map<String, String>>) sllbresult.get("data");
                    for (Map li : l) {
                        if (StringUtils.isEmpty(String.valueOf(li.get("sqh")))) {
                            System.out.println("注册号为空");
                            continue;
                        }
                        String isBsid = qyInfoPritnService.selectByAppNo(String.valueOf(li.get("sqh")));
                        System.out.println("是否已存在" + isBsid);
                        if (StringUtils.isNotEmpty(isBsid)) {
                            System.out.println("已存在的数据");
                            continue;
                        }
                        String msg;
                        try {
//                msg="{\"Qywtrxm\": \"张丽娟\", \"FrName\": \"李春\",\"WtrCardNo\": \"130124198703094560\", \"QyName\": \"石家庄正广通物业管理有限公司\", \"QyLx\": \"内资企业\", \"Qyjyfw\": \"物业管理。物业服务、停车场管理服务、保洁服务；房屋修缮；园林绿化养护；房屋租赁、汽车租赁；仓储服务（危险化学品、易燃易爆品除外）；企业管理咨询（金融、证券、期货、投资、教育咨询除外。（依法须经批准的项目，经相关部门批准后方可开展经营活动）**\", \"Qyjycs\": \"河北省石家庄市栾城区樊家屯人大路156号\", \"Qyclrq\": \"2020-06-01\", \"Qyyyqz\": \"2020-06-01 至 长期\", \"Qyzczj\": \"10.000000 万人民币\", \"xinyongCode\": \"91130124MA0F1X719C\"}";
                            msg = HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/slxx", "appNo=" + URLEncoder.encode(String.valueOf(li.get("sqh")), "utf-8") + "&appTypeId=" + lit + "&loginName=" +
                                    URLEncoder.encode(gtgsYwUser.getUsername(), "utf-8") + "&password=" + URLEncoder.encode(gtgsYwUser.getPassword(), "utf-8") + "&loginUserId=" +
                                    URLEncoder.encode(gtgsYwUser.getUserid(), "utf-8") + "&loginDeptId=" + URLEncoder.encode(gtgsYwUser.getDetpid(), "utf-8"));
                        } catch (Exception e) {
                            msg = "error: " + e.getMessage();
                            logger.error("error: " + e.getMessage());
                        }


                        Map<String, String> slxxm = (Map<String, String>) JSONUtils.parse(msg);
                        if ("302".equals(slxxm.get("code"))) {
                            continue;
                        }
                        QyInfoPritn qyInfoPritn = new QyInfoPritn();
                        qyInfoPritn.setBsid(UUID.randomUUID().toString());
                        qyInfoPritn.setFrname(StringUtils.trim(slxxm.get("FrName") + ""));
                        qyInfoPritn.setWtrcardno(StringUtils.trim(slxxm.get("WtrCardNo") + ""));
                        qyInfoPritn.setQylx(slxxm.get("Qylx") + "");
                        switch (String.valueOf(li.get("qylx"))) {
                            case "内资公司":
                                qyInfoPritn.setQylb("1");
                                break;
                            case "内资分公司":
                                qyInfoPritn.setQylb("2");
                                break;
                            case "内资非公司企业法人":
                                qyInfoPritn.setQylb("3");
                                break;
                            case "内资非公司企业法人分支机构":
                                qyInfoPritn.setQylb("4");
                                break;
                            case "个人独资企业":
                                qyInfoPritn.setQylb("5");
                                break;
                            case "个人独资企业分支机构":
                                qyInfoPritn.setQylb("6");
                                break;
                            case "合伙企业":
                                qyInfoPritn.setQylb("7");
                                break;
                            case "合伙企业分支机构":
                                qyInfoPritn.setQylb("8");
                                break;
                            case "农民专业合作社":
                                qyInfoPritn.setQylb("9");
                                break;
                            case "农民专业合作社分支机构":
                                qyInfoPritn.setQylb("10");
                                break;
                            default:
                                qyInfoPritn.setQylb("1");
                                System.out.println("未知等级");
                        }
                        qyInfoPritn.setQyjyfw(StringUtils.trim(slxxm.get("Qyjyfw") + ""));
                        qyInfoPritn.setQyjycs(StringUtils.trim(slxxm.get("Qyjycs") + ""));
                        qyInfoPritn.setQyclrq(DateUtils.parseDate(StringUtils.trim(slxxm.get("Qyclrq"))));
                        qyInfoPritn.setQyname(StringUtils.trim(slxxm.get("QyName") + ""));
                        if (lit.equals("02")) {
                            if (lin.equals("tabs-3")) {
                                qyInfoPritn.setLaiyuan("窗口收件代办(设立)");
                            } else if (lin.equals("tabs-4")) {
                                qyInfoPritn.setLaiyuan("全程电子化申请(设立)");
                            } else if (lin.equals("tabs-7")) {
                                qyInfoPritn.setLaiyuan("一窗通(设立)");
                            }
                        } else {
                            if (lit.equals("tabs-3")) {
                                qyInfoPritn.setLaiyuan("窗口收件代办(变更)");
                            } else if (lin.equals("tabs-4")) {
                                qyInfoPritn.setLaiyuan("全程电子化申请(变更)");
                            } else if (lin.equals("tabs-5")) {
                                qyInfoPritn.setLaiyuan("网上预申报(变更)");
                            }
                        }
                        if (StringUtils.trim(slxxm.get("Qyyyqz")).indexOf("长期") != -1) {
                            qyInfoPritn.setQyjyqx("长期");
                        } else if (!slxxm.get("Qyyyqz").equals("")) {
                            qyInfoPritn.setQyyyqz(DateUtils.parseDate(StringUtils.trim(slxxm.get("Qyyyqz")).substring(13, slxxm.get("Qyyyqz").length())));
                        }
                        qyInfoPritn.setQynx(StringUtils.trim(slxxm.get("Qyyyqz")));
                        //把爬取来的 etpsId 暂存到hangye3中
                        qyInfoPritn.setHangye3(StringUtils.trim(String.valueOf(li.get("etpsId"))));
                        qyInfoPritn.setZhucehao(StringUtils.trim(li.get("sqh") + ""));
                        qyInfoPritn.setQyzczj(StringUtils.trim(slxxm.get("Qyzczj") + "").replace(" 万人民币", ""));
                        qyInfoPritn.setXinyongcode(StringUtils.trim(slxxm.get("xinyongCode") + ""));

                        String maxZzcode = qyInfoPritnService.selectMaxZzCode();
                        qyInfoPritn.setZzcode(String.valueOf(Integer.parseInt(maxZzcode) + 1));

                        qyInfoPritn.setErweimabase64(getImg(StringUtils.trim(slxxm.get("xinyongCode") + "")));
//            qyInfoPritn.setLaiyuan(StringUtils.trim(li.get("sqly") + ""));
                        qyInfoPritn.setShenhename(shenHeUserName);
                        qyInfoPritn.setCreatedate(DateUtils.parseDate(StringUtils.trim(String.valueOf(li.get("sqrq")))));
                        qyInfoPritn.setShenhedate(new Date());
                        qyInfoPritn.setFlg("2");
                        a += qyInfoPritnService.insertQyInfoPritn(qyInfoPritn);
                    }
                }
            }
        }
        System.out.println("添加完成" + a + "条数据");
//        return "添加完成" + a + "条数据";

    }


    /**
     * 企业数据定时查数据打印状态
     *
     * @return
     */
    public void qyGsPrintEveryDay(String userName, String shenHeName) {
        List<String> listTab = new ArrayList<>();
        GtgsYwUser gtgsYwUser = gtgsYwUserService.selectGtgsYwUserByRemark(userName);
        QyInfoPritn qyInfoPritn = new QyInfoPritn();
        qyInfoPritn.setIsprintF("0");
        qyInfoPritn.setIsprintZ("0");
        qyInfoPritn.setShenhename(shenHeName);
        List<QyInfoPritn> qyInfoPritns = qyInfoPritnService.selectQyInfoPritnByIsPrint(qyInfoPritn);

        Integer upDateNum = 0;
        for (QyInfoPritn q : qyInfoPritns) {
            String userDetwail = "&loginName=" + gtgsYwUser.getUsername() + "&password=" + gtgsYwUser.getPassword() + "&authId=" +
                    gtgsYwUser.getAuthid() + "&loginDeptId=" + gtgsYwUser.getDetpid() + "&loginUserId=" + gtgsYwUser.getUserid();
            String lit = "";
            if (q.getLaiyuan() == null) {
                q.setLaiyuan("");
            }
            switch (q.getLaiyuan()) {
                case "窗口收件代办(设立)":
                    lit = "02";
                    break;
                case "全程电子化申请(设立)":
                    lit = "02";
                    break;
                case "一窗通(设立)":
                    lit = "02";
                    break;
                case "窗口收件代办(变更)":
                    lit = "03";
                    break;
                case "全程电子化申请(变更)":
                    lit = "03";
                    break;
                case "网上预申报(变更)":
                    lit = "03";
                    break;
                default:
                    lit = "03";
                    break;
            }
            String data = HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/checkQyPrint",
                    "appTypeId=" + lit + "&XinYongCode=" + q.getXinyongcode() + userDetwail);
            Map<String, Object> sllbresult = (Map<String, Object>) JSONUtils.parse(data);
            List<Map<String, String>> l = (List<Map<String, String>>) sllbresult.get("data");
            if (l.size() > 0) {
                System.out.println("户籍系统列表中还存在该数据-------------!");
                continue;
            } else {
                q.setIsprintZ("1");
                q.setIsprintF("1");
                q.setLqrname("前台领取");
                q.setLqdate(new Date());
                upDateNum += qyInfoPritnService.updateQyInfoPritn(q);
            }

        }
        System.out.println("更改一体机系统数据为已打印共:" + upDateNum + "条");
    }

    /**
     * 个体数据定时查数据打印状态
     *
     * @return
     */
    public void gtGsPrintEveryDay(String userName, String shenHeName) {
        List<String> listTab = new ArrayList<>();
        GtgsYwUser gtgsYwUser = gtgsYwUserService.selectGtgsYwUserByRemark(userName);
        GtgsywPrintList gtgsywPrintList = new GtgsywPrintList();
        gtgsywPrintList.setIsprintF(0);
        gtgsywPrintList.setIsprint(0);
        gtgsywPrintList.setShenherenname(shenHeName);
        List<GtgsywPrintList> gtgsywPrintLists = gtgsywPrintListService.selectByIsPrint(gtgsywPrintList);

        Integer upDateNum = 0;
        for (GtgsywPrintList g : gtgsywPrintLists) {
            String userDetwail = "&loginName=" + gtgsYwUser.getUsername() + "&password=" + gtgsYwUser.getPassword() + "&authId=" +
                    gtgsYwUser.getAuthid() + "&loginDeptId=" + gtgsYwUser.getDetpid() + "&loginUserId=" + gtgsYwUser.getUserid();
            String lit = "";
            if (g.getShenqinglaiyuan() == null) {
                g.setShenqinglaiyuan("");
            }

            switch (g.getShenqinglaiyuan()) {
                case "窗口数据下载(设立)":
                    lit = "02";
                    break;
                case "全程电子化数据下载(设立)":
                    lit = "02";
                    break;
                case "窗口数据下载(变更)":
                    lit = "03";
                    break;
                case "全程电子化数据下载(变更)":
                    lit = "03";
                    break;
                default:
                    lit = "03";
                    break;
            }
            String data = HttpUtils.sendPost(Global.getConfig("ruoyi.pyip") + "/checkGtPrint",
                    "appTypeId=" + lit + "&XinYongCode=" + g.getXinyongcode() + userDetwail);
            Map<String, Object> m = (Map<String, Object>) JSONUtils.parse(data);
            List<Map<String, String>> l = (List<Map<String, String>>) m.get("data");
            if (l.size() > 0) {
                System.out.println("户籍系统列表中还存在该数据-------------!");
                continue;
            } else {
                g.setIsprint(1);
                g.setIsprintF(1);
                g.setShenhenote("前台领取");
                g.setUpdateTime(new Date());
                upDateNum += gtgsywPrintListService.updateByPrimaryKeySelective(g);
            }

        }
        System.out.println("更改一体机系统数据为已打印共:" + upDateNum + "条");
    }


    private static String strNetImageToBase64;

    private static String getImg(String xycode) {
        String urlgs = Global.getConfig("ruoyi.gsdz") + ":8005/gtdj/licence.do?method=toTowDimCode&appNo=&uniScid=" + xycode + "&certTypeId=41";
        final ByteArrayOutputStream data = new ByteArrayOutputStream();
        try {
            // 创建URL
            URL url = new URL(urlgs);
            final byte[] by = new byte[1024];
            // 创建链接
            final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(20000);
            try {
                InputStream is = conn.getInputStream();
                // 将内容读取内存中
                System.err.println(111);
                int len = -1;
                while ((len = is.read(by)) != -1) {
                    data.write(by, 0, len);
                }
                // 对字节数组Base64编码
                BASE64Encoder encoder = new BASE64Encoder();
                strNetImageToBase64 = encoder.encode(data.toByteArray());
//                System.out.println("网络图片转换Base64:" + strNetImageToBase64);
                // 关闭流
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return strNetImageToBase64;
    }


}
