From ee93d2d3d6af26beae5fd515127c14ab4c555778 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Tue, 06 Sep 2022 11:40:18 +0800
Subject: [PATCH] 20220902

---
 src/main/resources/mapper/modules/MallTeamLeaderMapper.xml                        |    1 
 src/main/java/cc/mrbird/febs/mall/service/IApiMallAddressInfoService.java         |    3 
 src/main/java/cc/mrbird/febs/mall/controller/ApiLoginController.java              |   13 +++
 src/test/java/cc/mrbird/febs/ProfitTest.java                                      |  104 +++++++++++++++++++++++++
 src/main/java/cc/mrbird/febs/pay/service/impl/XcxPayServiceImpl.java              |   59 +++++++-------
 src/main/java/cc/mrbird/febs/mall/controller/ApiMallAddressInfoController.java    |    3 
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallAddressInfoServiceImpl.java |    5 +
 7 files changed, 153 insertions(+), 35 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/controller/ApiLoginController.java b/src/main/java/cc/mrbird/febs/mall/controller/ApiLoginController.java
index 7196119..1dfd151 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/ApiLoginController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/ApiLoginController.java
@@ -1,15 +1,18 @@
 package cc.mrbird.febs.mall.controller;
 
 import cc.mrbird.febs.common.entity.FebsResponse;
+import cc.mrbird.febs.common.utils.RedisUtils;
 import cc.mrbird.febs.mall.dto.*;
 import cc.mrbird.febs.mall.service.IApiMallMemberService;
 import cc.mrbird.febs.pay.model.WxGenerateQrCodeDto;
 import cc.mrbird.febs.pay.service.IXcxPayService;
+import cc.mrbird.febs.pay.util.WechatConfigure;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import net.sf.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -31,6 +34,7 @@
 
     private final IApiMallMemberService memberService;
     private final IXcxPayService iXcxPayService;
+    private final RedisUtils redisUtils;
 
     @ApiOperation(value = "app注册接口", notes = "app注册接口")
     @PostMapping(value = "/register")
@@ -107,4 +111,13 @@
         return iXcxPayService.generateQrCode(wxGenerateQrCodeDto);
     }
 
+    /**
+     * 获取ACCESS_TOKEN
+     */
+    @ApiOperation(value = "获取ACCESS_TOKEN", notes = "获取ACCESS_TOKEN")
+    @GetMapping(value = "/getAccessToken")
+    public FebsResponse getAccessToken(){
+        return new FebsResponse().success().data(redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY).toString());
+    }
+
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/controller/ApiMallAddressInfoController.java b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallAddressInfoController.java
index 35b5dc0..6130cf7 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/ApiMallAddressInfoController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallAddressInfoController.java
@@ -53,8 +53,7 @@
     @ApiOperation(value = "添加地址", notes = "添加地址")
     @PostMapping(value = "/addAddress")
     public FebsResponse addAddress(@RequestBody AddressInfoDto addressInfoDto) {
-        mallAddressInfoService.addAddress(addressInfoDto);
-        return new FebsResponse().success().message("添加成功");
+        return mallAddressInfoService.addAddress(addressInfoDto);
     }
 
     @ApiOperation(value = "修改地址", notes = "修改地址")
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IApiMallAddressInfoService.java b/src/main/java/cc/mrbird/febs/mall/service/IApiMallAddressInfoService.java
index 64d27c3..d4d5a65 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/IApiMallAddressInfoService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/IApiMallAddressInfoService.java
@@ -1,5 +1,6 @@
 package cc.mrbird.febs.mall.service;
 
+import cc.mrbird.febs.common.entity.FebsResponse;
 import cc.mrbird.febs.mall.dto.AddressInfoDto;
 import cc.mrbird.febs.mall.entity.MallAddressInfo;
 import cc.mrbird.febs.mall.vo.AddressInfoVo;
@@ -11,7 +12,7 @@
 
     List<AddressInfoVo> findAddressInfoList();
 
-    void addAddress(AddressInfoDto addressInfoDto);
+    FebsResponse addAddress(AddressInfoDto addressInfoDto);
 
     void modifyAddress(AddressInfoDto addressInfoDto);
 
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallAddressInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallAddressInfoServiceImpl.java
index a9b258c..4ebfcd9 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallAddressInfoServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallAddressInfoServiceImpl.java
@@ -1,5 +1,6 @@
 package cc.mrbird.febs.mall.service.impl;
 
+import cc.mrbird.febs.common.entity.FebsResponse;
 import cc.mrbird.febs.common.exception.FebsException;
 import cc.mrbird.febs.common.utils.LoginUserUtil;
 import cc.mrbird.febs.mall.conversion.MallAddressInfoConversion;
@@ -36,7 +37,7 @@
     }
 
     @Override
