java110 лет назад: 3
Родитель
Сommit
5fe83c8e85

+ 14 - 0
service-acct/pom-boot.xml

@@ -30,6 +30,20 @@
       <artifactId>alipay-sdk-java</artifactId>
     </dependency>
 
+    <!-- 浦发银行专用 -->
+    <!--    <dependency>-->
+    <!--      <groupId>cn.hutool</groupId>-->
+    <!--      <artifactId>hutool-all</artifactId>-->
+    <!--      <version>5.6.5</version>-->
+    <!--    </dependency>-->
+
+
+    <!--    <dependency>-->
+    <!--      <groupId>org.bouncycastle</groupId>-->
+    <!--      <artifactId>bcprov-jdk15to18</artifactId>-->
+    <!--      <version>1.68</version>-->
+    <!--    </dependency>-->
+
   </dependencies>
 
 </project>

+ 14 - 0
service-acct/pom-cloud.xml

@@ -55,6 +55,20 @@
       <!--<version>2.0.0.5</version>-->
     <!--</dependency>-->
 
+    <!-- 浦发银行专用 -->
+<!--    <dependency>-->
+<!--      <groupId>cn.hutool</groupId>-->
+<!--      <artifactId>hutool-all</artifactId>-->
+<!--      <version>5.6.5</version>-->
+<!--    </dependency>-->
+
+
+<!--    <dependency>-->
+<!--      <groupId>org.bouncycastle</groupId>-->
+<!--      <artifactId>bcprov-jdk15to18</artifactId>-->
+<!--      <version>1.68</version>-->
+<!--    </dependency>-->
+
   </dependencies>
 
 

+ 14 - 0
service-acct/pom.xml

@@ -50,6 +50,20 @@
 <!--      <version>2.0.0.5</version>-->
 <!--    </dependency>-->
 
+    <!-- 浦发银行专用 -->
+        <dependency>
+          <groupId>cn.hutool</groupId>
+          <artifactId>hutool-all</artifactId>
+          <version>5.6.5</version>
+        </dependency>
+
+
+        <dependency>
+          <groupId>org.bouncycastle</groupId>
+          <artifactId>bcprov-jdk15to18</artifactId>
+          <version>1.68</version>
+        </dependency>
+
   </dependencies>
   <build>
     <finalName>service-acct</finalName>

+ 65 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/RSAUtil.java

@@ -0,0 +1,65 @@
+package com.java110.acct.payment.adapt.spdb;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.asymmetric.KeyType;
+import cn.hutool.crypto.asymmetric.RSA;
+import cn.hutool.crypto.asymmetric.Sign;
+import cn.hutool.crypto.asymmetric.SignAlgorithm;
+
+import java.nio.charset.StandardCharsets;
+import java.security.KeyPair;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 回调接口RSA私钥解密、验签工具
+ *
+ * @author z
+ **/
+public class RSAUtil {
+
+    private RSAUtil() {
+        throw new IllegalStateException("Utility class");
+    }
+
+    /**
+     * RSA钥对生成
+     *
+     * @return privateKey私钥 publicKey公钥
+     */
+    public static Map<String, String> generateKey() {
+        KeyPair pair = SecureUtil.generateKeyPair("RSA");
+        String privateKey = Base64.encode(pair.getPrivate().getEncoded());
+        String publicKey = Base64.encode(pair.getPublic().getEncoded());
+        Map<String, String> result = new HashMap<>(1);
+        result.put("privateKey", privateKey);
+        result.put("publicKey", publicKey);
+        return result;
+    }
+
+    /**
+     * 验证签名
+     *
+     * @param decryptBody   报文明文
+     * @param spdbSign      浦发签名,一般放在请求头的"SPDB_PUBLIC_KEY"字段中
+     * @param spdbPublicKey 浦发公钥
+     * @return 是否验签通过
+     */
+    public static boolean verifySign(String decryptBody, String spdbSign, String spdbPublicKey) {
+        Sign sign = SecureUtil.sign(SignAlgorithm.SHA1withRSA, null, spdbPublicKey);
+        return sign.verify(decryptBody.getBytes(StandardCharsets.UTF_8), Base64.decode(spdbSign));
+    }
+
+    /**
+     * 使用合作方私钥解密报文体
+     *
+     * @param encryptBody 报文密文
+     * @return 解密后的明文
+     */
+    public static String decryptStr(String encryptBody, String myPrivateKey) {
+        RSA rsa = new RSA(myPrivateKey, null);
+        return rsa.decryptStr(encryptBody, KeyType.PrivateKey);
+    }
+
+}

+ 42 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SM2Util.java

@@ -0,0 +1,42 @@
+package com.java110.acct.payment.adapt.spdb;
+
+import cn.hutool.core.util.HexUtil;
+import cn.hutool.crypto.BCUtil;
+import cn.hutool.crypto.SmUtil;
+import cn.hutool.crypto.asymmetric.SM2;
+import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * SM2密钥对生成工具
+ *
+ * @author z
+ **/
+public class SM2Util {
+
+    private SM2Util() {
+        throw new IllegalStateException("Utility class");
+    }
+
+    /**
+     * 私钥长度
+     */
+    private static final int KEY_PRIVATE_LENGTH = 66;
+
+    public static Map<String, String> generateKey() {
+        SM2 sm2 = SmUtil.sm2();
+        byte[] privateKey = BCUtil.encodeECPrivateKey(sm2.getPrivateKey());
+        byte[] publicKey = ((BCECPublicKey) sm2.getPublicKey()).getQ().getEncoded(false);
+        String privateKeyStr = HexUtil.encodeHexStr(privateKey);
+        if (privateKeyStr.length() == KEY_PRIVATE_LENGTH) {
+            Map<String, String> result = new HashMap<>(1);
+            result.put("privateKey", privateKeyStr);
+            result.put("publicKey", HexUtil.encodeHexStr(publicKey));
+            return result;
+        } else {
+            return generateKey();
+        }
+    }
+}

+ 306 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SPDBApiClient.java

