zhangding 4 лет назад
Родитель
Сommit
53a1be3940

+ 27 - 4
suishenbang-api/src/test/java/test/MyTest.java

@@ -3,8 +3,8 @@ package test;
 
 import com.alibaba.fastjson.JSONObject;
 import com.dgtly.ApiApplication;
+import com.dgtly.wxportal.service.ESignService;
 import com.dgtly.wxportal.utils.ESign.ESignHttpUtil;
-import com.dgtly.wxportal.utils.ESign.ESignToken;
 import com.dgtly.wxportal.utils.ESign.ESignUrl;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -19,11 +19,34 @@ public class MyTest {
 
     @Autowired
     private ESignHttpUtil eSignHttpUtil;
+    @Autowired
+    private ESignService eSignService;
     @Test
     public void test(){
-        JSONObject json = new JSONObject();
-        String s=  eSignHttpUtil.doPost(ESignUrl.GetPersonalAddress,json);
-        System.out.println(s);
+        //创建文件
+        String result = eSignService.upload("D:/SZSM/工作交接表.docx");
+        System.out.println(result);
+
+        //注册用户
+        /*JSONObject json = new JSONObject();
+        json.put("thirdPartyUserId","18317541568");
+        json.put("name","张鼎");
+        json.put("idType","CRED_PSN_CH_IDCARD");
+        json.put("idNumber","410381200012281515");
+        json.put("mobile","18317541566");
+        json.put("email","18317541566@163.com");
+        String s=  eSignHttpUtil.doPost(ESignUrl.CreatePersonalAccount,json);
+        */
+
+        /*json.put("thirdPartyUserId","20190826110230222");
+        json.put("creator","40c83af8e2554732957ae14f357d37cb");
+        json.put("name","杭州天谷信息科技有限公司");
+        json.put("idType","CRED_PSN_CH_IDCARD");
+        json.put("idNumber","410381200012281514");
+        json.put("orgLegalIdNumber","410381200012281514");
+        json.put("orgLegalName","张鼎");*/
 
     }
+
+
 }

+ 25 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/ESignService.java

@@ -0,0 +1,25 @@
+package com.dgtly.wxportal.service;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * @author ZhangDing
+ * @version 1.0
+ * @descption: TODO
+ * @company 神州数码通用软件(洛阳)有限公司
+ * @copyright (c) 2019 LuoYang DGT Co'Ltd Inc. All rights reserved.
+ * @date 2020-10-10 11:26
+ * @since JDK1.8
+ */
+public interface ESignService {
+    /**
+     * @descption:
+     * @param:
+     * @return:
+     * @auther: ZhangDing
+     * @date: 2020-10-10 11:31
+     */
+    public String upload(String url);
+
+
+    }

+ 42 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/ESignServiceImpl.java

@@ -0,0 +1,42 @@
+package com.dgtly.wxportal.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.dgtly.wxportal.service.ESignService;
+import com.dgtly.wxportal.utils.ESign.ESignHttpUtil;
+import com.dgtly.wxportal.utils.ESign.ESignMD5;
+import com.dgtly.wxportal.utils.ESign.ESignUrl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+
+/**
+ * @author ZhangDing
+ * @version 1.0
+ * @descption: TODO
+ * @company 神州数码通用软件(洛阳)有限公司
+ * @copyright (c) 2019 LuoYang DGT Co'Ltd Inc. All rights reserved.
+ * @date 2020-10-10 11:27
+ * @since JDK1.8
+ */
+@Service
+public class ESignServiceImpl implements ESignService {
+
+    @Autowired
+    private ESignHttpUtil eSignHttpUtil;
+
+    @Override
+    public String upload(String url) {
+        File file = new File(url);
+        String fileName = file.getName();
+        JSONObject json = new JSONObject();
+        json.put("contentMd5", ESignMD5.getStringContentMD5(url));
+        json.put("contentType","application/octet-stream");
+        json.put("convert2Pdf",true);
+        json.put("fileName",fileName);
+        json.put("fileSize", ESignMD5.getFileSize(url));
+        String s=  eSignHttpUtil.doPost(ESignUrl.uploadCreateFile,json);
+        return s;
+    }
+
+}

