From 05f53069a91f979ec3d18e0a7abc8ce67c2656b2 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 04 九月 2025 14:35:01 +0800
Subject: [PATCH] bug修改

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java |  130 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 105 insertions(+), 25 deletions(-)

diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java
index e404966..73054d3 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TIntegralController.java
@@ -6,23 +6,23 @@
 import com.ruoyi.chargingPile.api.model.Site;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.core.web.page.PageInfo;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
+import com.ruoyi.common.redis.service.RedisService;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.other.api.domain.IntegralPay;
 import com.ruoyi.other.api.domain.IntegralRecord;
 import com.ruoyi.other.api.domain.ServicePay;
 import com.ruoyi.other.api.domain.TIntegralRule;
+import com.ruoyi.other.api.dto.NativePayDTO;
 import com.ruoyi.other.query.IntegralListQuery;
 import com.ruoyi.other.service.TIntegralPayService;
 import com.ruoyi.other.service.TIntegralRecordService;
 import com.ruoyi.other.service.TIntegralRuleService;
 import com.ruoyi.other.service.TServicePayService;
-import com.ruoyi.other.util.MyQrCodeUtil;
-import com.ruoyi.other.util.ObsUploadUtil;
-import com.ruoyi.other.util.QRCodeUtil;
-import com.ruoyi.other.util.UUIDUtil;
+import com.ruoyi.other.util.*;
 import com.ruoyi.other.util.pay.CreateLinkStringByGet1;
 import com.ruoyi.other.util.pay.HttpRequester;
 import com.ruoyi.other.util.pay.HttpRespons;
@@ -37,12 +37,19 @@
 import com.ruoyi.system.api.domain.SysUser;
 import com.ruoyi.system.api.feignClient.SysConfigClient;
 import com.ruoyi.system.api.feignClient.SysUserClient;
+import com.ruoyi.system.api.model.LoginUser;
 import io.swagger.annotations.ApiOperation;
+import org.apache.http.HttpResponse;
 import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ByteArrayResource;
+import org.springframework.http.*;
 import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -55,6 +62,7 @@
 import java.net.URL;
 import java.security.KeyFactory;
 import java.security.PrivateKey;
+import java.security.SecureRandom;
 import java.security.Signature;
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.text.SimpleDateFormat;
@@ -82,6 +90,15 @@
     @Autowired
     private SysConfigClient sysConfigClient;
 
+
+
+
+    @Autowired
+    private WxAppletTools wxAppletTools;
+
+
+    @Autowired
+    private RestTemplate restTemplate;
     @Autowired
     private TokenService tokenService;
     @Autowired
@@ -174,15 +191,72 @@
             return R.ok(false);
         }
     }
-
+    @ApiOperation(tags = {"2.0-积分钱包"}, value = "获取小程序二维码")
+    @PostMapping(value = "/getQrCode")
+    public R getQrCode(@RequestParam("amount") String amount ) {
+        LoginUser loginUser = tokenService.getLoginUser();
+        SysUser data = sysUserClient.getSysUser(loginUser.getUserid()).getData();
+        // 充值手机号
+        String phonenumber = data.getPhonenumber();
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        String accessToken = wxAppletTools.getAccessToken();
+        try {
+            String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
+            Map<String, Object> param = new HashMap<>();
+//            param.put("scene", "phone=" + phonenumber);
+            param.put("scene", "phone=" + phonenumber+",amount="+amount);
+            param.put("page", "chargingPile/payMent/payMent");
+            param.put("check_path", false);
+            param.put("env_version", "trial");
+            param.put("width", 200); //二维码尺寸
+            param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效
+            param.put("auto_color", true); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效
+            Map<String, Object> line_color = new HashMap<>();
+            line_color.put("r", 0);
+            line_color.put("g", 0);
+            line_color.put("b", 0);
+            param.put("line_color", line_color);
+            System.err.println("调用生成微信URL接口传参:" + param);
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity requestEntity = new HttpEntity(param, headers);
+            ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+            System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody());
+            byte[] result = entity.getBody();
+            inputStream = new ByteArrayInputStream(result);
+            //拿到httpResponse后,在获取里面的图片
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+            // 最后上传生成的文件名
+            String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
+            // oss中的文件夹名
+            String objectName = sdf.format(new Date()) + "/" + finalFileName;
+            // 上传oss
+            String s = ObsUploadUtil.obsUpload(objectName, inputStream);
+            return R.ok(s);
+        }catch (Exception e){
+            return R.fail(e.getMessage());
+        }
+    }
+    @Resource
+    private WeChatUtil weChatUtil;
     @PostMapping("/nativePay")
     @ApiOperation(tags = {"2.0-积分钱包"}, value = "获取支付二维码")