-    public void addAddress(AddressInfoDto addressInfoDto) {
+    public FebsResponse addAddress(AddressInfoDto addressInfoDto) {
         MallAddressInfo addressInfo = MallAddressInfoConversion.INSTANCE.dtoToEntity(addressInfoDto);
 
         MallMember member = LoginUserUtil.getLoginUser();
@@ -54,6 +55,8 @@
         addressInfo.setCreatedBy(member.getPhone());
         addressInfo.setUpdatedBy(member.getPhone());
         this.baseMapper.insert(addressInfo);
+
+        return new FebsResponse().success().data(addressInfo.getId());
     }
 
     @Override
diff --git a/src/main/java/cc/mrbird/febs/pay/service/impl/XcxPayServiceImpl.java b/src/main/java/cc/mrbird/febs/pay/service/impl/XcxPayServiceImpl.java
index b41bbb9..2b29706 100644
--- a/src/main/java/cc/mrbird/febs/pay/service/impl/XcxPayServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/pay/service/impl/XcxPayServiceImpl.java
@@ -249,34 +249,37 @@
     @Override
     public FebsResponse generateQrCode(WxGenerateQrCodeDto wxGenerateQrCodeDto) {
         String base64 = null;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY);
-            Map<String, Object> params = new HashMap<>();
-            params.put("scene", wxGenerateQrCodeDto.getScene());
-            params.put("page", wxGenerateQrCodeDto.getPage());
-            params.put("width", 430);
-            ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(url, params, byte[].class);
-            if (responseEntity.getStatusCode() == HttpStatus.OK) {
-                byte[] body = responseEntity.getBody();
-                InputStream inputStream = new ByteArrayInputStream(body);
-                // 将获取流转为base64格式
-                byte[] data = null;
-                ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
-                byte[] buff = new byte[100];
-                int rc = 0;
-                while ((rc = inputStream.read(buff, 0, 100)) > 0) {
-                    swapStream.write(buff, 0, rc);
-                }
-                data = swapStream.toByteArray();
-                base64 = Base64.byteArrayToBase64(data);
-                inputStream.close();
-                swapStream.close();
-            }
-        } catch (IOException e) {
-            throw new ApiException("生成二维码失败");
-        }
-        return new FebsResponse().success().data(base64);
+//        try {
+//            RestTemplate restTemplate = new RestTemplate();
+//            String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY);
+//            Map<String, Object> params = new HashMap<>();
+//            params.put("scene", wxGenerateQrCodeDto.getScene());
+//            params.put("page", wxGenerateQrCodeDto.getPage());
+//            params.put("width", 430);
+//            ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(url, params, byte[].class);
+//            log.info(String.valueOf(JSONUtil.parse(responseEntity)));
+//            if (responseEntity.getStatusCode() == HttpStatus.OK) {
+//                byte[] body = responseEntity.getBody();
+//                InputStream inputStream = new ByteArrayInputStream(body);
+//                // 将获取流转为base64格式
+//                byte[] data = null;
+//                ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
+//                byte[] buff = new byte[100];
+//                int rc = 0;
+//                while ((rc = inputStream.read(buff, 0, 100)) > 0) {
+//                    swapStream.write(buff, 0, rc);
+//                }
+//                data = swapStream.toByteArray();
+//                base64 = Base64.byteArrayToBase64(data);
+//                inputStream.close();
+//                swapStream.close();
+//
+//                return new FebsResponse().success().data(body);
+//            }
+//        } catch (IOException e) {
+//            throw new ApiException("生成二维码失败");
+//        }
+        return new FebsResponse().success();
     }
 
     /**
diff --git a/src/main/resources/mapper/modules/MallTeamLeaderMapper.xml b/src/main/resources/mapper/modules/MallTeamLeaderMapper.xml
index b687adf..fcd5bac 100644
--- a/src/main/resources/mapper/modules/MallTeamLeaderMapper.xml
+++ b/src/main/resources/mapper/modules/MallTeamLeaderMapper.xml
@@ -74,6 +74,7 @@
         <result column="carriage" property="carriage" />
         <result column="remark" property="remark" />
         <result column="del_flag" property="delFlag" />
+        <result column="is_home" property="isHome" />
         <collection property="items" ofType="cc.mrbird.febs.mall.entity.MallOrderItem">
             <id property="id" column="item_id" />
             <result property="orderId" column="order_id" />
diff --git a/src/test/java/cc/mrbird/febs/ProfitTest.java b/src/test/java/cc/mrbird/febs/ProfitTest.java
index c147e50..92113df 100644
--- a/src/test/java/cc/mrbird/febs/ProfitTest.java
+++ b/src/test/java/cc/mrbird/febs/ProfitTest.java
@@ -4,7 +4,10 @@
 import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
 import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
 import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
+import cc.mrbird.febs.common.properties.XcxProperties;
 import cc.mrbird.febs.common.utils.MallUtils;
+import cc.mrbird.febs.common.utils.RedisUtils;
+import cc.mrbird.febs.common.utils.SpringContextHolder;
 import cc.mrbird.febs.mall.dto.ApiLeaderOrderConfirmDto;
 import cc.mrbird.febs.mall.entity.*;
 import cc.mrbird.febs.mall.mapper.*;
@@ -12,23 +15,41 @@
 import cc.mrbird.febs.mall.vo.ApiLeaderProfitVo;
 import cc.mrbird.febs.pay.model.WxGenerateQrCodeDto;
 import cc.mrbird.febs.pay.service.IXcxPayService;
+import cc.mrbird.febs.pay.util.WechatConfigure;
 import cc.mrbird.febs.rabbit.consumer.AgentConsumer;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import lombok.RequiredArgsConstructor;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
+import java.io.*;
 import java.math.BigDecimal;
-import java.util.Date;
+import java.net.HttpURLConnection;
+import java.util.*;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Base64;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -182,7 +203,7 @@
     private IXcxPayService iXcxPayService;
 
     @Test
-    public void qrcode(){
+    public void qrcodeBase64(){
         WxGenerateQrCodeDto wxGenerateQrCodeDto = new WxGenerateQrCodeDto();
         wxGenerateQrCodeDto.setPage("wxGenerateQrCodeDto");
         wxGenerateQrCodeDto.setScene("15");
@@ -286,6 +307,83 @@
         System.out.println(monthProfit +";");
     }
 
+    @Autowired
+    RedisUtils redisUtils;
+
+
+
+    @Test
+    public void qrcode(){
+//        RestTemplate restTemplate = new RestTemplate();
+//        String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY);
+//        Map<String, Object> params = new HashMap<>();
+//        params.put("scene", "pages/index/index");
+//        params.put("page", "15");
+//        params.put("width", 430);
+//        ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(url, params, byte[].class);
+//        System.out.println(responseEntity.getBody());xcx_appid: wx0b515f652282158e
+//  xcx_secret: 8d3d3c14221f7dc37650b861dc0fc570
+
+        String imageNames = System.currentTimeMillis() + IdUtil.simpleUUID();
+        String s = getminiqrQr("15", redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY).toString(), "pages/index/index");
+        System.out.print(s);
+    }
+
+    private static final String GET_WXACODE ="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=";
+    /**
+     * 生成小程序码返回base64字符串
+     * @param sceneStr 要携带的参数
+     * @param accessToken 上面方法得到的token
+     * @param page 要跳转的小程序页面(必须是已发布的)
+     * @return
+     */
+
+    private static final String GETWXACODEUNLIMIT_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s";// 生成小程序码地址
+    private static final String URL_GET_TOKEN = "https://api.weixin.qq.com/cgi-bin/token";//获取access_token地址
+    private static final String APP_ID = "wx0b515f652282158e";// 小程序appid
+    private static final String APP_SECRET = "8d3d3c14221f7dc37650b861dc0fc570"; // 小程序秘钥
+
+    public static final String PATH_HOME = "";
+    private static final String BASE_PREFIX = "data:image/png;base64,"; // base64图片固定前缀
+    public static String getminiqrQr(String sceneStr, String accessToken,String page) {
+        HttpURLConnection httpURLConnection = null;
+        try {
+            URL url = new URL(String.format(GETWXACODEUNLIMIT_URL,accessToken));
+            httpURLConnection = (HttpURLConnection) url.openConnection();
+            httpURLConnection.setRequestMethod("POST");// 提交模式
+            // 发送POST请求必须设置如下两行
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
+            // 发送请求参数
+            JSONObject paramJson = new JSONObject();
+            paramJson.put("scene", sceneStr);
+            paramJson.put("page", page);
+            printWriter.write(paramJson.toString());
+            // flush输出流的缓冲
+            printWriter.flush();
+            //开始获取数据
+
+            BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
+            try (InputStream is = httpURLConnection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();){
+                byte[] buffer = new byte[1024];
+                int len = -1;
+                while ((len = is.read(buffer)) != -1) {
+                    baos.write(buffer, 0, len);
+                }
+                return BASE_PREFIX+ Base64.getEncoder().encodeToString(baos.toByteArray());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }finally {
+            if (httpURLConnection != null){
+                httpURLConnection.disconnect();
+            }
+        }
+        return null;
+    }
+
     public static void main(String[] args) {
         BigDecimal amount = new BigDecimal("0.15").setScale(2,BigDecimal.ROUND_DOWN);
         System.out.println(amount);

--
Gitblit v1.9.1