栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

七牛获取Token+百度人脸融合

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

七牛获取Token+百度人脸融合

获取七牛token返回给前端

 public RestResult minGetCosplayToken(RequestBean model) {
       
        CosplayPerson cosplayPerson = cosplayPersonService.queryByOId(model.getPersonId(), model.getClientId());
        if (cosplayPerson == null) {
            return RestResult.error("cosplay area is not found");
        }
        String bucket = "wilssir";
        long expireSeconds = 600;   //过期时间
        String body = "clientId=" + cosplayPerson.getClientId() +
                "&nickName=" + "nickNamw" +
                "&userId=" + "userId" +
                "&personId=" + "personId" +
                "&key=$(key)" +
                "&width=$(imageInfo.width)" +
                "&height=$(imageInfo.height)";
        StringMap putPolicy = new StringMap();
        putPolicy.put("scope", Constant.getQiNiuBucket());
        putPolicy.put("callbackUrl", Constant.getQiNiuCallbackUrl());
        putPolicy.put("callbackBody", body);
        String token = QiNiuUtils.getQiNiuToken(bucket, expireSeconds, putPolicy);
        return RestResult.ok(token);
    }

回调

public RestResult callBack(HttpServletRequest request) {
        try {
            String clientId = request.getParameter("clientId");

            String userId = request.getParameter("userId");
            String personId = request.getParameter("personId");
            String key = request.getParameter("key");
            String width = request.getParameter("width");
            String height = request.getParameter("height");
            String nickName = request.getParameter("nickName");
            CosplayPerson person = cosplayPersonService.queryByOId(personId, null);
            if (person == null) {
                return RestResult.error("person not found");
            }
            // add library
            Library library = new Library();
            library.setOId(UUIDGenerator.getUUID());
            library.setUserId(userId);
            library.setName("图中换人");
            library.setTags("图中换人,用户上传");
            library.setModule("Cosplay");
            library.setSubject("User");
            library.setOldUrl(key);
            library.setWidth(Long.valueOf(width));
            library.setHeight(Long.valueOf(height));
            library.setDateline(TimeUtils.getCurrentUnixTime());
            library.setStatus(200L);

            // add cosplay
            Cosplay cosplay = new Cosplay();
            cosplay.setOId(UUIDGenerator.getUUID());
            cosplay.setName("baidu:v2.0");
            cosplay.setUserId(userId);
            cosplay.setDateline(TimeUtils.getCurrentUnixTime());
            cosplay.setSubject("picture");
            cosplay.setTargetId(person.getTargetId());
            cosplay.setTargetNumber(person.getTargetNumber());
            cosplay.setPersonId(person.getOId());
            cosplay.setPersonName(person.getName());
            cosplay.setOldImageUrl(person.getPartImageUrl());
            cosplay.setStartShowTime(TimeUtils.getCurrentUnixTime());
            cosplay.setEndShowTime(cosplay.getStartShowTime() + 60);
            cosplay.setIsStar(0L);// 不参与点赞活动
            cosplay.setStar(0L);
//            cosplay.setStarTime(0L);
//            cosplay.setStarEndTime(0L);
//            cosplay.setStarLimit(1L);
            // request baidu faceMerge
            RestResult restResult = FaceMergeUtils.faceMerge(person.getPartImageUrl(), key);
            if (restResult.getCode() != 200) {  //fail add errInfo
                cosplay.setStatus(400L);
                cosplay.setErrInfo(restResult.getData());
                cosplayService.add(cosplay);
                return restResult;
            }
            String data = (String) restResult.getData();
            cosplay.setStatus(200L);
            cosplay.setNewImageUrl(data);
            cosplayService.add(cosplay);
            library.setNewUrl(data);
            libraryService.add(library);
            Map map = new HashMap<>();
            map.put("cosplay", cosplay);
            //send socket
            MinUserSocket.SendMessageAll(JSON.toJSONString(map));
            String start = TimeUtils.unixToTime(cosplay.getStartShowTime(), "HH:mm:ss");
            String end = TimeUtils.unixToTime(cosplay.getEndShowTime(), "HH:mm:ss");
            map.put("msg", start + "-" + end);
            return RestResult.ok(map);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResult.exception();
        }
    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1014334.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号