Kaynağa Gözat

正式测试环境做区分

yq 3 yıl önce
ebeveyn
işleme
6c11c2128a

+ 0 - 3
src/main/java/com/usky/dxtop/common/utils/QRCodeUtil.java

@@ -21,9 +21,6 @@ import com.google.zxing.Result;
 import com.google.zxing.common.BitMatrix;
 import com.google.zxing.common.HybridBinarizer;
 import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
-import com.usky.dxtop.common.utils.sign.Md5Utils;
-import com.usky.dxtop.common.utils.uuid.UUID;
-import com.usky.dxtop.service.api.TopApi;
 
 /**
  * 二维码生成

+ 5 - 2
src/main/java/com/usky/dxtop/controller/web/TopNotifyController.java

@@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.usky.dxtop.model.Order;
 import com.usky.dxtop.service.CallApiLogService;
 import com.usky.dxtop.service.OrderService;
-import com.usky.dxtop.service.api.TopApi;
+import com.usky.dxtop.service.api.TopApiConfiger;
 import com.usky.dxtop.service.impl.OrderServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +31,9 @@ public class TopNotifyController {
     @Autowired
     private CallApiLogService callApiLogService;
 
+    @Autowired
+    private TopApiConfiger topApiConfiger;
+
     @PostMapping("/notify")
     public void test(@RequestParam(required = false) String merchantNo,
                      @RequestParam(required = false) String storeNo,
@@ -74,7 +77,7 @@ public class TopNotifyController {
             if (null == order){
                 log.error("---订单回调"+"订单编号不存在");
             }else {
-                callApiLogService.saveOrUpdate(merchantOrderNo,OrderServiceImpl.SCAN_PAY, TopApi.SCAN_TO_PAY_URL,null,JSONObject.toJSONString(tMap));
+                callApiLogService.saveOrUpdate(merchantOrderNo,OrderServiceImpl.SCAN_PAY, topApiConfiger.scanPayUrl,null,JSONObject.toJSONString(tMap));
                 orderService.paySuccess(order);
             }
         }catch (Exception e){

+ 9 - 7
src/main/java/com/usky/dxtop/controller/web/WxController.java

@@ -7,8 +7,9 @@ import com.usky.dxtop.common.utils.DateUtils;
 import com.usky.dxtop.common.utils.http.HttpUtils;
 import com.usky.dxtop.common.utils.sign.Md5Utils;
 import com.usky.dxtop.common.utils.uuid.UUID;
-import com.usky.dxtop.service.api.TopApi;
+import com.usky.dxtop.service.api.TopApiConfiger;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
@@ -24,15 +25,16 @@ import java.util.TreeMap;
 public class WxController {
 
     private static final String WX_LOGIN_URL = "https://api.weixin.qq.com/sns/jscode2session";
-
+    @Autowired
+    private TopApiConfiger topApiConfiger;
     @GetMapping("/wxLogin")
     public String wxLogin(@RequestParam String jsCode){
         TreeMap<String, String> treeMap = new TreeMap<>();
-        treeMap.put("appid", TopApi.WX_APP_ID);
-        treeMap.put("secret", TopApi.WX_APP_SECRET);
+        treeMap.put("appid", topApiConfiger.wxAppId);
+        treeMap.put("secret", topApiConfiger.wxAppSecret);
         treeMap.put("js_code", jsCode);
         treeMap.put("grant_type", "authorization_code");
-        String result = HttpUtils.sendGet(WX_LOGIN_URL, TopApi.joinParam(treeMap),null);
+        String result = HttpUtils.sendGet(WX_LOGIN_URL, topApiConfiger.joinParam(treeMap),null);
         JSONObject obj= JSON.parseObject(result);
         log.info("获取到的相应"+obj);
         String openId = "";
@@ -47,12 +49,12 @@ public class WxController {
     @GetMapping("/wxPayParam")
     public String wxPayParam(@RequestParam String payInfo){
         TreeMap<String, String> treeMap = new TreeMap<>();
-        treeMap.put("appid", TopApi.WX_APP_ID);
+        treeMap.put("appid", topApiConfiger.wxAppId);
         treeMap.put("timeStamp", DateUtils.dateTimeNow());
         treeMap.put("nonceStr", UUID.randomUUID().toString(true));
         treeMap.put("package", String.format("prepay_id=%s",payInfo));
         treeMap.put("signType", "MD5");
-        String format = String.format("%s&key=%s", TopApi.joinParam(treeMap), TopApi.SECRET);
+        String format = String.format("%s&key=%s", topApiConfiger.joinParam(treeMap), topApiConfiger.secret);
         treeMap.put("paySign", Md5Utils.hash(format).toUpperCase());
         return JSONObject.toJSONString(treeMap);
     }

+ 46 - 33
src/main/java/com/usky/dxtop/service/api/TopApi.java → src/main/java/com/usky/dxtop/service/api/TopApiConfiger.java

@@ -5,6 +5,10 @@ import com.usky.dxtop.common.utils.DateUtils;
 import com.usky.dxtop.common.utils.StringUtils;
 import com.usky.dxtop.common.utils.sign.Md5Utils;
 import com.usky.dxtop.common.utils.uuid.UUID;
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
 
 import java.util.Map;
 import java.util.TreeMap;
@@ -13,65 +17,74 @@ import java.util.TreeMap;
  * @author yq
  * @date 2021/8/23 14:50
  */
