Browse Source

代码修改

LAPTOP-KB9HII50\70708 1 year ago
parent
commit
e6da844db9

+ 20 - 0
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/config/SystemConfig.java

@ -81,5 +81,25 @@ public class SystemConfig {
        return  getSystemProperties().getProperty("jw_licence");
    }
    public String getPlatformPublicKey()
    {
        return  getSystemProperties().getProperty("platform.public.key");
    }
    public String getCompanyPublicKey()
    {
        return  getSystemProperties().getProperty("company.public.key");
    }
    public String getCompanyPrivateKey()
    {
        return  getSystemProperties().getProperty("company.private.key");
    }
    public String getAuthorizationCode()
    {
        return  getSystemProperties().getProperty("authorization.code");
    }
    public String getKeyReadType()
    {
        return  getSystemProperties().getProperty("key.read.type");
    }
}

+ 11 - 0
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/controller/zy/IotDeviceController.java

@ -33,4 +33,15 @@ public class IotDeviceController extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = "/accesstoken2")
    @ApiOperation(value = "获取accesstoken2")
    public Envelop getAccessToken2() {
        try {
            return success(iotDeviceService.getAccessToken2());
        }catch (Exception e){
            e.printStackTrace();
            return Envelop.getError("查询失败");
        }
    }
}

+ 15 - 0
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/service/IotDeviceService.java

