From dcbf66105a86b5983e67e430d7efa73eb4d03dc4 Mon Sep 17 00:00:00 2001
From: chengf <cgf12138@163.com>
Date: 星期日, 31 八月 2025 14:51:53 +0800
Subject: [PATCH] 暂存0829

---
 service-acct/src/main/java/com/java110/acct/payment/adapt/fuiou/FuiouPaymentFactoryAdapt.java |  170 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 115 insertions(+), 55 deletions(-)

diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/fuiou/FuiouPaymentFactoryAdapt.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/fuiou/FuiouPaymentFactoryAdapt.java
index 29e2600..ab07a52 100644
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/fuiou/FuiouPaymentFactoryAdapt.java
+++ b/service-acct/src/main/java/com/java110/acct/payment/adapt/fuiou/FuiouPaymentFactoryAdapt.java
@@ -1,6 +1,7 @@
 package com.java110.acct.payment.adapt.fuiou;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.java110.acct.payment.IPaymentFactoryAdapt;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.factory.CommunitySettingFactory;
@@ -29,10 +30,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -83,9 +81,12 @@
     public static final String TRADE_TYPE_JSAPI = "JSAPI";
     public static final String TRADE_TYPE_MWEB = "MWEB";
     public static final String TRADE_TYPE_APP = "APP";
+    public static final String TRADE_TYPE_LETPAY = "LETPAY";
 
     @Value("${fuiou.pay.unified-order-url}")
     public String PAY_UNIFIED_ORDER_URL;
+    @Value("${fuiou.pay.wx-order-url}")
+    public String PAY_WX_ORDER_URL;
     private static final String VERSION = "1.0";
 
 
@@ -110,6 +111,7 @@
 
         SmallWeChatDto smallWeChatDto = getSmallWechat(reqJson);
 
+        smallWeChatDto.setAppId(reqJson.getString("appId"));
 
         String appId = context.getReqHeaders().get("app-id");
         String userId = context.getReqHeaders().get("user-id");
@@ -118,25 +120,29 @@
 
         String openId = reqJson.getString("openId");
 
-//        if(StringUtil.isEmpty(openId)) {
-//            //鐢变簬鐜板湪鍙湁006锛屾墍浠ュ啓姝籛ECHAT锛屽悗缁鏋滄湁澶氱鏀粯鏂瑰紡鍒欓噸鏂拌璁�
-////            String appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
-////            if (AppDto.WECHAT_OWNER_APP_ID.equals(appId)) {
-////                appType = OwnerAppUserDto.APP_TYPE_WECHAT;
-////            } else if (AppDto.WECHAT_MINA_OWNER_APP_ID.equals(appId)) {
-////                appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
-////            } else {
-////                appType = OwnerAppUserDto.APP_TYPE_APP;
-////            }
-//            String appType = OwnerAppUserDto.APP_TYPE_WECHAT;
-//            OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
-//            ownerAppUserDto.setUserId(userId);
-//            ownerAppUserDto.setAppType(appType);
-//            List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
-//
+        if(StringUtil.isEmpty(openId)) {
+            //鐢变簬鐜板湪鍙湁006锛屾墍浠ュ啓姝籛ECHAT锛屽悗缁鏋滄湁澶氱鏀粯鏂瑰紡鍒欓噸鏂拌璁�
+//            String appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
+//            if (AppDto.WECHAT_OWNER_APP_ID.equals(appId)) {
+//                appType = OwnerAppUserDto.APP_TYPE_WECHAT;
+//            } else if (AppDto.WECHAT_MINA_OWNER_APP_ID.equals(appId)) {
+//                appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
+//            } else {
+//                appType = OwnerAppUserDto.APP_TYPE_APP;
+//            }
+            String appType = OwnerAppUserDto.APP_TYPE_WECHAT;
+            OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+            ownerAppUserDto.setUserId(userId);
+            ownerAppUserDto.setAppType(appType);
+            List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+
 //            Assert.listOnlyOne(ownerAppUserDtos, "鏈壘鍒板紑鏀捐处鍙蜂俊鎭�");
-//            openId = ownerAppUserDtos.get(0).getOpenId();
-//        }
+            try{
+                openId = ownerAppUserDtos.get(0).getOpenId();
+            }catch (Exception e){
+
+            }
+        }
 
 
         logger.debug("銆愬皬绋嬪簭鏀粯銆� 缁熶竴涓嬪崟寮�濮�, 璁㈠崟缂栧彿=" + paymentOrderDto.getOrderId());
@@ -146,20 +152,37 @@
         //娣诲姞鎴栨洿鏂版敮浠樿褰�(鍙傛暟璺熻繘鑷繁涓氬姟闇�姹傛坊鍔�)
 
         JSONObject resMap = null;