@@ -0,0 +1,306 @@
+package com.java110.acct.payment.adapt.spdb;
+
+import cn.hutool.core.net.url.UrlBuilder;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.ContentType;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpStatus;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.http.body.MultipartBody;
+import cn.hutool.json.JSONUtil;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * API调用实现
+ *
+ * @author z
+ */
+public class SPDBApiClient {
+
+    private final SPDBSecurity spdbSecurity;
+
+    /**
+     * HTTP请求超时时间5分钟,可自行调整
+     */
+    private static final Integer HTTP_TIMEOUT = 5 * 60 * 1000;
+
+    private static final String ERROR_HTTP_UNAUTHORIZED = "请检查接口是否订阅并审批通过,沙盒环境审批通过后需等2小时数据同步";
+    private static final String ERROR_HTTP_BAD_METHOD = "HTTP请求方式有误,请参考API文档请求方式,通常有POST和GET两种";
+    private static final String ERROR_SIGN = "响应头签名为空或响应验签未通过,请检浦发SM2公钥参数";
+
+    private static final String HEAD_SPDB_CLIENT_ID = "X-SPDB-Client-ID";
+    private static final String HEAD_SPDB_SM = "X-SPDB-SM";
+    private static final String HEAD_SPDB_ENCRYPTION = "X-SPDB-Encryption";
+    private static final String HEAD_SPDB_SIGNATURE = "X-SPDB-SIGNATURE";
+    private static final String HEAD_SPDB_LABEL = "X-SPDB-LABEL";
+    private static final String HEAD_SPDB_META_DATA = "X-SPDB-MetaData";
+    private static final String HEAD_SPDB_CONTENT_TYPE = "Content-Type";
+    private static final String HEAD_SPDB_TRUE = "true";
+    private static final String HEAD_SPDB_CONTENT_TYPE_STR = "application/json;charset=utf-8";
+
+    public SPDBApiClient(SPDBSecurity spdbSecurity) {
+        this.spdbSecurity = spdbSecurity;
+    }
+
+    /**
+     * 全报文加密接入方式,POST请求
+     *
+     * @param url     请求地址
+     * @param reqBody 请求明文
+     * @return 响应报文
+     * @throws Exception 异常
+     */
+    public SPDBApiResponse post(String url, String reqBody) throws Exception {
+        HttpRequest httpRequest = HttpUtil.createPost(url);
+        String body = spdbSecurity.encrypt(reqBody);
+        httpRequest.body(body);
+        buildReqHeader(httpRequest, reqBody, null, true);
+        return req(httpRequest, true, true);
+    }
+
+    /**
+     * 普通验签接入方式,POST请求
+     *
+     * @param url              请求地址
+     * @param reqBody          请求明文
+     * @param isVerifyRespSign 是否验证响应签名
+     * @return 响应报文
+     * @throws Exception 异常
+     */
+    public SPDBApiResponse postWithNoEncrypt(String url, String reqBody, boolean isVerifyRespSign) throws Exception {
+        HttpRequest httpRequest = HttpUtil.createPost(url);
+        httpRequest.body(reqBody);
+        buildReqHeader(httpRequest, reqBody, null, false);
+        return req(httpRequest, false, isVerifyRespSign);
+    }
+
+    /**
+     * 普通验签接入方式,POST请求,可添加额外请求头
+     *
+     * @param url              请求地址
+     * @param reqBody          请求明文
+     * @param isVerifyRespSign 是否验证响应签名
+     * @param headers          额外的请求头
+     * @return 响应报文
+     * @throws Exception 异常
+     */
+    public SPDBApiResponse postWithNoEncrypt(String url, String reqBody, boolean isVerifyRespSign, Map<String, String> headers) throws Exception {
+        HttpRequest httpRequest = HttpUtil.createPost(url);
+        httpRequest.body(reqBody);
+        buildReqHeader(httpRequest, reqBody, headers, false);
+        return req(httpRequest, false, isVerifyRespSign);
+    }
+
+    /**
+     * 图文信息上传
+     *
+     * @param url         请求地址
+     * @param formDataMap 请求表单
+     * @param headersMap  请求头
+     * @return 响应报文
+     * @throws Exception 异常
+     */
+    public String postWithFile(String url, Map<String, Object> formDataMap, Map<String, String> headersMap) throws Exception {
+        HttpRequest httpRequest = HttpUtil.createPost(url);
+        httpRequest.form(formDataMap);
+
+        // 组装请求头
+        httpRequest.addHeaders(headersMap);
+        httpRequest.header(HEAD_SPDB_CLIENT_ID, spdbSecurity.getClientId());
+        httpRequest.header(HEAD_SPDB_SM, HEAD_SPDB_TRUE);
+        httpRequest.header(HEAD_SPDB_CONTENT_TYPE, ContentType.MULTIPART.getValue());
+
+        // 生成签名
+        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+            Map<String, Object> formMap = httpRequest.form();
+            MultipartBody.create(formMap, Charset.forName(StandardCharsets.UTF_8.name())).write(outputStream);
+            byte[] formByte = outputStream.toByteArray();
+            httpRequest.header(HEAD_SPDB_SIGNATURE, spdbSecurity.signNormalWithByte(formByte));
+        }
+
+        HttpResponse httpResponse = httpRequest.execute();
+        int httpStatus = httpResponse.getStatus();
+        if (httpStatus == HttpStatus.HTTP_OK) {
+            return httpResponse.body();
+        } else {
+            throw new SPDBApiException(httpStatus, httpResponse.body());
+        }
+
+    }
+
+    /**
+     * 全报文加密接入方式,GET请求
+     *
+     * @param url     请求地址
+     * @param reqBody 请求体
+     * @return 响应体
+     * @throws Exception 异常
+     */
+    public SPDBApiResponse get(String url, String reqBody) throws Exception {
+        url += "?encryptBody=" + spdbSecurity.encrypt(reqBody);
+        HttpRequest httpRequest = HttpUtil.createGet(url);
+        httpRequest.setUrl(UrlBuilder.ofHttpWithoutEncode(url));
+        buildReqHeader(httpRequest, reqBody, null, true);
+        return req(httpRequest, true, true);
+    }
+
+    /**
+     * 普通验签接入方式,GET请求
+     *
+     * @param url              请求地址
+     * @param param            GET请求的URL参数,例:a=1&b=2&c=3
+     * @param isVerifyRespSign 是否验证响应签名
+     * @return 响应体
+     * @throws Exception 异常
+     */
+    public SPDBApiResponse getWithNoEncrypt(String url, String param, boolean isVerifyRespSign) throws Exception {
+        url += "?" + param;
+        HttpRequest httpRequest = HttpUtil.createGet(url);
+        httpRequest.setUrl(UrlBuilder.ofHttpWithoutEncode(url));
+        buildReqHeader(httpRequest, param, null, false);
+        return req(httpRequest, false, isVerifyRespSign);
+    }
+
+    /**
+     * 普通验签接入方式,GET请求
+     *
+     * @param url     请求地址
+     * @param param   GET请求的URL参数,例:a=1&b=2&c=3
+     * @param headers 自定义请求头
+     * @return 响应体
+     * @throws Exception 异常
+     */
+    public SPDBApiResponse getWithNoEncrypt(String url, String param, boolean isVerifyRespSign, Map<String, String> headers) throws Exception {
+        url += "?" + param;
+        HttpRequest httpRequest = HttpUtil.createGet(url);
+        httpRequest.setUrl(UrlBuilder.ofHttpWithoutEncode(url));
+        buildReqHeader(httpRequest, param, headers, false);
+        return req(httpRequest, false, isVerifyRespSign);
+    }
+
+    /**
+     * 【公共文件下载】接口专用
+     *
+     * @param url   请求地址
+     * @param param GET请求的URL参数,例:fileId=0d01160ae808b0b0bb4f2ada958b96c9182ec52e
+     * @param label 场景编号,例:0001
+     * @return 响应文件流
+     * @throws Exception 异常
+     */
+    public InputStream downloadFile(String url, String param, String label) throws Exception {
+        url += "?" + param;
+        HttpRequest httpRequest = HttpUtil.createGet(url);
+        httpRequest.setUrl(UrlBuilder.ofHttpWithoutEncode(url));
+        Map<String, String> headersMap = new HashMap<>(1);
+        headersMap.put(HEAD_SPDB_LABEL, label);
+        buildReqHeader(httpRequest, param, headersMap, false);
+        HttpResponse httpResponse = httpRequest.execute();
+        int httpStatus = httpResponse.getStatus();
+        if (httpStatus == HttpStatus.HTTP_OK) {
+            return httpResponse.bodyStream();
+        } else {
+            throw new SPDBApiException(httpStatus, httpResponse.body());
+        }
+    }
+
+    /**
+     * 【公共文件上传】接口专用
+     *
+     * @param url      请求地址
+     * @param spdbFile 请求体
+     * @return 响应文件流
+     * @throws Exception 异常
+     */
+    public String uploadFile(String url, SPDBFile spdbFile, String label) throws Exception {
+        File file = spdbFile.getFile();
+        if (file == null || !file.isFile()) {
+            throw new FileNotFoundException("文件不存在,请在SPDBFile变量初始化文件参数");
+        }
+        spdbFile.build();
+
+        HttpRequest httpRequest = HttpUtil.createPost(url);
+        httpRequest.form("s3File", file);
+
+        String metaData = JSONUtil.toJsonStr(spdbFile);
+
+        httpRequest.header(HEAD_SPDB_CLIENT_ID, spdbSecurity.getClientId());
+        httpRequest.header(HEAD_SPDB_SM, HEAD_SPDB_TRUE);
+        httpRequest.header(HEAD_SPDB_LABEL, label);
+
+        httpRequest.header(HEAD_SPDB_SIGNATURE, spdbSecurity.signNormal(metaData));
+        httpRequest.header(HEAD_SPDB_META_DATA, metaData);
+
+        HttpResponse httpResponse = httpRequest.execute();
+        int httpStatus = httpResponse.getStatus();
+        String resBody = httpResponse.body();
+        if (httpStatus == HttpStatus.HTTP_OK) {
+            return resBody;
+        } else {
+            throw new SPDBApiException(httpStatus, resBody);
+        }
+    }
+
+    /**
+     * 构建请求头
+     *
+     * @param httpRequest 请求
+     * @param data        报文明文
+     * @param encrypt     是否全报文加密方式接入
+     */
+    private void buildReqHeader(HttpRequest httpRequest, String data, Map<String, String> headers, boolean encrypt) throws Exception {
+        httpRequest.addHeaders(headers);
+        httpRequest.header(HEAD_SPDB_CONTENT_TYPE, HEAD_SPDB_CONTENT_TYPE_STR);
+        httpRequest.header(HEAD_SPDB_CLIENT_ID, spdbSecurity.getClientId());
+        httpRequest.header(HEAD_SPDB_SM, HEAD_SPDB_TRUE);
+
+        if (encrypt) {
+            httpRequest.header(HEAD_SPDB_ENCRYPTION, HEAD_SPDB_TRUE);
+            httpRequest.header(HEAD_SPDB_SIGNATURE, spdbSecurity.sign(data));
+        } else {
+            httpRequest.header(HEAD_SPDB_SIGNATURE, spdbSecurity.signNormal(data));
+        }
+
+    }
+
+    /**
+     * http请求
+     *
+     * @param httpRequest      请求
+     * @param isEncrypt        是否为全文加密请求
+     * @param isVerifyRespSign 是否验证响应签名
+     * @return 响应体
+     * @throws Exception 异常
+     */
+    private SPDBApiResponse req(HttpRequest httpRequest, boolean isEncrypt, boolean isVerifyRespSign) throws SPDBApiException {
+        httpRequest.timeout(HTTP_TIMEOUT);
+        HttpResponse httpResponse = httpRequest.execute();
+        int httpStatus = httpResponse.getStatus();
+        String httpResBody = httpResponse.body();
+        if (httpStatus == HttpStatus.HTTP_OK) {
+            String resBody = isEncrypt ? spdbSecurity.decrypt(httpResBody) : httpResBody;
+            if (isVerifyRespSign) {
+                String spdbSign = httpResponse.header(HEAD_SPDB_SIGNATURE);
+                if (StrUtil.isBlank(spdbSign) || !spdbSecurity.verifySign(resBody, spdbSign)) {
+                    throw new SPDBApiException(ERROR_SIGN, httpStatus, "报文:" + resBody + "\n签名:" + spdbSign);
+                }
+            }
+
+            return new SPDBApiResponse(resBody, httpResBody, httpStatus, httpResponse.headers());
+        } else if (httpStatus == HttpStatus.HTTP_UNAUTHORIZED) {
+            throw new SPDBApiException(ERROR_HTTP_UNAUTHORIZED, httpStatus, null);
+        } else if (httpStatus == HttpStatus.HTTP_BAD_METHOD) {
+            throw new SPDBApiException(ERROR_HTTP_BAD_METHOD, httpStatus, httpResBody);
+        } else {
+            throw new SPDBApiException(httpStatus, httpResBody);
+        }
+    }
+}

