shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.ishop.mobile.service;
 
import com.ishop.model.vo.QrCodeVo;
import com.walker.infrastructure.utils.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
 
@Service
public class QrcodeServiceImpl {
 
    private RestTemplate restTemplate;
 
    @Autowired
    public QrcodeServiceImpl(RestTemplate restTemplate){
        this.restTemplate = restTemplate;
    }
 
    /**
     * 远程图片转base64
     *
     * @param url 图片链接地址
     * @return QrCodeVo
     * @date 2023-07-09
     */
    public QrCodeVo urlToBase64(String url) {
        byte[] bytes = restTemplate.getForEntity(url, byte[].class).getBody();
        String base64Image = "data:image/png;base64," + new String(Base64.encodeBase64(bytes));
        QrCodeVo vo = new QrCodeVo();
        vo.setCode(base64Image);
        return vo;
    }
}