-        resMap = this.java110UnifieldOrder(
-                paymentOrderDto.getName(),
-                paymentOrderDto.getOrderId(),
-                tradeType,
-                payAmount,
-                openId,
-                smallWeChatDto,
-                notifyUrl
-        );
+        if (TRADE_TYPE_LETPAY.equals(tradeType)){
+            resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
+                    paymentOrderDto.getOrderId(),
+                    tradeType,
+                    payAmount,
+                    openId,
+                    smallWeChatDto,
+                    notifyUrl
+            );
+        }else{
+
+            resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
+                    paymentOrderDto.getOrderId(),
+                    tradeType,
+                    payAmount,
+                    openId,
+                    smallWeChatDto,
+                    notifyUrl
+            );
+        }
 
         if ("000000".equals(resMap.getString("result_code"))) {
-            if (TRADE_TYPE_JSAPI.equals(tradeType)) {
-//                resultMap.putAll(JSONObject.toJavaObject(JSONObject.parseObject(resMap.getString("reserved_pay_info")), Map.class));
+            if (TRADE_TYPE_LETPAY.equals(tradeType)) {
+                resultMap.putAll(JSONObject.toJavaObject(JSONObject.parseObject(resMap.getString("reserved_pay_info")), Map.class));
                 resultMap.put("sign", resultMap.get("paySign"));
+                resultMap.put("timeStamp", resMap.get("sdk_timestamp").toString());
+                resultMap.put("nonceStr", resMap.get("sdk_noncestr").toString());
+                resultMap.put("package", resMap.get("sdk_package").toString());
+                resultMap.put("signType", resMap.get("sdk_signtype").toString());
+                resultMap.put("paySign", resMap.get("sdk_paysign").toString());
+                resultMap.put("payAppId", resMap.get("sdk_appid").toString());
             } else if (TRADE_TYPE_APP.equals(tradeType)) {
                 resultMap.put("appId", smallWeChatDto.getAppId());
                 resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp());
@@ -167,14 +190,15 @@
                 resultMap.put("partnerid", smallWeChatDto.getMchId());
                 resultMap.put("prepayid", resMap.getString("session_id"));
                 //resultMap.put("signType", "MD5");
-                resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword()));
+                resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getAppSecret()));
             } else if (TRADE_TYPE_NATIVE.equals(tradeType)) {
                 resultMap.put("prepayId", resMap.getString("session_id"));
                 resultMap.put("codeUrl", resMap.getString("qr_code"));
             }
+
+            resultMap.put("qrCode", resMap.getString("qr_code"));
             resultMap.put("code", "0");
             resultMap.put("msg", "涓嬪崟鎴愬姛");
-            resultMap.put("qrCode", resMap.getString("qr_code"));
             logger.info("銆愬皬绋嬪簭鏀粯銆戠粺涓�涓嬪崟鎴愬姛锛岃繑鍥炲弬鏁�:" + resultMap);
         } else {
             resultMap.put("code", resMap.getString("result_code"));
@@ -196,21 +220,48 @@
 //        String orderPre = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "FUIOU_ORDER_PRE");
         String orderPre = smallWeChatDto.getOrderPre();
         JSONObject paramMap = new JSONObject();
+        if (tradeType == null){
+            paramMap.put("version", VERSION);
+            paramMap.put("mchnt_cd", smallWeChatDto.getMchId()); // 瀵屽弸鍒嗛厤缁欎簩绾у晢鎴风殑鍟嗘埛鍙�
+            paramMap.put("random_str", PayUtil.makeUUID(32));
+            paramMap.put("order_amt", PayUtil.moneyToIntegerStr(payAmount));
+            paramMap.put("mchnt_order_no", orderPre + orderNum);
+            paramMap.put("txn_begin_ts", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_DEFAULT));
+            paramMap.put("goods_des", "cesdasw");
+            paramMap.put("term_id", "abcdefgh");
+            paramMap.put("term_ip", PayUtil.getLocalIp());
+            paramMap.put("notify_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
+            paramMap.put("order_type", "WECHAT");
+            paramMap.put("sub_openid", openid);
+            paramMap.put("sub_appid", smallWeChatDto.getAppId());
+            paramMap.put("sign", createSignByQrCode(paramMap, smallWeChatDto.getAppSecret()));
+
+            logger.debug("璋冪敤鏀粯缁熶竴涓嬪崟鎺ュ彛" + paramMap.toJSONString());
+            HttpHeaders headers = new HttpHeaders();
+            headers.add("Content-Type", "application/json");
+            HttpEntity httpEntity = new HttpEntity(paramMap.toJSONString(), headers);
+            ResponseEntity<String> responseEntity = outRestTemplate.exchange(
+                    PAY_UNIFIED_ORDER_URL, HttpMethod.POST, httpEntity, String.class);
+
+            logger.debug("缁熶竴涓嬪崟杩斿洖" + responseEntity);
+
+            if (responseEntity.getStatusCode() != HttpStatus.OK) {
+                throw new IllegalArgumentException("鏀粯澶辫触" + responseEntity.getBody());
+            }
+            return JSONObject.parseObject(responseEntity.getBody());
+        }
+        paramMap.put("version", VERSION);
         paramMap.put("mchnt_cd", smallWeChatDto.getMchId()); // 瀵屽弸鍒嗛厤缁欎簩绾у晢鎴风殑鍟嗘埛鍙�
-        paramMap.put("order_type", "WECHAT");
-//        paramMap.put("order_amt", PayUtil.moneyToIntegerStr(payAmount));
-        paramMap.put("order_amt", (int)(payAmount*100));
-//        paramMap.put("order_amt", 1);
+        paramMap.put("random_str", PayUtil.makeUUID(32));
+        paramMap.put("order_amt", PayUtil.moneyToIntegerStr(payAmount));
         paramMap.put("mchnt_order_no", orderPre + orderNum);
         paramMap.put("txn_begin_ts", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_DEFAULT));