+ 15 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SPDBApiException.java

@@ -0,0 +1,15 @@
+package com.java110.acct.payment.adapt.spdb;
+
+/**
+ * @author z
+ **/
+public class SPDBApiException extends Exception {
+
+    public SPDBApiException(int httpStatus, String httpBody) {
+        super(String.format("浦发银行API调用失败%n请根据响应报文至API官网排查错误原因:https://open.spdb.com.cn/develop/#/document/2/15%nHTTP状态码:%d%n报文:%s", httpStatus, httpBody));
+    }
+
+    public SPDBApiException(String errMsg, int httpStatus, String httpBody) {
+        super(String.format("浦发银行API调用失败%n%s%nHTTP状态码:%d%n报文:%s", errMsg, httpStatus, httpBody));
+    }
+}

+ 92 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SPDBApiResponse.java

@@ -0,0 +1,92 @@
+package com.java110.acct.payment.adapt.spdb;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * API调用响应对象
+ *
+ * @author z
+ */
+public class SPDBApiResponse {
+    /**
+     * HTTP响应体,解密后的
+     */
+    private String resBody;
+
+    /**
+     * HTTP响应体,非解密后的原报文体
+     */
+    private String resOriBody;
+
+    /**
+     * HTTP响应状态码;200、401、500等
+     */
+    private Integer httpStatus;
+
+    /**
+     * HTTP响应头
+     */
+    private Map<String, List<String>> resHeaders;
+
+    public SPDBApiResponse(String resBody, String resOriBody, Integer httpStatus, Map<String, List<String>> resHeaders) {
+        this.resBody = resBody;
+        this.resOriBody = resOriBody;
+        this.httpStatus = httpStatus;
+        this.resHeaders = resHeaders;
+    }
+
+    public String getResBody() {
+        return resBody;
+    }
+
+    public void setResBody(String resBody) {
+        this.resBody = resBody;
+    }
+
+    public String getResOriBody() {
+        return resOriBody;
+    }
+
+    public void setResOriBody(String resOriBody) {
+        this.resOriBody = resOriBody;
+    }
+
+    public Integer getHttpStatus() {
+        return httpStatus;
+    }
+
+    public void setHttpStatus(Integer httpStatus) {
+        this.httpStatus = httpStatus;
+    }
+
+    public Map<String, List<String>> getResHeaders() {
+        return resHeaders;
+    }
+
+    public void setResHeaders(Map<String, List<String>> resHeaders) {
+        this.resHeaders = resHeaders;
+    }
+
+    @Override
+    public String toString() {
+        return "SPDBApiResponse{" +
+                "resBody='" + resBody + '\'' +
+                ", resOriBody='" + resOriBody + '\'' +
+                ", httpStatus=" + httpStatus +
+                ", resHeaders=" + headersToString() +
+                '}';
+    }
+
+    public String headersToString() {
+        if (resHeaders != null && !resHeaders.isEmpty()) {
+            StringBuilder stringBuilder = new StringBuilder();
+            stringBuilder.append("{");
+            resHeaders.forEach((key, value) -> stringBuilder.append(key).append("=").append(String.join(",", value)).append(";"));
+            stringBuilder.append("}");
+            return stringBuilder.toString();
+        } else {
+            return "";
+        }
+    }
+}

