wks hace 2 años
padre
commit
a6025242e1

+ 16 - 13
src/main/java/com/ydtech/modules/admin/components/UnionPayRequestApiComponent.java

@@ -62,11 +62,12 @@ public class UnionPayRequestApiComponent {
 
     /**
      * 运营商二要素验证接口
+     *
      * @param request
      */
     public UnionPayResponse twoFactorVerifyRequest(UnionPayRequest request) {
         String url = unionPayApiConfigurationProperties.getTwoFactorVerifyUrl();
-        JSONObject params=new JSONObject();
+        JSONObject params = new JSONObject();
         if (StringUtils.isBlank(request.getPhoneNo())) {
             throw new InvalidParameterException("手机号不允许为空!");
         }
@@ -181,25 +182,25 @@ public class UnionPayRequestApiComponent {
             httpHeaders.set("Accept", "application/json");
             httpHeaders.set("Authorization", getAccessToken());
             // 请求
-            LOGGER.error("银联接口url:"+url);
-            LOGGER.error("银联接口请求报文:"+params);
-            LOGGER.error("银联接口加密请求报文:"+data);
+            LOGGER.error("银联接口url:" + url);
+            LOGGER.error("银联接口请求报文:" + params);
+            LOGGER.error("银联接口加密请求报文:" + data);
             HttpEntity<String> httpEntity = new HttpEntity<>(data.toString(), httpHeaders);
             ResponseEntity<String> response = restTemplate.postForEntity(url, httpEntity, String.class);
             JSONObject resp = JSONObject.parseObject(response.getBody());
-            LOGGER.error("银联接口响应报文:"+resp);
+            LOGGER.error("银联接口响应报文:" + resp);
             if ("20000000".equals(resp.getString("errCode"))) {
                 String privateKey = unionPayApiConfigurationProperties.getPrivateKey();
                 String respData = SM2.sm2Decrypt(resp.getString("data"),
                         privateKey);
-                LOGGER.error("银联接口解密响应报文:"+respData);
+                LOGGER.error("银联接口解密响应报文:" + respData);
                 return JSONObject.parseObject(respData, UnionPayResponse.class);
             } else {
-                LOGGER.error("银联信息验证异常[" + resp.getString("errCode") + ":" +
+                throw new SystemException("银联信息验证异常[" + resp.getString("errCode") + ":" +
                         resp.getString("errInfo") + "]");
-                throw new SystemException(resp.getString("errInfo"));
             }
-
+        } catch (SystemException e) {
+            throw new SystemException(e.getMessage());
         } catch (Exception e) {
             LOGGER.error("银联接口调用异常", e);
             throw new RuntimeException("银联接口调用异常:", e);
@@ -277,18 +278,18 @@ public class UnionPayRequestApiComponent {
             httpHeaders.set("Content-Type", "application/json;charset=UTF-8");
             httpHeaders.set("Accept", "application/json");
             // 请求
-            LOGGER.error("银联获取token-url:"+accessTokenUrl);
-            LOGGER.error("银联获取token-入参:"+params);
+            LOGGER.error("银联获取token-url:" + accessTokenUrl);
+            LOGGER.error("银联获取token-入参:" + params);
             HttpEntity<JSONObject> httpEntity = new HttpEntity<>(params, httpHeaders);
             ResponseEntity<String> response = restTemplate.postForEntity(accessTokenUrl, httpEntity, String.class);
             JSONObject resp = JSONObject.parseObject(response.getBody());
-            LOGGER.error("银联获取token-返参:"+resp);
+            LOGGER.error("银联获取token-返参:" + resp);
             if ("0000".equals(resp.getString("errCode"))) {
                 String token = resp.getString("accessToken");
                 int expiresIn = resp.getIntValue("expiresIn"); //失效时间
                 Map<String, String> map = new HashMap<>();
                 String tokenValue = "OPEN-ACCESS-TOKEN AccessToken=" + token + ", AppId=" + appId;
-                map.put(UNION_PAY_ACCESS_TOKEN_KEY, tokenValue );
+                map.put(UNION_PAY_ACCESS_TOKEN_KEY, tokenValue);
                 redisTemplate.opsForHash().putAll(UNION_PAY_MAP, map);
                 redisTemplate.expire(UNION_PAY_MAP, expiresIn - 30, TimeUnit.SECONDS);
                 return tokenValue;
@@ -297,6 +298,8 @@ public class UnionPayRequestApiComponent {
                         resp.getString("errInfo") + "]");
             }
 
+        } catch (SystemException e) {
+            throw new SystemException(e.getMessage());
         } catch (Exception e) {
             LOGGER.error("获取银联Token异常", e);
             throw new SystemException("获取银联Token异常,请重试!");