-    public R nativePay(@RequestParam("amount") String amount) throws Exception {
-        BigDecimal bigDecimal = new BigDecimal(amount);
-        BigDecimal money = bigDecimal.setScale(2, RoundingMode.HALF_UP);
-        Long userid = tokenService.getLoginUser().getUserid();
-        R<SysUser> sysUser = sysUserClient.getSysUser(userid);
-        SysUser data = sysUser.getData();
+    public R nativePay(@RequestBody @Validated NativePayDTO dto) throws Exception {
+
+        R<SysUser> sysUserR = sysUserClient.queryUserByPhone(dto.getPhone());
+        SysUser data = sysUserR.getData();
+        //使用jscode获取微信openid
+        Map<String, Object> map = weChatUtil.code2Session(dto.getJsCode());
+        Integer errcode = Integer.valueOf(map.get("errcode").toString());
+        if(0 != errcode){
+            return R.fail(map.get("msg").toString());
+        }
+        String openid = map.get("openid").toString();
+        data.setOpenId(openid);
+        BigDecimal amount = dto.getAmount();
+        BigDecimal money = amount.setScale(2, RoundingMode.HALF_UP);
+
         List<Site> sites = siteClient.getSiteAll().getData();
         Site site = sites.stream().filter(e -> e.getId().equals(data.getSiteId())).findFirst().orElse(null);
         if (site==null){
@@ -190,15 +264,19 @@
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
         String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
-        ServicePay servicePay = new ServicePay();
-        servicePay.setUserId(data.getUserId());
-        servicePay.setAmount(site.getAnnualServiceFee());
-        servicePay.setCode(code);
-        servicePay.setPayStatus(1);
-        servicePay.setPayType(1);
-        servicePay.setDelFlag(0);
-        servicePay.setCreateTime(LocalDateTime.now());
-        servicePayService.save(servicePay);
+        IntegralPay integralPay = new IntegralPay();
+        integralPay.setUserId(data.getUserId());
+        SysConfig data1 = sysConfigClient.getInfo(8L).getData();
+        BigDecimal bigDecimal = amount.multiply(new BigDecimal(data1.getConfigValue())).setScale(2, RoundingMode.HALF_DOWN);
+        integralPay.setIntegralCount(bigDecimal.intValue());
+        integralPay.setAmount(amount);
+        integralPay.setCode(code);
+        integralPay.setPayStatus(1);
+        integralPay.setDelFlag(0);
+        integralPay.setCreateTime(LocalDateTime.now());
+
+
+        integralPayService.save(integralPay);
 
 
 //        return wechatPayService.unifiedOrderApplet(servicePay.getId()+"",code, site.getAnnualServiceFee()+"", "服务费缴纳",data.getOpenId(), "/other/wx/serviceCallback");
@@ -211,7 +289,7 @@
         Map<String, Object> dataMap = new LinkedHashMap<String, Object>(); // 使用LinkedHashMap保持顺序
         dataMap.put("goods_desc", "积分充值");
         dataMap.put("huifu_id", "6666000174575407");
-        dataMap.put("notify_url", "http://221.182.45.100:8084/other/wx/integralCallback");
+        dataMap.put("notify_url", "http://47.120.5.122:8080/other/wx/integralCallback");
         dataMap.put("req_date", date.format(new Date()));
         dataMap.put("req_seq_id", code);
         dataMap.put("trade_type", "T_MINIAPP");
@@ -281,6 +359,7 @@
         }
 
         System.out.println("接收返回参数:" + response.toString());
+        sysUserClient.updateSysUser(data);
         return R.ok(response.toString());
     }
     @Autowired
@@ -324,7 +403,7 @@
         Map<String, Object> dataMap = new LinkedHashMap<String, Object>(); // 使用LinkedHashMap保持顺序
         dataMap.put("goods_desc", "积分充值");
         dataMap.put("huifu_id", "6666000174575407");
-        dataMap.put("notify_url", "http://221.182.45.100:8084/other/wx/integralCallback");
+        dataMap.put("notify_url", "http://47.120.5.122:8080/other/wx/integralCallback");
         dataMap.put("req_date", date.format(new Date()));
         dataMap.put("req_seq_id", code);
         dataMap.put("trade_type", "T_MINIAPP");
@@ -411,7 +490,7 @@
         Map<String, Object> dataMap = new LinkedHashMap<String, Object>(); // 使用LinkedHashMap保持顺序
         dataMap.put("goods_desc", "积分充值");
         dataMap.put("huifu_id", "6666000174575407");
-        dataMap.put("notify_url", "http://221.182.45.100:8084/other/wx/integralCallback");
+        dataMap.put("notify_url", "http://47.120.5.122:8080/other/wx/integralCallback");
         dataMap.put("req_date", date.format(new Date()));
         dataMap.put("req_seq_id", code);
         dataMap.put("trade_type", "T_JSAPI");
@@ -426,6 +505,7 @@
         // 将dataMap转化为json对象
 
         String signStr = JSON.toJSONString(JSONObject.parseObject(JSON.toJSONString(dataMap), TreeMap.class));
+
 
         System.out.println("待签名字符串:" + signStr);
 
@@ -537,7 +617,7 @@
         if (data != null ) {
             if (data.getRoleType() == 1) {
                 // 平台
-                SysConfig data1 = sysConfigClient.getInfo(8L).getData();
+                SysConfig data1 = sysConfigClient.getInfo(10L).getData();
                 sysConfigClient.update(data1);
                 TIntegralRule tIntegralRule = new TIntegralRule();
                 tIntegralRule.setChargeCredit("{\"num1\":"+data1.getConfigValue()+"}");
@@ -570,7 +650,7 @@
         SysUser data = sysUserClient.getSysUser(userid).getData();
 
         if (data.getRoleType() == 1) {
-            SysConfig data1 = sysConfigClient.getInfo(8L).getData();
+            SysConfig data1 = sysConfigClient.getInfo(10L).getData();
             JSONObject jsonObject = JSONObject.parseObject(dto.getChargeCredit());
             Integer num1 = jsonObject.getInteger("num1");
             data1.setConfigValue(num1.toString());

--
Gitblit v1.7.1