-        paramMap.put("goods_des", feeName);
+        paramMap.put("goods_des", "cesdasw");
         paramMap.put("term_id", "abcdefgh");
         paramMap.put("term_ip", PayUtil.getLocalIp());
         paramMap.put("notify_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
-        paramMap.put("random_str", PayUtil.makeUUID(32));
-        paramMap.put("version", VERSION);
         paramMap.put("trade_type", tradeType);
-//        paramMap.put("sub_openid", openid);
+        paramMap.put("sub_openid", openid);
         paramMap.put("sub_appid", smallWeChatDto.getAppId());
         paramMap.put("sign", createSign(paramMap, smallWeChatDto.getAppSecret()));
 
@@ -219,7 +270,7 @@
         headers.add("Content-Type", "application/json");
         HttpEntity httpEntity = new HttpEntity(paramMap.toJSONString(), headers);
         ResponseEntity<String> responseEntity = outRestTemplate.exchange(
-                PAY_UNIFIED_ORDER_URL, HttpMethod.POST, httpEntity, String.class);
+                PAY_WX_ORDER_URL, HttpMethod.POST, httpEntity, String.class);
 
         logger.debug("缁熶竴涓嬪崟杩斿洖" + responseEntity);
 
@@ -267,7 +318,7 @@
             String wId = map.get("wId").toString();
             wId = wId.replace(" ", "+");
             appId = WechatFactory.getAppId(wId);
-        } else if(map.containsKey("appId")) {
+        } else {
             appId = map.get("appid").toString();
         }
         SortedMap<String, String> paramMap = new TreeMap<String, String>();
@@ -284,7 +335,7 @@
         paramIn.put("communityId",notifyPaymentOrderDto.getCommunityId());
         SmallWeChatDto smallWeChatDto = getSmallWechat(paramIn);
 
-        String sign = createSign(map, smallWeChatDto.getPayPassword());
+        String sign = createSign(map, smallWeChatDto.getAppSecret());
 
         if (!sign.equals(map.get("sign"))) {
 //            throw new IllegalArgumentException("閴存潈澶辫触");
@@ -298,14 +349,6 @@
 
     private SmallWeChatDto getSmallWechat(JSONObject paramIn) {
 
-//        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
-//        smallWeChatDto.setObjId(paramIn.getString("communityId"));
-//        smallWeChatDto.setAppId(paramIn.getString("appId"));
-//        smallWeChatDto.setPage(1);
-//        smallWeChatDto.setRow(1);
-//        List<SmallWeChatDto> smallWeChatDtos = smallWechatV1InnerServiceSMOImpl.querySmallWechats(smallWeChatDto);
-
-//        if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
         SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
         //鐢变簬瀵屾湁鏀粯鏂瑰紡瑕佷粠鏁版嵁搴撻噷闈㈠彇鍊硷紝鎵�浠ユ澶勮鏌ヨ
         PaymentPoolDto paymentPoolDto = new PaymentPoolDto();
@@ -356,7 +399,7 @@
      */
     private String createSign(JSONObject paramMap, String payPassword) {
         String str = paramMap.getString("mchnt_cd") + "|"
-                + paramMap.getString("order_type") + "|"
+                + paramMap.getString("trade_type") + "|"
                 + paramMap.getString("order_amt") + "|"
                 + paramMap.getString("mchnt_order_no") + "|"
                 + paramMap.getString("txn_begin_ts") + "|"
@@ -370,4 +413,21 @@
         return PayUtil.md5(str);
     }
 
+
+
+    private String createSignByQrCode(JSONObject paramMap, String payPassword) {
+        String str = paramMap.getString("mchnt_cd") + "|"
+                + paramMap.getString("order_type") + "|"
+                + paramMap.getString("order_amt") + "|"
+                + paramMap.getString("mchnt_order_no") + "|"
+                + paramMap.getString("txn_begin_ts") + "|"
+                + paramMap.getString("goods_des") + "|"
+                + paramMap.getString("term_id") + "|"
+                + paramMap.getString("term_ip") + "|"
+                + paramMap.getString("notify_url") + "|"
+                + paramMap.getString("random_str") + "|"
+                + paramMap.getString("version") + "|"
+                + payPassword;
+        return PayUtil.md5(str);
+    }
 }

--
Gitblit v1.8.0