rentaiming
2024-05-21 dd7ad1ab0ead2aa3c9f7fc35cc9b0635309c642a
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
package com.ruoyi.order.util.tencent.service;
import com.ruoyi.order.util.tencent.common.Configure;
 
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(Integer apptype,String api) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        apiURL = api;
    
           if (apptype.equals(2)) {//微信小程序和公众号的
                Class<?> c = Class.forName(Configure.HttpsRequestClassName_2);
                serviceRequest = (IServiceRequest) c.newInstance();
            } else {//微信app的
                Class<?> c = Class.forName(Configure.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;
    }
}