liujie
8 天以前 3caaf21916009fe7d12430f8fbac053384616e45
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/DriverController.java
@@ -531,7 +531,7 @@
    }
    @ApiOperation(value = "个人的小程序码(分享码)生成", tags = {"司机端-首页"}, notes = "")
    @ApiOperation(value = "个人的小程序码(分享码)/链接", tags = {"司机端-首页"}, notes = "")
    @GetMapping("/api/driver/person-code")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
@@ -544,48 +544,66 @@
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            Driver driver = driverService.selectById(uid);
            String accessToken=null;
            // 获取调用凭证accessToken
            String accessToken = getAccessToken();
            RestTemplate rest = new RestTemplate();
            if(ToolUtil.isEmpty(driver.getShareImg())|| ToolUtil.isEmpty(driver.getShareImg())){
                accessToken = getAccessToken();
            }
            String img=driver.getShareImg();
            int index=0;
            String imgUrl = "";
            String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken;
            Map<String, Object> param = new HashMap<>();
            param.put("path", "pages/home/home?driverId=" + uid);
            param.put("width", 430); //二维码尺寸
            MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
            HttpEntity requestEntity = new HttpEntity(param, headers);
            ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
            byte[] result = entity.getBody();
            inputStream = new ByteArrayInputStream(result);
            if(ToolUtil.isEmpty(driver.getShareImg())) {
                index=1;
                RestTemplate rest = new RestTemplate();
                String imgUrl = "";
                String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken;
                Map<String, Object> param = new HashMap<>();
                param.put("path", "pages/home/home?driverId=" + uid);
                param.put("width", 430); //二维码尺寸
                MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
                HttpEntity requestEntity = new HttpEntity(param, headers);
                ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
                byte[] result = entity.getBody();
                inputStream = new ByteArrayInputStream(result);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            // 最后上传生成的文件名
            String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
            // oss中的文件夹名
            String objectName = sdf.format(new Date()) + "/" + finalFileName;
            String key = "imgs/management/" + objectName;
            String object = NCOSSUtil.putObject( qianYunTongConfig.getBucketName(), key, inputStream);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                // 最后上传生成的文件名
                String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
                // oss中的文件夹名
                String objectName = sdf.format(new Date()) + "/" + finalFileName;
                String key = "imgs/management/" + objectName;
                String object = NCOSSUtil.putObject(qianYunTongConfig.getBucketName(), key, inputStream);
                System.out.println(object);
                driver.setShareImg(object);
                img= object;
            }
            System.out.println(object);
            String urlLink = driver.getShareLink();
            if(ToolUtil.isEmpty(urlLink)) {
                index=1;
                String url1 = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + accessToken;
                Map<String, Object> param1 = new HashMap<>();
                param1.put("path", "pages/home/home");
                param1.put("query", "driverId=" + uid);
            String url1 ="https://api.weixin.qq.com/wxa/generate_urllink?access_token="+accessToken;
            Map<String, Object> param1 = new HashMap<>();
            param1.put("path", "pages/home/home");
            param1.put("query","driverId="+uid);
                HttpRequest post = HttpUtil.createPost(url1);
                // map转json
                String jsonString = JSON.toJSONString(param1);
                post.body(jsonString);
                HttpResponse execute = post.execute();
                String body = execute.body();
                urlLink = JSONObject.parseObject(body).get("url_link").toString();
                driver.setShareLink(urlLink);
            }
            HttpRequest post = HttpUtil.createPost(url1);
            // map转json
            String jsonString = JSON.toJSONString(param1);
            post.body(jsonString);
            HttpResponse execute = post.execute();
            String body = execute.body();
            String urlLink = JSONObject.parseObject(body).get("url_link").toString();
            if(index==1){
                driverService.updateById(driver);
            }
            HashMap<String, String> stringStringHashMap = new HashMap<>();
            stringStringHashMap.put("url_link",urlLink);
            stringStringHashMap.put("img",object);
            stringStringHashMap.put("img",img);
//            inputStream = new ByteArrayInputStream(result);