xiaoyong931011
2022-09-07 11edfa154a6f6c48d06de201315b25978601229c
20220902
5 files modified
133 ■■■■■ changed files
src/main/java/cc/mrbird/febs/mall/entity/MallGoods.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/entity/MallTeamLeader.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/model/WxGenerateQrCodeDto.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/service/impl/XcxPayServiceImpl.java 112 ●●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/ProfitTest.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/entity/MallGoods.java
@@ -115,4 +115,6 @@
    private BigDecimal carriage;
    private String wxCodeImg;
}
src/main/java/cc/mrbird/febs/mall/entity/MallTeamLeader.java
@@ -47,4 +47,6 @@
    @TableField(exist = false)
    private Double distance;
    private String wxCodeImg;
}
src/main/java/cc/mrbird/febs/pay/model/WxGenerateQrCodeDto.java
@@ -17,4 +17,10 @@
    @ApiModelProperty(value = "参数 订单id 例如 15")
    private String scene;
    @ApiModelProperty(value = "1:商品分享 2:团长分享")
    private Integer type;
    @ApiModelProperty(value = "商品分享传商品ID,团长分享放图章特征码")
    private String typeParam;
}
src/main/java/cc/mrbird/febs/pay/service/impl/XcxPayServiceImpl.java
@@ -158,42 +158,41 @@
    @Override
    public FebsResponse getQrCode(WxGenerateQrCodeDto wxGenerateQrCodeDto) {
        //这里调用的是上面的获取access_token方法
        String access_token = redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY).toString();
        String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+access_token;
        String scene = wxGenerateQrCodeDto.getScene();
        Map<String, String> param = new HashMap<>();
        param.put("scene",scene);
        //这里的page如果没有的话可以不写,默认是跳主页,如果写了没有的页面的话,会返回错误信息
        param.put("page",wxGenerateQrCodeDto.getPage());
        String json = JSON.toJSONString(param);
        ByteArrayInputStream inputStream = sendPost(url, json);
        try {
            System.out.println(inputStream);
            //这里判断的是返回的图片还是错误信息,一般错误信息不会大于200
            if (inputStream.available() <= 200){
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                int i;
                byte[] buffer = new byte[200];
                while ((i = inputStream.read(buffer)) != -1){
                    byteArrayOutputStream.write(buffer,0,i);
                }
                String str = new String(byteArrayOutputStream.toByteArray());
                System.out.println(str);
                //错误信息的格式在官方文档里有
                com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(str);
                if ("41030".equals(jsonObject.getString("errcode"))){
                    return new FebsResponse().fail().data("所传page页面不存在,或者小程序没有发布");
                }else if ("45009".equals(jsonObject.getString("errcode"))){
                    return new FebsResponse().fail().data("调用分钟频率受限");
                }
                byteArrayOutputStream.close();
            }
            inputStream.close();
        }catch (Exception e){
            return new FebsResponse().fail().data("获取二维码失败");
        }
        return new FebsResponse().success().data(inputStream);
//        //这里调用的是上面的获取access_token方法
//        String access_token = redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY).toString();
//        String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+access_token;
//        String scene = wxGenerateQrCodeDto.getScene();
//        Map<String, String> param = new HashMap<>();
//        param.put("scene",scene);
//        //这里的page如果没有的话可以不写,默认是跳主页,如果写了没有的页面的话,会返回错误信息
//        param.put("page",wxGenerateQrCodeDto.getPage());
//        String json = JSON.toJSONString(param);
//        ByteArrayInputStream inputStream = sendPost(url, json);
//        try {
//            System.out.println(inputStream);
//            //这里判断的是返回的图片还是错误信息,一般错误信息不会大于200
//            if (inputStream.available() <= 200){
//                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//                int i;
//                byte[] buffer = new byte[200];
//                while ((i = inputStream.read(buffer)) != -1){
//                    byteArrayOutputStream.write(buffer,0,i);
//                }
//                String str = new String(byteArrayOutputStream.toByteArray());
//                byteArrayOutputStream.close();
//                //错误信息
//                com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(str);
//                if ("41030".equals(jsonObject.getString("errcode"))){
//                    return new FebsResponse().fail().data("所传page页面不存在,或者小程序没有发布");
//                }else if ("45009".equals(jsonObject.getString("errcode"))){
//                    return new FebsResponse().fail().data("调用分钟频率受限");
//                }
//            }
//            inputStream.close();
//        }catch (Exception e){
//            return new FebsResponse().fail().data("获取二维码失败");
//        }
        return new FebsResponse().success();
    }
    @Override