+ 58 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SPDBApp.java

@@ -0,0 +1,58 @@
+package com.java110.acct.payment.adapt.spdb;
+
+/**
+ * API平台APP参数维护,若您有多个,可在此添加,通过new SPDBSecurity(SPDBApp spdbApp)初始化
+ * 仅测试环境推荐此方式,生产环境相关参数建议存放数据库做成可配置项
+ *
+ * @author z
+ */
+public enum SPDBApp {
+    /**
+     * APP参数列表
+     */
+    TEST("b*******-****-****-****-***********3",
+            "N**************************************************************0",
+            "1**************************************************************s", "1********************************************************************************************************************************4"),
+
+    ;
+
+    /**
+     * API平台APP的唯一标识
+     */
+    private final String clientId;
+    /**
+     * API平台APP的secret
+     */
+    private final String secret;
+    /**
+     * 合作方SM2私钥
+     */
+    private final String sm2PrivateKey;
+    /**
+     * 浦发SM2公钥
+     */
+    private final String spdbSM2PublicKey;
+
+    SPDBApp(String clientId, String secret, String sm2PrivateKey, String spdbSM2PublicKey) {
+        this.clientId = clientId;
+        this.secret = secret;
+        this.sm2PrivateKey = sm2PrivateKey;
+        this.spdbSM2PublicKey = spdbSM2PublicKey;
+    }
+
+    public String getClientId() {
+        return clientId;
+    }
+
+    public String getSecret() {
+        return secret;
+    }
+
+    public String getSm2PrivateKey() {
+        return sm2PrivateKey;
+    }
+
+    public String getSpdbSM2PublicKey() {
+        return spdbSM2PublicKey;
+    }
+}

+ 95 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SPDBFile.java

