package com.fzzy.push.gd2020.v2;
|
|
import com.fzzy.api.data.AuthToken;
|
import com.fzzy.api.entity.ApiConfs;
|
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
|
|
import javax.xml.namespace.QName;
|
|
/**
|
* @Desc: token获取
|
* @author: Andy
|
* @update-time: 2022/10/10
|
*/
|
public class AuthTokenWebService {
|
|
|
public static AuthTokenWebService newInstance() {
|
return new AuthTokenWebService();
|
}
|
|
/**
|
* 获取接口报文方法
|
*
|
* @param username
|
* @param password
|
* @return
|
*/
|
public AuthToken getToken(String bastPath, String username, String password) {
|
|
//在一个方法中连续调用多次WebService接口,每次调用前需要重置上下文
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
AuthToken authToken = new AuthToken();
|
String result;
|
String url = bastPath + "/authWebService?wsdl";// 填写身份验证接口服务地址
|
String method = "authToken";// 填写身份验证接口服务的方法
|
String nameSpace = "http://service.sljt.com";
|
|
Thread.currentThread().setContextClassLoader(cl);
|
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
|
org.apache.cxf.endpoint.Client client = dcf.createClient(url);
|
QName name = new QName(nameSpace, method);
|
Object[] objects;
|
try {
|
objects = client.invoke(name, new Object[]{username, password});
|
|
result = objects[0].toString();
|
authToken.setToken(result);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return authToken;
|
}
|
|
/**
|
* 获取接口报文方法
|
*
|
* @return
|
*/
|
public AuthToken getToken(ApiConfs apiConf) {
|
return getToken(apiConf.getApiUrl(), apiConf.getUserName(), apiConf.getPassword());
|
}
|
|
|
public static void main(String[] args) {
|
|
/**
|
* 广澳粮库:91440500190354212L004 密码:123456
|
*
|
*
|
*/
|
String pwd = "123456";
|
String bastPath = "https://ylt.gdgrain.gd.gov.cn:8443/spt-main/services/v2";
|
|
String userName = "91440500190354212L004";
|
|
|
AuthTokenWebService webService = AuthTokenWebService.newInstance();
|
|
AuthToken authToken = webService.getToken(bastPath, userName, pwd);
|
|
System.out.println(authToken.toString());
|
|
}
|
|
}
|