rk
10 小时以前 56fcde8c93a1a10bc50fac775e370a2db57f520e
server/dmmall_service/src/main/java/com/doumee/core/utils/Constants.java
@@ -1,15 +1,22 @@
package com.doumee.core.utils;
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
import com.doumee.core.wx.WxMiniConfig;
import com.doumee.dao.business.model.Areas;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Slf4j
public class Constants {
    public static final String[]  ALL_SPELL_LIST_FIRST = new String[]{"A", "B", "C", "D", "E", "F", "G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
@@ -137,6 +144,18 @@
    public static final String COFFEE_ARTICLE_BACKGROUND = "COFFEE_ARTICLE_BACKGROUND";
    public static final String TRANSFER_FILE = "TRANSFER_FILE";
    public static final String INVITE_RULE = "INVITE_RULE";
    public static final String INVITE_IMG = "INVITE_IMG";
    public static final String SHARES_FILE = "SHARES_FILE";
    public static final String INVITE_IMG_URL = "INVITE_IMG_URL";
    public interface RedisKeys {
@@ -1228,4 +1247,52 @@
            this.info = info;
        }
    }
    public static InputStream generateWxMiniImgStream(String scene, String page, boolean isUsePage) {
        //生成图片上传OSS
        Map<String,Object> body = new HashMap<>();
        // 场景码,与前端约定,最终是需要前端解析
        body.put("scene", scene);
        // 正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
        String env_version = "release";
        body.put("env_version", env_version);
        if(isUsePage){
            body.put("page", page);
        }
        //body.put("page", "pages/index/index");
        // 透明,根据你的场景自行设置body参数
        body.put("is_hyaline", true);
        try {
            WxMaCodeLineColor codeLineColor = new WxMaCodeLineColor("0","0","0");
            byte[]  bytes =  WxMiniConfig.wxMaService.getQrcodeService().createWxaCodeUnlimitBytes
                    (scene,null,false,env_version,300,false,codeLineColor,false);
            if (bytes !=null) {
                InputStream inputStream = new ByteArrayInputStream(bytes);
              /* ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    byte[] buffer = new byte[1024];
                    int len = -1;
                    while ((len = inputStream.read(buffer)) != -1) {
                        baos.write(buffer, 0, len);
                    }
                 System.out.println("data:mediatype;base64," + Base64.getEncoder().encodeToString(baos.toByteArray()));*/
                log.error("生成小程序码成功:============"+inputStream.available());
                return inputStream;
            }else{
                log.error("生成小程序码失败:============");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("生成小程序码失败:============"+e.getMessage());
        }
        return  null;
    }
    public static Integer getInviteCode(String inviteStr){
        if(StringUtils.isNotBlank(inviteStr)&&inviteStr.startsWith("m_")){
            return Integer.valueOf(inviteStr.replace("m_",""));
        }
        return null;
    }
}