@@ -0,0 +1,95 @@
+package com.java110.acct.payment.adapt.spdb;
+
+import cn.hutool.crypto.SecureUtil;
+
+import java.io.File;
+
+/**
+ * 【公共文件上传】接口专用
+ *
+ * @author z
+ */
+public class SPDBFile {
+    /**
+     * 文件对象
+     */
+    private File file;
+    /**
+     * 文件名
+     */
+    private String fileName;
+    /**
+     * 文件大小,单位字节
+     */
+    private String fileSize;
+    /**
+     * 文件sha1后的值
+     */
+    private String fileSha1;
+    /**
+     * 文件路径
+     */
+    private String path;
+
+
+    /**
+     * 构建文件参数
+     */
+    public void build() {
+        this.fileName = file.getName();
+        this.fileSize = file.length() + "B";
+        this.fileSha1 = SecureUtil.sha1(file);
+    }
+
+    public SPDBFile(File file) {
+        this.file = file;
+    }
+
+    public SPDBFile(File file, String fileName, String fileSize, String fileSha1, String path) {
+        this.file = file;
+        this.fileName = fileName;
+        this.fileSize = fileSize;
+        this.fileSha1 = fileSha1;
+        this.path = path;
+    }
+
+    public File getFile() {
+        return file;
+    }
+
+    public void setFile(File file) {
+        this.file = file;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public String getFileSize() {
+        return fileSize;
+    }
+
+    public void setFileSize(String fileSize) {
+        this.fileSize = fileSize;
+    }
+
+    public String getFileSha1() {
+        return fileSha1;
+    }
+
+    public void setFileSha1(String fileSha1) {
+        this.fileSha1 = fileSha1;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+}

+ 10 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SPDBNormalException.java

@@ -0,0 +1,10 @@
+package com.java110.acct.payment.adapt.spdb;
+
+/**
+ * @author z
+ **/
+public class SPDBNormalException extends Exception {
+    public SPDBNormalException(String errMsg, Exception e) {
+        super(errMsg, e);
+    }
+}

+ 171 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SPDBSecurity.java

@@ -0,0 +1,171 @@
+package com.java110.acct.payment.adapt.spdb;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.util.CharsetUtil;
+import cn.hutool.core.util.HexUtil;
+import cn.hutool.crypto.ECKeyUtil;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.SmUtil;
+import cn.hutool.crypto.asymmetric.SM2;
+import cn.hutool.crypto.digest.SM3;
+import cn.hutool.crypto.symmetric.SymmetricCrypto;
+
+import java.nio.charset.StandardCharsets;
+
+/**
+ * 加解密及加签验签
+ *
+ * @author z
+ */
+public class SPDBSecurity {
+
+    private static final String ERROR_KEY = "初始化国密类异常,请检查密钥参数";
+    private static final String ERROR_SM2 = "加签异常,请检查SM2私钥";
+    private static final String ERROR_SECRET = "普通验签加签异常,请检查secret参数";
+
+    /**
+     * API平台APP唯一标识
+     */
+    private final String clientId;
+
+    /**
+     * sm4加解密对象
+     */
+    private final SymmetricCrypto sm4;
+    /**
+     * sm2加签对象
+     */
+    private final SM2 signSM2;
+    /**
+     * sm2验签对象
+     */
+    private final SM2 verifySM2;
+
+    /**
+     * 构造方法,初始化
+     *
+     * @param secret           secret
+     * @param sm2PrivateKey    合作方国密私钥
+     * @param spdbSM2PublicKey 浦发国密公钥
+     */
+    public SPDBSecurity(String clientId, String secret, String sm2PrivateKey, String spdbSM2PublicKey) throws SPDBNormalException {
+        try {
+            this.clientId = clientId;
+
+            String sha256Key = SecureUtil.sha256(secret);
+            SM3 sm3 = SmUtil.sm3();
+            String sm3Key = sm3.digestHex(sha256Key);
+            String md5Key = SecureUtil.md5(sm3Key);
+            this.sm4 = SmUtil.sm4(HexUtil.decodeHex(md5Key));
+
+            this.signSM2 = new SM2(sm2PrivateKey, null, null);
+            this.verifySM2 = new SM2(null, ECKeyUtil.toSm2PublicParams(spdbSM2PublicKey));
+        } catch (Exception e) {
+            throw new SPDBNormalException(ERROR_KEY, e);
+        }
+    }
+
+    /**
+     * 构造方法,初始化
+     */
+    public SPDBSecurity(SPDBApp spdbApp) throws SPDBNormalException {
+        try {
+            this.clientId = spdbApp.getClientId();
+
+            String sha256Key = SecureUtil.sha256(spdbApp.getSecret());
+            SM3 sm3 = SmUtil.sm3();
+            String sm3Key = sm3.digestHex(sha256Key);
+            String md5Key = SecureUtil.md5(sm3Key);
+            this.sm4 = SmUtil.sm4(HexUtil.decodeHex(md5Key));
+
+            this.signSM2 = new SM2(spdbApp.getSm2PrivateKey(), null, null);
+            this.verifySM2 = new SM2(null, ECKeyUtil.toSm2PublicParams(spdbApp.getSpdbSM2PublicKey()));
+        } catch (Exception e) {
+            throw new SPDBNormalException(ERROR_KEY, e);
+        }
+    }
+
+
+    /**
+     * 浦发sm4加密
+     *
+     * @param reqBody 请求报文明文
+     * @return 密文
+     */
+    public String encrypt(String reqBody) {
+        return Base64.encode(sm4.encryptHex(reqBody).toLowerCase());
+    }
+
+    /**
+     * 浦发sm4解密
+     *
+     * @param encryptResBody 响应报文密文
+     * @return 明文
+     */
+    public String decrypt(String encryptResBody) {
+        return sm4.decryptStr(Base64.decodeStr(encryptResBody).toLowerCase(), CharsetUtil.CHARSET_UTF_8);
+    }
+
+    /**
+     * 请求加签
+     *
+     * @param reqBody 请求报文明文
+     * @return 加签结果
+     */
+    public String sign(String reqBody) throws SPDBNormalException {
+        try {
+            byte[] sign = signSM2.sign(reqBody.getBytes(StandardCharsets.UTF_8));
+            return Base64.encode(HexUtil.encodeHexStr(sign));
+        } catch (Exception e) {
+            throw new SPDBNormalException(ERROR_SM2, e);
+        }
+    }
+
+    /**
+     * 响应验签
+     *
+     * @param resBody 响应报文明文
+     * @param resSign 响应头浦发签名
+     * @return 是否验签通过
+     */
+    public boolean verifySign(String resBody, String resSign) {
+        byte[] body = Base64.encode(SecureUtil.sha1().digest(resBody)).getBytes(StandardCharsets.UTF_8);
+        byte[] spdbSign = HexUtil.decodeHex(Base64.decodeStr(resSign));
+        return verifySM2.verify(body, spdbSign);
+    }
+
+    /**
+     * 普通验签接入方式加签
+     *
+     * @param reqBody 请求报文明文
+     * @return 加签结果
+     */
+    public String signNormal(String reqBody) throws SPDBNormalException {
+        try {
+            String sha1 = SecureUtil.sha1(reqBody);
+            String dataEncrypt = Base64.encode(HexUtil.decodeHex(sha1));
+            SM3 sm3 = SmUtil.sm3();
+            String sm3Key = sm3.digestHex(dataEncrypt);
+            return Base64.encode(sm4.encryptHex(sm3Key).toUpperCase());
+        } catch (Exception e) {
+            throw new SPDBNormalException(ERROR_SECRET, e);
+        }
+    }
+
+    public String signNormalWithByte(byte[] data) throws SPDBNormalException {
+        try {
+            byte[] sha1 = SecureUtil.sha1().digest(data);
+            String dataEncrypt = Base64.encode(sha1);
+            SM3 sm3 = SmUtil.sm3();
+            String sm3Key = sm3.digestHex(dataEncrypt);
+            return Base64.encode(sm4.encryptHex(sm3Key).toUpperCase());
+        } catch (Exception e) {
+            throw new SPDBNormalException(ERROR_SECRET, e);
+        }
+    }
+
+
+    public String getClientId() {
+        return clientId;
+    }
+}

+ 363 - 0
service-acct/src/main/java/com/java110/acct/payment/adapt/spdb/SpdbPaymentFactoryAdapt.java

@@ -0,0 +1,363 @@
+package com.java110.acct.payment.adapt.spdb;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.payment.IPaymentFactoryAdapt;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.factory.CommunitySettingFactory;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.factory.WechatFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.app.AppDto;
+import com.java110.dto.onlinePay.OnlinePayDto;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.payment.PaymentOrderDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
+import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
+import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
+import com.java110.po.onlinePay.OnlinePayPo;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.cache.UrlCache;
+import com.java110.utils.constant.MappingConstant;
+import com.java110.utils.constant.WechatConstant;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.PayUtil;
+import com.java110.utils.util.StringUtil;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+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;
+
+/**
+ * 浦发银行支付厂家类
+ * <p>
+ * App支付交易接口
+ * <p>
+ * App支付退货
+ * <p>
+ *
+ * 1.0 sql 配置说明:
+ *
+ * INSERT INTO `TT`.`t_dict` ( `status_cd`, `name`, `description`, `create_time`, `table_name`, `table_columns`)
+ * VALUES ( '9070', 'SPDB', 'SPDB', '2022-08-16 15:51:55', 'community_setting_key', 'setting_type');
+ *
+ * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
+ * VALUES ('82', '9070', 'SPDB_CLIENT_ID', 'SPDB_CLIENT_ID', '应用id', '2021-10-10 21:25:46', '0');
+ * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
+ * VALUES ('88', '9070', 'ICBC_DECIVE_INFO', 'SPDB_SECRET', '秘钥', '2021-10-10 21:25:46', '0');
+ * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
+ * VALUES ('83', '9070', 'ICBC_PRIVATE_KEY(私钥)', 'SPDB_PRIVATE_KEY', '值请填写1 私钥 请填写在备注中', '2021-10-10 21:25:46', '0');
+ * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
+ * VALUES ('84', '9070', 'ICBC_PUBLIC_KEY(公钥)', 'SPDB_PUBLIC_KEY', '值请填写1 公钥 请填写在备注中 ', '2021-10-10 21:25:46', '0');
+ * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
+ * VALUES ('85', '9070', 'ICBC_MER_ID', 'SPDB_MRCH_NO', '值请填写商家ID', '2021-10-10 21:25:46', '0');
+ * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
+ * VALUES ('86', '9070', 'ICBC_MER_PRTCL_NO', 'SPDB_TERMINAL_NO', '值请填写终端', '2021-10-10 21:25:46', '0');
+ * // 以下数据先查询是否存在 存在则修改 不存在添加
+ * INSERT INTO `TT`.`c_mapping` (`domain`, `name`, `key`, `value`, `remark`, `create_time`, `status_cd`)
+ *  VALUES ('WECHAT', '被扫支付厂家', 'PAY_QR_ADAPT', 'qrCodeSpdbPaymentAdapt', '', '2023-02-18 18:47:14', '0');
+ *
+ * INSERT INTO `TT`.`c_mapping` (`domain`, `name`, `key`, `value`, `remark`, `create_time`, `status_cd`)
+ *  VALUES ('WECHAT', '线上支付厂家', 'PAYMENT_ADAPT', 'pufaPaymentFactory', '', '2023-02-18 18:47:14', '0');
+ *
+ *  2.0 开发代码
+ *   包含类为:service-acct模块 com.java110.acct.payment.adapt.spdb 下的所有类
+ *  service-acct 模块下 com.java110.acct.smo.impl.QrCodeSpdbPaymentAdapt 类
+ *  3.0 pom 配置
+ *  在 service-acct 下的pom.xml 中加入以下
+ *         <dependency>
+ *           <groupId>cn.hutool</groupId>
+ *           <artifactId>hutool-all</artifactId>
+ *           <version>5.6.5</version>
+ *         </dependency>
+ *
+ *
+ *         <dependency>
+ *           <groupId>org.bouncycastle</groupId>
+ *           <artifactId>bcprov-jdk15to18</artifactId>
+ *           <version>1.68</version>
+ *         </dependency>
+ *  4.0 登录物业系统后在 设置下的系统下的小区配置中配置 相关信息
+ *
+ */
+@Service("pufaPaymentFactory")
+public class SpdbPaymentFactoryAdapt implements IPaymentFactoryAdapt {
+
+    private static final Logger logger = LoggerFactory.getLogger(SpdbPaymentFactoryAdapt.class);
+
+
+    //微信支付
+    public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
+    // 微信服务商支付开关
+    public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
+
+    //开关ON打开
+    public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
+
+    public static final String TRADE_TYPE_NATIVE = "NATIVE";
+    public static final String TRADE_TYPE_JSAPI = "JSAPI";
+    public static final String TRADE_TYPE_APP = "APP";
+
+
+    public static final String wxPayUnifiedOrder = "https://api.spdb.com.cn/spdb/prd/api/acquiring/appPay/initiation";
+
+    @Autowired
+    private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
+
+
+    @Autowired
+    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
+
+
+    @Autowired
+    private IOnlinePayV1InnerServiceSMO onlinePayV1InnerServiceSMOImpl;
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+
+    @Override
+    public Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson, ICmdDataFlowContext context) throws Exception {
+
+        SmallWeChatDto smallWeChatDto = getSmallWechat(reqJson);
+
+
+        String appId = context.getReqHeaders().get("app-id");
+        String userId = context.getReqHeaders().get("user-id");
+        String tradeType = reqJson.getString("tradeType");
+        String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/wechat/992020011134400001";
+
+        String openId = reqJson.getString("openId");
+
+        if (StringUtil.isEmpty(openId)) {
+            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;
+            }
+
+            OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+            ownerAppUserDto.setUserId(userId);
+            ownerAppUserDto.setAppType(appType);
+            List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+
+            if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
+                throw new IllegalArgumentException("未找到开放账号信息");
+            }
+            openId = ownerAppUserDtos.get(0).getOpenId();
+        }
+
+
+        logger.debug("【小程序支付】 统一下单开始, 订单编号=" + paymentOrderDto.getOrderId());
+        SortedMap<String, String> resultMap = new TreeMap<String, String>();
+        //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元
+        double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue(MappingConstant.ENV_DOMAIN, "HC_ENV"), paymentOrderDto.getMoney());
+        //添加或更新支付记录(参数跟进自己业务需求添加)
+
+        JSONObject resMap = null;
+        resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
+                paymentOrderDto.getOrderId(),
+                tradeType,
+                payAmount,
+                openId,
+                smallWeChatDto,
+                notifyUrl
+        );
+
+
+        if ("SUCCESS".equals(resMap.get("return_code")) && "SUCCESS".equals(resMap.get("result_code"))) {
+            if (TRADE_TYPE_JSAPI.equals(tradeType)) {
+
+                resultMap.put("appId", smallWeChatDto.getAppId());
+                resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp());
+                resultMap.put("nonceStr", PayUtil.makeUUID(32));
+                resultMap.put("package", "prepay_id=" + resMap.get("prepay_id"));
+                resultMap.put("signType", "MD5");
+                resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword()));
+            } else if (TRADE_TYPE_APP.equals(tradeType)) {
+                resultMap.put("appId", smallWeChatDto.getAppId());
+                resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp());
+                resultMap.put("nonceStr", PayUtil.makeUUID(32));
+                resultMap.put("partnerid", smallWeChatDto.getMchId());
+                resultMap.put("prepayid", resMap.getString("prepay_id"));
+                //resultMap.put("signType", "MD5");
+                resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword()));
+            } else if (TRADE_TYPE_NATIVE.equals(tradeType)) {
+                resultMap.put("prepayId", resMap.getString("prepay_id"));
+                resultMap.put("codeUrl", resMap.getString("code_url"));
+            }
+            resultMap.put("code", "0");
+            resultMap.put("msg", "下单成功");
+            logger.info("【小程序支付】统一下单成功,返回参数:" + resultMap + "===notifyUrl===" + notifyUrl);
+        } else {
+            resultMap.put("code", resMap.getString("return_code"));
+            resultMap.put("msg", resMap.getString("return_msg"));
+            logger.info("【小程序支付】统一下单失败,失败原因:" + resMap.get("return_msg") + "===code===" + resMap.get("return_code") + "===notifyUrl===" + notifyUrl);
+        }
+        return resultMap;
+    }
+
+
+    /**
+     * {
+     * "cmdtyCd": "",
+     * "terminalNo": "98009459",
+     * "subMechNoAcctID": "wx13de10893e064009",
+     * "channelNo": "00",
+     * "spdbMrchNo": "310999880620003",
+     * "cmdtyDtl": "[993137072803]自助生活缴费",
+     * "terminaIP": "223.104.247.218",
+     * "frmrMrchOrdrNo": "20113017050000041231",
+     * "cmdtyDsc": "[993137072803]自助生活缴费",
+     * "tranType": "OA",
+     * "tranAmt": 0.01,
+     * "mrchlInfmAdr": "http://paycenter-channel.hw-qa.eslink.net.cn/eslink/pay/spdb/callback",
+     * "usrChildFlg": "oaX8s04YCscDovz8Re-c7GxyWZWY"
+     * }
+     *
+     * @param feeName
+     * @param orderNum
+     * @param tradeType
+     * @param payAmount
+     * @param openid
+     * @param smallWeChatDto
+     * @param notifyUrl
+     * @return
+     * @throws Exception
+     */
+    private JSONObject java110UnifieldOrder(String feeName, String orderNum,
+                                            String tradeType, double payAmount, String openid,
+                                            SmallWeChatDto smallWeChatDto, String notifyUrl) throws Exception {
+
+        String clientId = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "SPDB_CLIENT_ID");
+        String secret = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "SPDB_SECRET");
+        String privateKey = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "SPDB_PRIVATE_KEY");
+        String apiPublicKey = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "SPDB_PUBLIC_KEY");
+        String terminalNo = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "SPDB_TERMINAL_NO");
+        String spdbMrchNo = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "SPDB_MRCH_NO");
+
+        SPDBSecurity spdbSecurity = new SPDBSecurity(clientId, secret, privateKey, apiPublicKey);
+        SPDBApiClient spdbApiClient = new SPDBApiClient(spdbSecurity);
+
+        if (feeName.length() > 127) {
+            feeName = feeName.substring(0, 126);
+        }
+
+        JSONObject paramIn = new JSONObject();
+        paramIn.put("terminalNo", terminalNo);
+        paramIn.put("subMechNoAcctID", smallWeChatDto.getAppId());
+        paramIn.put("channelNo", "00");
+        paramIn.put("spdbMrchNo", spdbMrchNo);
+        paramIn.put("cmdtyDtl", "[" + spdbMrchNo + "]" + feeName);
+        paramIn.put("terminaIP", PayUtil.getLocalIp());
+        paramIn.put("frmrMrchOrdrNo", orderNum);
+        paramIn.put("cmdtyDsc", "[" + spdbMrchNo + "]" + feeName);
+        if (TRADE_TYPE_JSAPI.equals(tradeType)) {
+            paramIn.put("tranType", "OA");
+        } else if (TRADE_TYPE_APP.equals(tradeType)) {
+            paramIn.put("tranType", "OM");
+        } else {
+            throw new IllegalArgumentException("不支持的支付类型");
+        }
+        paramIn.put("tranAmt", payAmount);
+        paramIn.put("mrchlInfmAdr", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
+        paramIn.put("usrChildFlg", openid);
+
+
+        SPDBApiResponse response = spdbApiClient.post(wxPayUnifiedOrder, paramIn.toJSONString());
+
+        if (response.getHttpStatus() != 0000) {
+            throw new IllegalArgumentException(response.getResBody());
+        }
+
+        JSONObject paramOut = JSONObject.parseObject(response.getResBody());
+
+        if (!"0000".equals(paramOut.getString("statusCode"))) {
+            throw new IllegalArgumentException(paramOut.getString("statusMsg"));
+        }
+
+
+        logger.debug("统一下单返回" + response.getResBody());
+//请求微信后台,获取预支付ID
+
+        doSaveOnlinePay(smallWeChatDto, openid, orderNum, feeName, payAmount, OnlinePayDto.STATE_WAIT, "待支付");
+        return JSONObject.parseObject(paramOut.getString("sgnData")); //signature
+    }
+
+
+    @Override
+    public PaymentOrderDto java110NotifyPayment(String param) {
+        PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
+        JSONObject json = JSONObject.parseObject(param);
+
+
+        //更新数据
+        paymentOrderDto.setOrderId(json.getString("MrchOrdrNo3"));
+        paymentOrderDto.setTransactionId(json.getString("ThdPtySeq"));
+
+        JSONObject paramOut = new JSONObject();
+        paramOut.put("AcceptFlag", "0");
+
+        paymentOrderDto.setResponseEntity(new ResponseEntity<String>(paramOut.toJSONString(), HttpStatus.OK));
+        doUpdateOnlinePay(json.getString("MrchOrdrNo3"), OnlinePayDto.STATE_COMPILE, "支付成功");
+        return paymentOrderDto;
+    }
+
+
+    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 = new SmallWeChatDto();
+            smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
+            smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
+            smallWeChatDto.setMchId(MappingCache.getValue(MappingConstant.WECHAT_STORE_DOMAIN, "mchId"));
+            smallWeChatDto.setPayPassword(MappingCache.getValue(MappingConstant.WECHAT_STORE_DOMAIN, "key"));
+            return smallWeChatDto;
+        }
+
+        return BeanConvertUtil.covertBean(smallWeChatDtos.get(0), SmallWeChatDto.class);
+    }
+
+
+    private void doUpdateOnlinePay(String orderId, String state, String message) {
+        OnlinePayPo onlinePayPo = new OnlinePayPo();
+        onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
+        onlinePayPo.setOrderId(orderId);
+        onlinePayPo.setState(state);
+        onlinePayV1InnerServiceSMOImpl.updateOnlinePay(onlinePayPo);
+    }
+
+    private void doSaveOnlinePay(SmallWeChatDto smallWeChatDto, String openId, String orderId, String feeName, double money, String state, String message) {
+        OnlinePayPo onlinePayPo = new OnlinePayPo();
+        onlinePayPo.setAppId(smallWeChatDto.getAppId());
+        onlinePayPo.setMchId(smallWeChatDto.getMchId());
+        onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
+        onlinePayPo.setOpenId(openId);
+        onlinePayPo.setOrderId(orderId);
+        onlinePayPo.setPayId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
+        onlinePayPo.setPayName(feeName);
+        onlinePayPo.setRefundFee("0");
+        onlinePayPo.setState(state);
+        onlinePayPo.setTotalFee(money + "");
+        onlinePayPo.setTransactionId(orderId);
+        onlinePayV1InnerServiceSMOImpl.saveOnlinePay(onlinePayPo);
+    }
+
+}