-public class TopApi {
+@Data
+@Component
+@ConfigurationProperties(prefix = "toppay")
+public class TopApiConfiger {
 
     /**
      * 版本
      */
-    public static final String VERSION = "v1.0";
-
-    public static final String URL = "https://interfacetest.allinpaygx.com";
-
+    @Value("${toppay.version}")
+    public String version;
     /**
      * 扫码支付
      */
-    public static final String SCAN_TO_PAY_URL = String.format("%s%s",URL,"/api/access/payInterface/usePaymentCode");
+    @Value("${toppay.scanPayUrl}")
+    public String scanPayUrl;
     /**
      * 交易查询
      */
-    public static final String DEAL_SELECT_URL = String.format("%s%s",URL,"/api/access/payInterface/findOrderInfo");
+    @Value("${toppay.dealSelectUrl}")
+    public  String dealSelectUrl;
 
     /**
      * 统一支付
      */
-    public static final String UNIFY_URL = String.format("%s%s",URL,"/api/access/payInterface/unifiedPay");
+    @Value("${toppay.unifyUrl}")
+    public String unifyUrl;
 
     /**
      * 商户编号
      */
-    public static final String MERCHANT_NO = "121050000127";
+    @Value("${toppay.merchantNo}")
+    public String merchantNo;
 
     /**
      * 密钥
      */
-    public static final String SECRET = "MTEODEKT";
+    @Value("${toppay.secret}")
+    public String secret;
 
     /**
      * 回调url
      */
-    public static final String SCAN_NOTIFY_URL = "https://wx.ewoogi.com/dxapi/top/notify";
+    @Value("${toppay.notifyUrl}")
+    public String notifyUrl;
 
     /**
      * 微信appid
      */
-    public static final String WX_APP_ID = "wx40274c2aaec24330";
+    @Value("${toppay.wxAppId}")
+    public String wxAppId;
 
     /**
      * 微信密钥
      */
-    public static final String WX_APP_SECRET = "4b0c04f796a8bed2c2435cc68362b22b";
+    @Value("${toppay.wxAppSecret}")
+    public String wxAppSecret;
 
     /**
      * 拼接扫码支付参数
      * @return
      */
-    public static TreeMap<String, String> generateScanPayApiParam(String merchantOrderNo, Integer amount, String note,
+    public TreeMap<String, String> generateScanPayApiParam(String merchantOrderNo, Integer amount, String note,
                                                                   String storeNo, String backUrl, String orderNumber,
                                                                   String validTime, String remark, String goods){
         TreeMap<String, String> tMap = new TreeMap<>();
-        tMap.put("version",VERSION);
+        tMap.put("version",version);
         tMap.put("payTime",DateUtils.dateTimeNow());
-        tMap.put("merchantNo",MERCHANT_NO);
+        tMap.put("merchantNo",merchantNo);
         tMap.put("merchantOrderNo",merchantOrderNo);
         tMap.put("amount",amount.toString());
         tMap.put("note",note);
@@ -80,7 +93,7 @@ public class TopApi {
         tMap.put("orderNumber",orderNumber);
         tMap.put("validTime",validTime);
         tMap.put("remark",remark);
-        tMap.put("notifyUrl",SCAN_NOTIFY_URL);
+        tMap.put("notifyUrl",notifyUrl);
         tMap.put("goods",goods);
         return tMap;
     }
@@ -93,10 +106,10 @@ public class TopApi {
      * @param groupNo
      * @return
      */
-    public static TreeMap<String, String> generateDealSelectParam(String merchantOrderNo,String storeNo,String trxid,String groupNo){
+    public  TreeMap<String, String> generateDealSelectParam(String merchantOrderNo,String storeNo,String trxid,String groupNo){
         TreeMap<String, String> tMap = new TreeMap<>();
-        tMap.put("version",VERSION);
-        tMap.put("merchantNo",MERCHANT_NO);
+        tMap.put("version",version);
+        tMap.put("merchantNo",merchantNo);
         tMap.put("merchantOrderNo",merchantOrderNo);
         tMap.put("storeNo",storeNo);
         tMap.put("trxid",trxid);
@@ -115,11 +128,11 @@ public class TopApi {
      * @param groupNo
      * @return
      */
-    public static TreeMap<String, String> generateReturnDealParam(Integer amount,String orderNo,String oriMerchantOrderNo,
+    public TreeMap<String, String> generateReturnDealParam(Integer amount,String orderNo,String oriMerchantOrderNo,
                                                                   String trxid,String refundType,String remark,String groupNo){
         TreeMap<String, String> tMap = new TreeMap<>();
-        tMap.put("version",VERSION);
-        tMap.put("merchantNo",MERCHANT_NO);
+        tMap.put("version",version);
+        tMap.put("merchantNo",merchantNo);
         tMap.put("amount",amount.toString());
         tMap.put("orderNo",orderNo);
         tMap.put("oriMerchantOrderNo",oriMerchantOrderNo);
@@ -149,17 +162,17 @@ public class TopApi {
      * @param consumerIp
      * @return
      */
-    public static TreeMap<String, String> generateUnifyParam(String merchantOrderNo,Integer amount,String notifyUrl,
+    public TreeMap<String, String> generateUnifyParam(String merchantOrderNo,Integer amount,String notifyUrl,
                                                              String backUrl,String note,String orderName,String acct,
                                                              String payType,String validTime,String subAppid,
                                                              String remark,String asinfo,String groupNo,
                                                              String consumerIp){
         TreeMap<String, String> tMap = new TreeMap<>();
-        tMap.put("version",VERSION);
-        tMap.put("merchantNo",MERCHANT_NO);
+        tMap.put("version",version);
+        tMap.put("merchantNo",merchantNo);
         tMap.put("merchantOrderNo",merchantOrderNo);
         tMap.put("amount",amount.toString());
-        tMap.put("notifyUrl",SCAN_NOTIFY_URL);
+        tMap.put("notifyUrl",notifyUrl);
         tMap.put("backUrl",backUrl);
         tMap.put("note",note);
         tMap.put("orderName",orderName);
@@ -175,13 +188,13 @@ public class TopApi {
     }
 
 
-    public static String generateParam(TreeMap<String, String> params){
+    public String generateParam(TreeMap<String, String> params){
         return String.format("%s&sign=%s",
-                TopApi.joinParam(params),
-                TopApi.signData(params));
+                this.joinParam(params),
+                this.signData(params));
     }
 
-    public static String joinParam(TreeMap<String, String> params){
+    public String joinParam(TreeMap<String, String> params){
         StringBuilder buf = new StringBuilder();
         for (Map.Entry<String, String> entry : params.entrySet()) {
             if (!StringUtils.isBlank(entry.getValue()) && !"sign".equals(entry.getKey())) {
@@ -200,14 +213,14 @@ public class TopApi {
      * @param treeMap
      * @return
      */
-    public static String signData(Map<String, String> treeMap) {
+    public String signData(Map<String, String> treeMap) {
         StringBuilder buf = new StringBuilder();
         for (Map.Entry<String, String> entry : treeMap.entrySet()) {
             if (!StringUtils.isBlank(entry.getValue()) && !"sign".equals(entry.getKey())) {
                 buf.append(entry.getKey()).append(entry.getValue());
             }
         }
-        buf.append(SECRET);
+        buf.append(secret);
         return Md5Utils.hash(buf.toString()).toUpperCase();
     }
 

+ 16 - 14
src/main/java/com/usky/dxtop/service/impl/OrderServiceImpl.java

@@ -19,7 +19,7 @@ import com.usky.dxtop.common.utils.sign.Base64;
 import com.usky.dxtop.mapper.OrderMapper;
 import com.usky.dxtop.model.*;
 import com.usky.dxtop.service.*;
-import com.usky.dxtop.service.api.TopApi;
+import com.usky.dxtop.service.api.TopApiConfiger;
 import com.usky.dxtop.service.config.rabbitmq.charge.ChargeConsumeConfig;
 import com.usky.dxtop.service.emun.AsyncResultType;
 import com.usky.dxtop.service.emun.OrderPayType;
@@ -93,6 +93,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
     private ISysAsyncTaskService sysAsyncTaskService;
     @Autowired
     private SysFileService sysFileService;
+    @Autowired
+    private TopApiConfiger topApiConfiger;
 
     @Transactional(rollbackFor = Exception.class)
     @Override
@@ -150,12 +152,12 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
     @Override
     public String getTopScanPayApi(Order order){
         verifyOrder(order);
-        TreeMap<String, String> params = TopApi.generateScanPayApiParam(order.getOrderNumber(),
+        TreeMap<String, String> params = topApiConfiger.generateScanPayApiParam(order.getOrderNumber(),
                                         new Double(Arith.mul(order.getMoney().doubleValue(),100)).intValue(), null,
                 null,null,null,null,null,null);
         //记录调用日志
-        callApiLogService.saveOrUpdate(order.getOrderNumber(),SCAN_PAY,TopApi.SCAN_TO_PAY_URL,JSONObject.toJSONString(params),null);
-        return String.format("%s?%s",TopApi.SCAN_TO_PAY_URL,TopApi.generateParam(params));
+        callApiLogService.saveOrUpdate(order.getOrderNumber(),SCAN_PAY, topApiConfiger.scanPayUrl,JSONObject.toJSONString(params),null);
+        return String.format("%s?%s", topApiConfiger.scanPayUrl, topApiConfiger.generateParam(params));
     }
 
     /**
@@ -191,9 +193,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
     @Transactional(rollbackFor = Exception.class)
     @Override
     public String callTopFindOrderInfoApi(String orderNumber) {
-        TreeMap<String, String> param = TopApi.generateDealSelectParam(orderNumber, null, null, null);
-        String format = TopApi.generateParam(param);
-        String result = HttpUtils.sendGet(TopApi.DEAL_SELECT_URL, format,null);
+        TreeMap<String, String> param = topApiConfiger.generateDealSelectParam(orderNumber, null, null, null);
+        String format = topApiConfiger.generateParam(param);
+        String result = HttpUtils.sendGet(topApiConfiger.dealSelectUrl, format,null);
         Order order = one(orderNumber);
         //处理订单
         checkOrder(order, result,JSONObject.toJSONString(param));
@@ -276,7 +278,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
                 orderError(order);
             }
         }
-        callApiLogService.saveOrUpdate(order.getOrderNumber(), FIND_ORDER_INFO, TopApi.DEAL_SELECT_URL, param, result);
+        callApiLogService.saveOrUpdate(order.getOrderNumber(), FIND_ORDER_INFO, topApiConfiger.dealSelectUrl, param, result);
     }
 
     /**
@@ -495,17 +497,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         String appId = null;
         String openId = null;
         if ("W06".equals(order.getTopPayType())){
-            appId = TopApi.WX_APP_ID;
+            appId = topApiConfiger.wxAppId;
             openId = order.getOpenId();
         }
         verifyOrder(order);
         String orderNumber = order.getOrderNumber();
-        TreeMap<String, String> params = TopApi.generateUnifyParam(orderNumber,new Double(Arith.mul(order.getMoney().doubleValue(),100)).intValue(),
+        TreeMap<String, String> params = topApiConfiger.generateUnifyParam(orderNumber,new Double(Arith.mul(order.getMoney().doubleValue(),100)).intValue(),
                 null, null,
                 null,null,openId,order.getTopPayType(),null,appId,
                 null,null,null,null);
-        String unify = TopApi.generateParam(params);
-        String result = HttpUtils.sendGet(TopApi.UNIFY_URL, unify,null);
+        String unify = topApiConfiger.generateParam(params);
+        String result = HttpUtils.sendGet(topApiConfiger.unifyUrl, unify,null);
         JSONObject obj= JSON.parseObject(result);
         String payInfo;
         if ("0000".equals(obj.get("status"))){
@@ -514,7 +516,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
             throw new CustomException(obj.get("errorMessage").toString());
         }
         //记录调用日志
-        callApiLogService.saveOrUpdate(orderNumber,SCAN_PAY,TopApi.SCAN_TO_PAY_URL,JSONObject.toJSONString(params),null);
+        callApiLogService.saveOrUpdate(orderNumber,SCAN_PAY, topApiConfiger.scanPayUrl,JSONObject.toJSONString(params),null);
         return payInfo;
     }
 
@@ -634,7 +636,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
      * @param order
      */
     public void verifyOrder(Order order){
-        String orderNumber = TopApi.getOrderNumber();
+        String orderNumber = TopApiConfiger.getOrderNumber();
         order.setOrderNumber(orderNumber);
         Assert.check(null != order.getPayType(),"请选择支付方式");
         Assert.check(null != order.getMoney() && order.getMoney().compareTo(BigDecimal.ZERO)  != 0,"请输入订单金额");

+ 10 - 1
src/main/resources/application-dev.properties

@@ -105,4 +105,13 @@ spring.rabbitmq.username=admin
 spring.rabbitmq.password=admin
 # 开启confirms回调 P -> Exchange
 spring.rabbitmq.publisher-confirm-type=correlated
-
+# 通云支付配置
+toppay.version:v1.0
+toppay.merchantNo:121050000127
+toppay.secret:MTEODEKT
+toppay.wxAppId:wx40274c2aaec24330
+toppay.wxAppSecret:4b0c04f796a8bed2c2435cc68362b22b
+toppay.notifyUrl:https://wx.ewoogi.com/dxapi/top/notify
+toppay.scanPayUrl:https://wx.ewoogi.com/dxapi/top/notify
+toppay.dealSelectUrl:https://wx.ewoogi.com/dxapi/top/notify
+toppay.unifyUrl:https://wx.ewoogi.com/dxapi/top/notify

+ 12 - 0
src/main/resources/application-test.properties

@@ -98,3 +98,15 @@ spring.rabbitmq.port=5672
 spring.rabbitmq.username=admin
 spring.rabbitmq.password=123456
 spring.rabbitmq.publisher-confirm-type=correlated
+
+# 通云支付配置
+toppay.version:v1.0
+toppay.merchantNo:121050000127
+toppay.secret:MTEODEKT
+toppay.wxAppId:wx40274c2aaec24330
+toppay.wxAppSecret:4b0c04f796a8bed2c2435cc68362b22b
+toppay.notifyUrl:https://wx.ewoogi.com/dxapi/top/notify
+toppay.scanPayUrl:https://wx.ewoogi.com/dxapi/top/notify
+toppay.dealSelectUrl:https://wx.ewoogi.com/dxapi/top/notify
+toppay.unifyUrl:https://wx.ewoogi.com/dxapi/top/notify
+