zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.changhong.epc.admin;
 
import com.alibaba.fastjson.TypeReference;
import com.changhong.epc.bean.admin.InitPowerInfo;
import com.iemsoft.framework.cloud.core.password.MD5;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.http.Http;
import org.junit.Test;
import org.springframework.ui.ModelMap;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
 
//@RunWith(SpringRunner.class)
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MasterTest {
 
    public static final String id = "1000000";
 
    public static final String token = "e06b3e54e4e95fe4d1578df184f198f3";
 
    public static final String sign = "fa5e4cca8dc79ad8aa333e867b2ecb10";
//    @Test
    public void test2(){
        System.out.println(
                "{\"compId\":200,\"tenantId\":100000362,\"type\":\"I\",\"busType\":\"[{\\\"children\\\":[{\\\"children\\\":[],\\\"id\\\":51,\\\"name\\\":\\\"办公费\\\",\\\"orderTypeCode\\\":\\\"A0030001\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1},{\\\"children\\\":[],\\\"id\\\":55,\\\"name\\\":\\\"市内交通费\\\",\\\"orderTypeCode\\\":\\\"A0030003\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1},{\\\"children\\\":[],\\\"id\\\":151,\\\"name\\\":\\\"通讯费\\\",\\\"orderTypeCode\\\":\\\"A0030009\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"核算公司各管理、生产部门因工作需要发生的在规定报销范围内的通讯费,不包括由专项费用承担部分\\\\n;记账所需单据:分配表\\\",\\\"state\\\":0,\\\"type\\\":0},{\\\"children\\\":[],\\\"id\\\":371,\\\"name\\\":\\\"差旅费\\\",\\\"orderTypeCode\\\":\\\"A0030036\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"<p>差旅系统的差旅费。</p>\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1},{\\\"children\\\":[],\\\"id\\\":769,\\\"name\\\":\\\"公务接待费\\\",\\\"orderTypeCode\\\":\\\"A0030084\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1}],\\\"id\\\":17,\\\"name\\\":\\\"费用业务\\\",\\\"orderTypeCode\\\":\\\"A003\\\",\\\"parentId\\\":0,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":0}]\"}"
        );
    }
 
//    @Test
    public void test(){
//        InitCompany data = new InitCompany();
//        data.setOpenId("893ccd52f0ec4eae");
//        data.setOpenId("36b5b39ecbaef0e9");
        InitPowerInfo data = new InitPowerInfo();
        data.setAppKey("d225556010534db0a970d70fae190ef4");
        data.setSecretKey("c7cde0e36fb3404eab0f3efe350143e2");
 
        data.setCompanyId(2);
        data.setTenantId(9);
 
        Map<String, Object> val =
//        Http.post("https://epc.sunscloud.com/epc/epc-center-api/push/power", Map.class)
//        Http.post("http://chartbb.chfcloud.com:10080/ereport/push/power", Map.class)
//        Http.post("http://travelcl.chfcloud.com/travel-web/push/power", Map.class)
        Http.post("http://formbd.chfcloud.com:8086/autoForm/push/power", Map.class)
//        Http.post("https://epc.sunscloud.com/epc/epc-center-api/admin/doInit/company", Map.class)
//        Http.post("https://epc.sunscloud.com/epc/epc-tenant-api/json/updateBusType", Map.class)
                .addUrlParam(getParam(new ModelMap("data", JSONTool.toJson(data))))
//                .addUrlParam(getParam(new ModelMap("data", "{\"compId\":200,\"tenantId\":100000362,\"type\":\"I\",\"busType\":\"[{\\\"children\\\":[{\\\"children\\\":[],\\\"id\\\":51,\\\"name\\\":\\\"办公费\\\",\\\"orderTypeCode\\\":\\\"A0030001\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1},{\\\"children\\\":[],\\\"id\\\":55,\\\"name\\\":\\\"市内交通费\\\",\\\"orderTypeCode\\\":\\\"A0030003\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1},{\\\"children\\\":[],\\\"id\\\":151,\\\"name\\\":\\\"通讯费\\\",\\\"orderTypeCode\\\":\\\"A0030009\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"核算公司各管理、生产部门因工作需要发生的在规定报销范围内的通讯费,不包括由专项费用承担部分\\\\n;记账所需单据:分配表\\\",\\\"state\\\":0,\\\"type\\\":0},{\\\"children\\\":[],\\\"id\\\":371,\\\"name\\\":\\\"差旅费\\\",\\\"orderTypeCode\\\":\\\"A0030036\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"<p>差旅系统的差旅费。</p>\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1},{\\\"children\\\":[],\\\"id\\\":769,\\\"name\\\":\\\"公务接待费\\\",\\\"orderTypeCode\\\":\\\"A0030084\\\",\\\"parentId\\\":17,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":1}],\\\"id\\\":17,\\\"name\\\":\\\"费用业务\\\",\\\"orderTypeCode\\\":\\\"A003\\\",\\\"parentId\\\":0,\\\"remark\\\":\\\"\\\",\\\"sortCode\\\":\\\"A003\\\",\\\"state\\\":0,\\\"type\\\":0}]\"}")))
                .execute(new TypeReference<Map<String, Object>>(){}.getType())
                .orElse(new ModelMap());
        System.out.println(JSONTool.toJson(val));
    }
 
 
    public static Map<String, Object> getParam(Map<String, Object> data){
        Map<String, Object> param = new TreeMap<>(data);
        param.put("id", id + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%09d", new Random().nextInt(999999999)));
        param.put("token", token);
        param.put("sign", countSign(param));
        return param;
    }
 
    public static String countSign(Map<String, Object> param) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Object> map : param.entrySet()) {
            /* 拼接条件 */
            sb.append(map.getKey())
                    .append('=')
                    .append(map.getValue())
                    .append('&');
        }
        sb.append("key=").append(sign);
        return MD5.toMD5(sb.toString());
    }
}