@ -1,6 +1,7 @@
package com.yihu.jw.entrance.service;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entrance.util.zysoft.SDKRunnerService;
import com.yihu.jw.entrance.util.zysoft.ZysoftBaseService;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import org.springframework.beans.factory.annotation.Autowired;
@ -22,6 +23,8 @@ public class IotDeviceService {
    private ZysoftBaseService zysoftBaseService;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private SDKRunnerService sdkRunnerService;
    /**
     * 获取accesstoken
@ -42,4 +45,16 @@ public class IotDeviceService {
        return response;
    }
    public String getAccessToken2(){
        Map<String,String> header = new HashMap<>();
        List<WlyyHospitalSysDictDO> dictDOList =  wlyyHospitalSysDictDao.findByDictName("zy_iot");
        Map<String,String> dictMap = dictDOList.stream().collect(Collectors.toMap(WlyyHospitalSysDictDO::getDictCode,WlyyHospitalSysDictDO::getDictValue));
        Map<String,String> params = new HashMap<>();
        params.put("appid",dictMap.get("appid"));
        params.put("appSecret",dictMap.get("appSecret"));
        String response = sdkRunnerService.post("wlw/accesstoken",params,header,true,true);
        return response;
    }
}

+ 58 - 0
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/util/zysoft/CallApiGatewaySample.java

@ -0,0 +1,58 @@
package com.yihu.jw.entrance.util.zysoft;
import cn.com.zoe.crypto.jna.CryptoType;
import com.zoe.phip.ssp.sdk.*;
import java.io.IOException;
import java.util.List;
public class CallApiGatewaySample extends AbstractApiExecuter2 {
    private String apiUrl;
    private List<RequestValue> parameters;
    private RequestMethod method;
    private HeaderValue[] headers;
    public CallApiGatewaySample(byte[] platformPublicKey, byte[] parameterPublicKey, byte[] resultPrivateKey) {
        super(platformPublicKey, parameterPublicKey, resultPrivateKey);
    }
    public CallApiGatewaySample(String publicKeyBase64String, String parameterPublicKey, String resultPrivateKey) {
        super(publicKeyBase64String, parameterPublicKey, resultPrivateKey);
    }
    public CallApiGatewaySample setApiUrl(String apiUrl) {
        this.apiUrl = apiUrl;
        return this;
    }
    public CallApiGatewaySample setParameters(List<RequestValue> parameters) {
        this.parameters = parameters;
        return this;
    }
    public CallApiGatewaySample setMethod(RequestMethod method) {
        this.method = method;
        return this;
    }
    public CallApiGatewaySample setHeaders(HeaderValue[] headers) {
        this.headers = headers;
        return this;
    }
    @Override
    public String run(String authorizationCode, boolean openCrypto, CryptoType type) throws ApiException, IOException {
        if (!CryptoType.NO_CRYPTO.equals(type) && (authorizationCode == null || "".equals(authorizationCode))) {
            throw new ApiException("用户token不能为空", null);
        }
        if (apiUrl == null || "".equals(apiUrl)) {
            throw new ApiException("未填写接口地址", null);
        }
        if (method == null) {
            method = RequestMethod.POST;
        }
        return doHttp(apiUrl, method, authorizationCode, openCrypto, parameters, type, headers);
    }
}

+ 123 - 0
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/util/zysoft/SDKRunnerService.java

@ -0,0 +1,123 @@
package com.yihu.jw.entrance.util.zysoft;
import cn.com.zoe.crypto.Base64;
import cn.com.zoe.crypto.jna.CryptoType;
import com.yihu.jw.entrance.config.SystemConfig;
import com.zoe.phip.ssp.sdk.ApiException;
import com.zoe.phip.ssp.sdk.HeaderValue;
import com.zoe.phip.ssp.sdk.RequestMethod;
import com.zoe.phip.ssp.sdk.RequestValue;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * SDK调用代码参考
 */
@Service
public class SDKRunnerService {
    private static String platformPublicKey;
    private static String companyPrivateKeyBase64String;
    private static String companyPublicKeyBase64String;
    private static String authorizationCode;
    private static String gateway_url;
    static {
        platformPublicKey = getEncryptData(SystemConfig.getInstance().getPlatformPublicKey());
        companyPrivateKeyBase64String = getEncryptData(SystemConfig.getInstance().getCompanyPrivateKey());
        companyPublicKeyBase64String = getEncryptData(SystemConfig.getInstance().getCompanyPublicKey());
//        platformPublicKey = SystemConfig.getInstance().getPlatformPublicKey();
//        companyPrivateKeyBase64String = SystemConfig.getInstance().getCompanyPrivateKey();
//        companyPublicKeyBase64String = SystemConfig.getInstance().getCompanyPublicKey();
        // 平台分配的授权码
        authorizationCode = SystemConfig.getInstance().getAuthorizationCode();
        gateway_url = SystemConfig.getInstance().getGatewayUrl();
    }
    /**
     *
     * @param api
     * @param params
     * @param header
     * @param openCrypto 是否启用平台加密
     * @param urlEncode url编码
     * @return
     */
    public String post(String api, Map<String,String> params,Map<String,String> header,boolean openCrypto,boolean urlEncode){
        String result = null;
        try {
            // 密钥类型(RSA、SM2、SM2V2)
            CryptoType type = CryptoType.SM2_V2;
            // 接口地址
            String apiUrl = gateway_url+api;
            // 参数
            List<RequestValue> parameters = new ArrayList<>();
            if(params!=null)
            {
                // 普通参数请求示例
//                    new RequestValue("msgHeader", "<?xml version=\"1.0\" encoding=\"utf-8\"?><ROOT></ROOT>", true, openCrypto),
//                    new RequestValue("msgBody", "<?xml version=\"1.0\" encoding=\"utf-8\"?><ROOT></ROOT>", true, openCrypto)
                // new RequestValue("idCard", "123", true, openCrypto)
                //实体参数请求示例
//                    new RequestValue("{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}")
                for(String key :params.keySet())
                {
                    RequestValue obj = new RequestValue(key,params.get(key),urlEncode,openCrypto);
                    parameters.add(obj);
                }
            }
            HeaderValue[] headers = new HeaderValue[header.size()];
//            headers[0] = new HeaderValue("Content-Type","application/json",true);
            int i = 0;
            for(String key :header.keySet())
            {
                headers[i] = new HeaderValue(key,header.get(key),urlEncode);
                i++;
            }
            // 请求方式
            RequestMethod method = RequestMethod.POST;
            //实例化需要使用的接口对象
            CallApiGatewaySample runnable =
                    new CallApiGatewaySample(platformPublicKey, companyPublicKeyBase64String, companyPrivateKeyBase64String)
                            .setApiUrl(apiUrl)
                            .setParameters(parameters)
                            .setHeaders(headers)
                            .setMethod(method);
            // 运行Api进行数据请求
            result = runnable.run(authorizationCode, openCrypto, type);
        } catch (ApiException e) {
            System.out.println("Api请求失败:");
            System.out.println("\t 编码: " + e.errorCode());
            System.out.println("\t 信息: " + e.getMessage());
            e.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
    private static String getEncryptData(String value) {
        InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(value);
        try {
            if (stream != null && stream.available() > 0) {
                byte[] bytes = new byte[stream.available()];
                stream.read(bytes);
                return Base64.getEncoder().encodeToString(bytes);
            } else {
                System.out.println("未找到密钥文件:"+value);
            }
        } catch (Exception e) {
            System.out.println("读取密钥文件出错:"+value);
            e.printStackTrace();
        }
        return null;
    }
}

+ 5 - 0
svr/svr-internet-hospital-entrance/src/main/resources/jwkey/sqsyy_PrivateKey.SM2_V2.key

@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQg8kLSVhORuWO9i7Rx
CkEQqJusNfbIutl2dTnQ+WgQVZKhRANCAASahdH/xeHWXsxQ6SPfmN+TwslMqy8k
XhH8K+CY71oEZ13991AOv8H21NBd7AZ8Qcj/itJHu3Hf59q0J2pfy7ky
-----END PRIVATE KEY-----

+ 4 - 0
svr/svr-internet-hospital-entrance/src/main/resources/jwkey/sqsyy_PublicKey.SM2_V2.key

@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEmoXR/8Xh1l7MUOkj35jfk8LJTKsv
JF4R/CvgmO9aBGdd/fdQDr/B9tTQXewGfEHI/4rSR7tx3+fatCdqX8u5Mg==
-----END PUBLIC KEY-----

+ 19 - 9
svr/svr-internet-hospital-entrance/src/main/resources/system.properties

@ -1,16 +1,26 @@
#?????? 0?? 1???
key.read.type=0
##test
gateway_url = http://117.25.173.18:18280/
#gateway_url = http://117.25.173.18:18280/
#gateway_licence = 1GPM6UKII0NF33155F0A0000348D061E
#gateway_public_key = PublicKeyTest.key
#jw_hospital = 350211A1004
#jw_licence = 1GPM6UKII0NF33155F0A0000348D061E
#platform.public.key=jwkey/ZOE.PLATFORM_PublicKey.SM2_V2.key
#company.public.key=jwkey/sqsyy_PublicKey.SM2_V2.key
#company.private.key=jwkey/sqsyy_PrivateKey.SM2_V2.key
#authorization.code=1ERSRATH80010100007F0000E43BC68D
###prod
gateway_url = http://10.95.21.21:18280/
gateway_licence = 1GPM6UKII0NF33155F0A0000348D061E
gateway_public_key = PublicKeyTest.key
gateway_public_key = PublicGov.key
jw_hospital = 350211A1004
jw_licence = 1GPM6UKII0NF33155F0A0000348D061E
platform.public.key=jwkey/ZOE.PLATFORM_PublicKey.SM2_V2.key
company.public.key=jwkey/350211A1004_PublicKey.SM2_V2.key
company.private.key=jwkey/350211A1004_PrivateKey.SM2_V2.key
authorization.code=1GPM6UKII0NF33155F0A0000348D061E
###prod
#gateway_url = http://10.95.21.21:18280/
#gateway_licence = 1GPM6UKII0NF33155F0A0000348D061E
#gateway_public_key = PublicGov.key
#jw_hospital = 350211A1004
#jw_licence = 1GPM6UKII0NF33155F0A0000348D061E