|  | @@ -1,5 +1,8 @@
 | 
	
		
			
				|  |  |  package thyyxxk.webserver.service.jcptmobile;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import cn.hutool.core.date.DateUtil;
 | 
	
		
			
				|  |  | +import cn.hutool.crypto.asymmetric.KeyType;
 | 
	
		
			
				|  |  | +import cn.hutool.crypto.asymmetric.RSA;
 | 
	
		
			
				|  |  |  import com.dtflys.forest.Forest;
 | 
	
		
			
				|  |  |  import com.dtflys.forest.http.ForestRequest;
 | 
	
		
			
				|  |  |  import com.dtflys.forest.utils.ForestDataType;
 | 
	
	
		
			
				|  | @@ -7,28 +10,41 @@ import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.config.envionment.Other;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.utils.TokenUtil;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class JcptMobileService {
 | 
	
		
			
				|  |  |      private final Other other;
 | 
	
		
			
				|  |  | +    private final RSA rsa;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public JcptMobileService(Other other) {
 | 
	
		
			
				|  |  |          this.other = other;
 | 
	
		
			
				|  |  | +        rsa = new RSA(null, other.getPublicKey());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public ForestRequest<?> get(String url) {
 | 
	
		
			
				|  |  | -        return Forest.get(url)
 | 
	
		
			
				|  |  | -                .addHeader("token", TokenUtil.getInstance().getUserToken())
 | 
	
		
			
				|  |  | +    public ForestRequest<?> request(String url, String request) {
 | 
	
		
			
				|  |  | +        ForestRequest<?> forestRequest;
 | 
	
		
			
				|  |  | +        if ("get".equals(request)) {
 | 
	
		
			
				|  |  | +            forestRequest = Forest.get(url);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            forestRequest = Forest.post(url);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String token = TokenUtil.getInstance().getTokenUserId() + "_" + DateUtil.now();
 | 
	
		
			
				|  |  | +        String encrypted = rsa.encryptBase64(token, KeyType.PublicKey);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        forestRequest.addHeader("token", encrypted)
 | 
	
		
			
				|  |  |                  .bodyType(ForestDataType.JSON)
 | 
	
		
			
				|  |  |                  .addHeader("content-type", "application/json")
 | 
	
		
			
				|  |  |                  .basePath(other.getMobileAddress() + "/thyy/moveEmr/api");
 | 
	
		
			
				|  |  | +        return forestRequest;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public ForestRequest<?> get(String url) {
 | 
	
		
			
				|  |  | +        return request(url, "get");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public ForestRequest<?> post(String url) {
 | 
	
		
			
				|  |  | -        return Forest.post(url)
 | 
	
		
			
				|  |  | -                .addHeader("token", TokenUtil.getInstance().getUserToken())
 | 
	
		
			
				|  |  | -                .addHeader("content-type", "application/json")
 | 
	
		
			
				|  |  | -                .bodyType(ForestDataType.JSON)
 | 
	
		
			
				|  |  | -                .basePath(other.getMobileAddress() + "/thyy/moveEmr/api");
 | 
	
		
			
				|  |  | +        return request(url, "post");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  }
 |