+ 171 - 0
service-acct/src/main/java/com/java110/acct/smo/impl/QrCodeSpdbPaymentAdapt.java

@@ -0,0 +1,171 @@
+package com.java110.acct.smo.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.payment.adapt.spdb.SPDBApiClient;
+import com.java110.acct.payment.adapt.spdb.SPDBApiResponse;
+import com.java110.acct.payment.adapt.spdb.SPDBSecurity;
+import com.java110.acct.smo.IQrCodePaymentSMO;
+import com.java110.core.client.RestTemplate;
+import com.java110.core.factory.CommunitySettingFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.cache.UrlCache;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.PayUtil;
+import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * 工商银行支付
+ */
+@Service
+public class QrCodeSpdbPaymentAdapt implements IQrCodePaymentSMO {
+    private static Logger logger = LoggerFactory.getLogger(QrCodeSpdbPaymentAdapt.class);
+
+    //微信支付
+    public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
+    // 微信服务商支付开关
+    public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
+
+    //开关ON打开
+    public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
+
+    public static final String wxPayUnifiedOrder = "https://api.spdb.com.cn/spdb/prd/api/acquiring/appPay/initiation";
+
+    @Autowired
+    private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+    @Override
+    public ResultVo pay(String communityId, String orderNum, double money, String authCode, String feeName) throws Exception {
+        logger.info("【浦发银行支付】 统一下单开始, 订单编号=" + orderNum);
+        String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/wechat/992020011134400001";
+
+        //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元
+        // double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue(MappingConstant.ENV_DOMAIN,"HC_ENV"), money);
+        double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue("HC_ENV"), money);
+        //添加或更新支付记录(参数跟进自己业务需求添加)
+
+        CommonCache.setValue("spdb_qrcode_payment_" + orderNum, payAmount + "", CommonCache.PAY_DEFAULT_EXPIRE_TIME);
+
+        String clientId = CommunitySettingFactory.getValue(communityId, "SPDB_CLIENT_ID");
+        String secret = CommunitySettingFactory.getValue(communityId, "SPDB_SECRET");
+        String privateKey = CommunitySettingFactory.getRemark(communityId, "SPDB_PRIVATE_KEY");
+        String apiPublicKey = CommunitySettingFactory.getRemark(communityId, "SPDB_PUBLIC_KEY");
+        String terminalNo = CommunitySettingFactory.getValue(communityId, "SPDB_TERMINAL_NO");
+        String spdbMrchNo = CommunitySettingFactory.getValue(communityId, "SPDB_MRCH_NO");
+
+        SPDBSecurity spdbSecurity = new SPDBSecurity(clientId, secret, privateKey, apiPublicKey);
+        SPDBApiClient spdbApiClient = new SPDBApiClient(spdbSecurity);
+
+        if (feeName.length() > 127) {
+            feeName = feeName.substring(0, 126);
+        }
+
+        JSONObject paramIn = new JSONObject();
+        paramIn.put("ordTtl", feeName);
+        paramIn.put("terminalNo", terminalNo);
+        // paramIn.put("busnPckt", terminalNo);
+        paramIn.put("spdbMrchNo", spdbMrchNo);
+        paramIn.put("createTimep", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_DEFAULT));
+        paramIn.put("mrchlInfmAdr", notifyUrl);
+        paramIn.put("cmdtyDsc", feeName);
+        paramIn.put("terminaIP", PayUtil.getLocalIp());
+        paramIn.put("channelNo", "00");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.HOUR_OF_DAY, 1);
+        paramIn.put("trnsFnshStrtTm", DateUtil.getFormatTimeString(c.getTime(), DateUtil.DATE_FORMATE_STRING_DEFAULT));
+        paramIn.put("frmrMrchOrdrNo", orderNum);
+        paramIn.put("tranAmt", payAmount);
+        paramIn.put("prblmNo", orderNum);
+        int pre = Integer.parseInt(authCode.substring(0, 2));
+        if (pre > 24 && pre < 31) { // 支付宝
+            paramIn.put("tranType", "OF");
+        } else {
+            paramIn.put("tranType", "OC");
+        }
+        paramIn.put("authrCd", authCode);
+
+        SPDBApiResponse response = spdbApiClient.post(wxPayUnifiedOrder, paramIn.toJSONString());
+
+        if (response.getHttpStatus() != 0000) {
+            throw new IllegalArgumentException(response.getResBody());
+        }
+        logger.debug("统一下单返回" + response.getResBody());
+
+        JSONObject paramOut = JSONObject.parseObject(response.getResBody());
+
+        if (!"0000".equals(paramOut.getString("statusCode"))) {
+            throw new IllegalArgumentException(paramOut.getString("statusMsg"));
+        }
+
+
+        if (!"00".equals(paramOut.getString("ordrSt"))) {
+            return new ResultVo(ResultVo.CODE_ERROR, "未知异常");
+        }
+
+        return new ResultVo(ResultVo.CODE_OK, "成功");
+
+    }
+
+    public ResultVo checkPayFinish(String communityId, String orderNum) {
+        SmallWeChatDto shopSmallWeChatDto = null;
+        Map<String, String> result = null;
+
+        String clientId = CommunitySettingFactory.getValue(communityId, "SPDB_CLIENT_ID");
+        String secret = CommunitySettingFactory.getValue(communityId, "SPDB_SECRET");
+        String privateKey = CommunitySettingFactory.getRemark(communityId, "SPDB_PRIVATE_KEY");
+        String apiPublicKey = CommunitySettingFactory.getRemark(communityId, "SPDB_PUBLIC_KEY");
+        String terminalNo = CommunitySettingFactory.getValue(communityId, "SPDB_TERMINAL_NO");
+        String spdbMrchNo = CommunitySettingFactory.getValue(communityId, "SPDB_MRCH_NO");
+        try {
+            SPDBSecurity spdbSecurity = new SPDBSecurity(clientId, secret, privateKey, apiPublicKey);
+            SPDBApiClient spdbApiClient = new SPDBApiClient(spdbSecurity);
+
+
+            JSONObject paramIn = new JSONObject();
+            paramIn.put("mrchOrdrNo", orderNum);
+            paramIn.put("spdbMrchNo", spdbMrchNo);
+            paramIn.put("tranDate", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H));
+
+            String payAmount = CommonCache.getValue("spdb_qrcode_payment_" + orderNum);
+            paramIn.put("tranAmt", payAmount);
+
+            SPDBApiResponse response = spdbApiClient.post(wxPayUnifiedOrder, paramIn.toJSONString());
+
+            if (response.getHttpStatus() != 0000) {
+                throw new IllegalArgumentException(response.getResBody());
+            }
+            logger.debug("统一下单返回" + response.getResBody());
+
+            JSONObject paramOut = JSONObject.parseObject(response.getResBody());
+
+            if (!"0000".equals(paramOut.getString("statusCode"))) {
+                throw new IllegalArgumentException(paramOut.getString("statusMsg"));
+            }
+
+
+            if ("00".equals(paramOut.getString("ordrSt"))) {
+                return new ResultVo(ResultVo.CODE_OK, "成功");
+            } else if ("09".equals(paramOut.getString("ordrSt"))) {
+                return new ResultVo(ResultVo.CODE_WAIT_PAY, "等待支付完成");
+            } else {
+                return new ResultVo(ResultVo.CODE_ERROR, "支付已经被取消,银行 状态码:" + paramOut.getString("ordrSt"));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResultVo(ResultVo.CODE_ERROR, "未知异常" + e.getMessage());
+        }
+
+
+    }
+}