xiaoyong931011
2022-09-24 3ddef0887c7446b7eab55caf067ef68dc399e166
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
package cc.mrbird.febs.pay.service.impl;
 
import cc.mrbird.febs.pay.service.IServiceRequest;
 
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
 
/**
 * User: rizenguo
 * Date: 2014/12/10
 * Time: 15:44
 * 服务的基类
 */
public class BaseService {
 
    //API的地址
    private String apiURL;
 
    //发请求的HTTPS请求器
    private IServiceRequest serviceRequest;
 
    public BaseService(String api, String HttpsRequestClassName) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        apiURL = api;
        Class<?> c = Class.forName(HttpsRequestClassName);
        serviceRequest = (IServiceRequest) c.newInstance();
    }
 
    protected String sendPost(Object xmlObj) throws UnrecoverableKeyException, IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
        return serviceRequest.sendPost(apiURL,xmlObj);
    }
 
    
    /**
     * 供商户想自定义自己的HTTP请求器用
     * @param request 实现了IserviceRequest接口的HttpsRequest
     */
    public void setServiceRequest(IServiceRequest request){
        serviceRequest = request;
    }
 
    public IServiceRequest getServiceRequest() {
        return serviceRequest;
    }
}