@@ -298,11 +297,50 @@
        return wxTemplates;
    }
    @Autowired
    private MallGoodsMapper mallGoodsMapper;
    @Autowired
    private MallTeamLeaderMapper mallTeamLeaderMapper;
    @Override
    public FebsResponse generateQrCode(WxGenerateQrCodeDto wxGenerateQrCodeDto) {
        Integer type = wxGenerateQrCodeDto.getType();
        if(1 == type){
            long goodsId = StrUtil.isBlank(wxGenerateQrCodeDto.getTypeParam()) ? 0L : Long.parseLong(wxGenerateQrCodeDto.getTypeParam());
            MallGoods mallGoods = mallGoodsMapper.selectById(goodsId);
            if(ObjectUtil.isNotNull(mallGoods)){
                String wxCodeImg = mallGoods.getWxCodeImg();
                if(StrUtil.isNotBlank(wxCodeImg)){
                    return new FebsResponse().success().data(wxCodeImg);
                }
            }
        }
        if(2 == type){
            String uniqueCode = wxGenerateQrCodeDto.getTypeParam();
            MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(uniqueCode);
            if(ObjectUtil.isNotNull(mallTeamLeader)){
                String wxCodeImg = mallTeamLeader.getWxCodeImg();
                if(StrUtil.isNotBlank(wxCodeImg)){
                    return new FebsResponse().success().data(wxCodeImg);
                }
            }
        }
        String randomNum = MallUtils.getRandomNum(5);
        String imgName="/user_" + randomNum + "_acode_1.jpg";
        String codeImgPath = generateAcode(wxGenerateQrCodeDto.getScene(), wxGenerateQrCodeDto.getPage(), imgName, "800px", null);
        if(1 == type){
            long goodsId = StrUtil.isBlank(wxGenerateQrCodeDto.getTypeParam()) ? 0L : Long.parseLong(wxGenerateQrCodeDto.getTypeParam());
            MallGoods mallGoods = mallGoodsMapper.selectById(goodsId);
            mallGoods.setWxCodeImg(codeImgPath);
            mallGoodsMapper.updateById(mallGoods);
        }
        if(2 == type){
            String uniqueCode = wxGenerateQrCodeDto.getTypeParam();
            MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(uniqueCode);
            mallTeamLeader.setWxCodeImg(codeImgPath);
            mallTeamLeaderMapper.updateById(mallTeamLeader);
        }
        return new FebsResponse().success().data(codeImgPath);
    }
@@ -363,7 +401,7 @@
    //图片上传路径
    public  static  final String IMG_UPLOAD_PATH="/mnt/sdc/webresource/groupbuy/wxcode";
    public  String generateAcode(String scene,String path,String imgName,String width, Integer type){
        String urlPrefix="http://hwfile.csxuncong.com/groupbuy/wxcode";
        String urlPrefix="https://hwfile.csxuncong.com/groupbuy/wxcode";
        String imgPath=IMG_UPLOAD_PATH+imgName;
        if(!FileUtil.exist(imgPath)){
src/test/java/cc/mrbird/febs/ProfitTest.java
@@ -19,6 +19,7 @@
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -390,7 +391,6 @@
            String json = JSON.toJSONString(param);
            ByteArrayInputStream inputStream = sendPost(url, json);
            System.out.println(inputStream);
            //这里判断的是返回的图片还是错误信息,一般错误信息不会大于200
            if (inputStream.available() <= 200){
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@@ -400,7 +400,6 @@
                    byteArrayOutputStream.write(buffer,0,i);
                }
                String str = new String(byteArrayOutputStream.toByteArray());
                System.out.println(str);
                //错误信息的格式在官方文档里有
                JSONObject jsonObject = JSONObject.parseObject(str);
                if ("41030".equals(jsonObject.getString("errcode"))){
@@ -414,13 +413,13 @@
            //输出到本地的代码
            FileOutputStream fileOutputStream = new FileOutputStream("D:/123.png");
            int i;
            byte[] buffer = new byte[200];
            byte[] buffer = new byte[10240000];
            while ((i = inputStream.read(buffer)) != -1){
                fileOutputStream.write(buffer,0,i);
            }
            fileOutputStream.flush();
            fileOutputStream.close();
            inputStream.close();
        }catch (Exception e){
        }
@@ -459,6 +458,10 @@
                inputStream.close();
                // 把outStream里的数据写入内存
                byteArrayInputStream = new ByteArrayInputStream(outStream.toByteArray());
                byte[] data = outStream.toByteArray();
                String result = new String(Base64.getEncoder().encode(data));
                result = "data:image/jpeg;base64," + result;
                System.out.println(result);
            }
        } catch (Exception e) {
            e.printStackTrace();