+ 1 - 3
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/ESign/ESignErrCode.java

@@ -15,9 +15,7 @@ public class ESignErrCode {
 		codeMap.put("-1","系统繁忙");
 		codeMap.put("0","请求成功");
 		codeMap.put("401","token过期了或者 header请求头不正确 或 apiurl和应用ID的环境不对应,例如apiurl是模拟环境,应用ID是正式环境的");
-
-
-
+		codeMap.put("1560102","证件格式异常");
 		codeMap.put("53000000","个人账号已存在的");
 	}
 	

+ 81 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/ESign/ESignMD5.java

@@ -0,0 +1,81 @@
+package com.dgtly.wxportal.utils.ESign;
+
+import org.apache.commons.codec.binary.Base64;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author ZhangDing
+ * @version 1.0
+ * @descption: 计算文件MD5值
+ * @company 神州数码通用软件(洛阳)有限公司
+ * @copyright (c) 2019 LuoYang DGT Co'Ltd Inc. All rights reserved.
+ * @date 2020-10-10 11:05
+ * @since JDK1.8
+ */
+public class ESignMD5 {
+    /***
+     * 计算字符串的Content-MD5
+     * @param str 文件路径
+     * @return
+     */
+    public static String getStringContentMD5(String str) {
+        // 获取文件MD5的二进制数组(128位)
+        byte[] bytes = getFileMD5Bytes1282(str);
+        // 对文件MD5的二进制数组进行base64编码
+        return new String(Base64.encodeBase64(bytes));
+    }
+
+    /**
+     * @descption: 获取文件大小
+     * @param:
+     * @return:
+     * @auther: ZhangDing
+     * @date: 2020-10-10 14:02
+     */
+    public static int getFileSize(String filePath){
+        int size = 0;
+        File file = new File(filePath);
+        size = (int)file.length();
+        return size;
+    }
+
+    /***
+     * 获取文件MD5-二进制数组(128位)
+     *
+     * @param filePath
+     * @return
+     * @throws IOException
+     */
+    public static byte[] getFileMD5Bytes1282(String filePath) {
+        FileInputStream fis = null;
+        byte[] md5Bytes = null;
+        try {
+            File file = new File(filePath);
+            fis = new FileInputStream(file);
+            MessageDigest md5 = MessageDigest.getInstance("MD5");
+            byte[] buffer = new byte[1024];
+            int length = -1;
+            while ((length = fis.read(buffer, 0, 1024)) != -1) {
+                md5.update(buffer, 0, length);
+            }
+            md5Bytes = md5.digest();
+            fis.close();
+        } catch (FileNotFoundException e) {
+            System.out.println(e.getMessage());
+            e.printStackTrace();
+        } catch (NoSuchAlgorithmException e) {
+            System.out.println(e.getMessage());
+            e.printStackTrace();
+        } catch (IOException e) {
+            System.out.println(e.getMessage());
+            e.printStackTrace();
+        }
+        return md5Bytes;
+    }
+}

+ 2 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/ESign/ESignUrl.java

@@ -14,6 +14,8 @@ public enum ESignUrl {
     AccessToken("/v1/oauth2/access_token?appId=%s&secret=%s&grantType=client_credentials")
     ,CreatePersonalAccount("/v1/accounts/createByThirdPartyUserId")
     ,GetPersonalAddress("/v2/identity/auth/web/%s/indivIdentityUrl")
+    ,CreateThirdParty("/v1/organizations/createByThirdPartyUserId")
+    ,uploadCreateFile("/v1/files/getUploadUrl")
     ;
     private String url;
     private ESignConfig eSignConfig ;