Commit fd4aa0e1 by rongkailun

Merge remote-tracking branch 'origin/master'

parents 807f2032 5aea37e4
......@@ -233,6 +233,25 @@
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.xml.rpc</groupId>
<artifactId>javax.xml.rpc-api</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
......
package io.office.common.constant;
/**
*
* 
 @description:
*
* @author wudi
* @date 18:25 2021/11/14
*/
public class WebServiceConstant {
private static String PrefixLicensee = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n" +
" <soap12:Header>\n" +
" <requestHeader xmlns=\"http://gepir4.ws.gs1.org/\">\n" +
" <requesterGLN xmlns=\"\">@{requesterGLN}</requesterGLN>\n" +
" <onBehalfOfGLN xmlns=\"\">@{onBehalfOfGLN}</onBehalfOfGLN>\n" +
" <isAuthenticated xmlns=\"\">@{Authenticated}</isAuthenticated>\n" +
" <cascade xmlns=\"\">@{cascade}</cascade>\n" +
" </requestHeader>\n" +
" </soap12:Header>\n" +
" <soap12:Body>\n" +
" <getPrefixLicensee xmlns=\"http://gepir4.ws.gs1.org/\">\n" +
" <getPrefixLicensee xmlns=\"\">\n" +
" <getPrefixLicensee>\n" +
" <requestedKeyCode>@{requestedKeyCode}<requestedKeyCode/>\n" +
" <requestedKeyValue>@{requestedKeyValue}</requestedKeyValue>\n" +
" <requestedLanguage>en</requestedLanguage>" +
" </getPrefixLicensee>\n" +
" </getPrefixLicensee>\n" +
" </getPrefixLicensee>\n" +
" </soap12:Body>\n" +
"</soap12:Envelope>";
}
package io.office.modules.manage.controller;
import io.office.common.utils.IPUtils;
import io.office.common.utils.R;
import io.office.modules.app.annotation.Login;
import io.office.modules.manage.entity.SearchgtinlogEntity;
import io.office.modules.manage.service.SearchgtinlogService;
import io.office.modules.manage.utils.GLNSearchUtils;
import io.office.modules.manage.utils.UploadUtils;
import io.office.modules.manage.vo.request.GLNRequestBo;
import io.office.modules.sys.service.SysCaptchaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
/**
*
* 
 @description:
*
* @author wudi
* @date 10:36 2021/11/21
*/
@RestController
@RequestMapping(value = "/codeSearch")
@Slf4j
public class GLNController {
@Autowired
private SysCaptchaService sysCaptchaService;
@Autowired
private SearchgtinlogService searchgtinlogService;
@Login
@PostMapping("/api/gln")
public R uploadFile(@RequestBody GLNRequestBo glnRequestBo, HttpServletRequest request) {
/* boolean captcha = sysCaptchaService.validate(glnRequestBo.getUuid(), glnRequestBo.getCaptcha());
if(!captcha){
return R.error("验证码不正确");
}*/
SearchgtinlogEntity searchgtinlogEntity = new SearchgtinlogEntity();
searchgtinlogEntity.setCreatedate(new Date());
searchgtinlogEntity.setIp(IPUtils.getIpAddr(request));
if(glnRequestBo.getType().equals("GLN")) {
searchgtinlogEntity.setClassStr("GLN查询");
} else if(glnRequestBo.getType().equals("GTIN")){
searchgtinlogEntity.setClassStr("境外条码查询:厂商信息查询");
}
searchgtinlogEntity.setKeyword(glnRequestBo.getCode());
searchgtinlogEntity.setSearchsource(0);
//新增查询日志
searchgtinlogService.save(searchgtinlogEntity);
return R.ok().put("data",GLNSearchUtils.getGLNResult("9","GLN",glnRequestBo.getCode(),glnRequestBo.getRequestedLanguage()));
}
}
......@@ -91,6 +91,7 @@ public class SearchgtinlogController {
public R delete(@RequestBody Integer[] ids){
searchgtinlogService.removeByIds(Arrays.asList(ids));
return R.ok();
}
......
......@@ -24,7 +24,7 @@ public class SearchgtinlogEntity implements Serializable {
* $column.comments
*/
@TableId
private Integer id;
private Long id;
/**
* $column.comments
*/
......
package io.office.modules.manage.utils;
import io.office.modules.manage.webservice.PartyDataLine;
import io.office.modules.manage.webservice.WebServiceXmlTemplate;
import org.jdom.Document;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
/**
*
* 
 @description:
*
* @author wudi
* @date 10:37 2021/11/21
*/
public class GLNSearchUtils {
public static PartyDataLine getGLNResult(String cascade,String requestedKeyCode,String requestedKeyValue,String requestedLanguage) {
String smsTemplateXml = WebServiceXmlTemplate.SEND_MESSAGE_TEMPLATE.replaceAll("\\$\\{cascade\\}", cascade).replaceAll("\\$\\{requestedKeyCode\\}", requestedKeyCode)
.replaceAll("\\$\\{requestedKeyValue\\}", requestedKeyValue).replaceAll("\\$\\{requestedLanguage\\}", requestedLanguage);
String url = "http://webservice.anccnet.com:8080/gepir4/gepirv4.asmx";
RestTemplate restTemplate = new RestTemplate();
//创建请求头
//创建请求头
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "text/xml; charset=utf-8");
HttpEntity<String> entity = new HttpEntity<>(smsTemplateXml, headers);
System.out.println(smsTemplateXml);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
// 下面的是通过解析xml字符串的
String returnObjs = responseEntity.getBody().substring(responseEntity.getBody().indexOf("<partyDataLine>"), responseEntity.getBody().indexOf("</gepirParty>")).replaceAll("<partyName />","");//注意 获取根节点的时候要查看返回的xml参数的形式是否为一个根节点
System.out.println(returnObjs);
PartyDataLine xmlObject = null;
Reader reader = null;
//利用JAXBContext将类转为一个实例
try {
JAXBContext context = JAXBContext.newInstance(PartyDataLine.class);
//XMl 转为对象的接口
Unmarshaller unmarshaller = context.createUnmarshaller();
reader = new StringReader(returnObjs);
xmlObject = (PartyDataLine) unmarshaller.unmarshal(reader);
if (reader != null) {
reader.close();
}
} catch (JAXBException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return xmlObject;
}
return null;
}
}
package io.office.modules.manage.vo.request;
import lombok.Data;
import java.io.Serializable;
/**
*
* 
 @description:
*
* @author wudi
* @date 10:46 2021/11/21
*/
@Data
public class GLNRequestBo implements Serializable {
private String captcha;
private String uuid;
private String code;
private String type;
private String requestedLanguage;
}
package io.office.modules.manage.webservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:11 2021/11/18
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "address")
public class Address implements Serializable {
private String name;
private String streetAddressOne;
private String city;
}
package io.office.modules.manage.webservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:13 2021/11/18
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "gS1CompanyPrefixLicensee")
public class GS1CompanyPrefixLicensee implements Serializable {
private String partyName;
}
package io.office.modules.manage.webservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:13 2021/11/18
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "gS1KeyLicensee")
public class GS1KeyLicensee implements Serializable {
private String partyName;
}
package io.office.modules.manage.webservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:12 2021/11/18
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "gepirRequestedKey")
public class GepirRequestedKey {
private String requestedKeyCode;
private String requestedKeyValue;
private String requestedLanguage;
}
package io.office.modules.manage.webservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:14 2021/11/18
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "informationProvider")
public class InformationProvider implements Serializable {
private String partyName;
private String gln;
}
package io.office.modules.manage.webservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:10 2021/11/18
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "partyDataLine")
public class PartyDataLine {
private String gS1CompanyPrefix;
private String partyDataLanguage;
private String returnCode;
private Address address;
private GepirRequestedKey gepirRequestedKey;
private GS1CompanyPrefixLicensee gS1CompanyPrefixLicensee;
private GS1KeyLicensee gS1KeyLicensee;
private InformationProvider informationProvider;
}
package io.office.modules.manage.webservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:05 2021/11/18
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "getPrefixLicenseeResponse")
public class PrefixLicenseeResponse implements Serializable {
private String gln;
private String partyName;
}
package io.office.modules.manage.webservice;
import cn.hutool.json.JSONUtil;
import org.jdom.Document;
import org.jdom.Element;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Iterator;
/**
*
* 
 @description:
*
* @author wudi
* @date 10:06 2021/11/18
*/
public class Test {
public static void main(String[] args) throws JAXBException, IOException {
String smsTemplateXml = WebServiceXmlTemplate.SEND_MESSAGE_TEMPLATE.replaceAll("\\$\\{cascade\\}", "9").replaceAll("\\$\\{requestedKeyCode\\}", "GLN")
.replaceAll("\\$\\{requestedKeyValue\\}", "6973947140013").replaceAll("\\$\\{requestedLanguage\\}", "en");
String url = "http://webservice.anccnet.com:8080/gepir4/gepirv4.asmx";
RestTemplate restTemplate = new RestTemplate();
//创建请求头
//创建请求头
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type","text/xml; charset=utf-8");
HttpEntity<String> entity = new HttpEntity<>(smsTemplateXml, headers);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
// 下面的是通过解析xml字符串的
Document doc = null;
String returnObjs = responseEntity.getBody().substring(responseEntity.getBody().indexOf("<partyDataLine>"),responseEntity.getBody().indexOf("</gepirParty>"));//注意 获取根节点的时候要查看返回的xml参数的形式是否为一个根节点
System.out.println(returnObjs);
Object xmlObject = null;
Reader reader = null;
//利用JAXBContext将类转为一个实例
JAXBContext context = JAXBContext.newInstance(PartyDataLine.class);
//XMl 转为对象的接口
Unmarshaller unmarshaller = context.createUnmarshaller();
reader = new StringReader(returnObjs);
xmlObject = unmarshaller.unmarshal(reader);
if (reader != null) {
reader.close();
}
System.out.println(JSONUtil.toJsonStr(xmlObject));
/*Object xmlObject = null;
Reader reader = null;
JAXBContext context = JAXBContext.newInstance(clazz);
// XML 转为对象的接口
Unmarshaller unmarshaller = context.createUnmarshaller();
reader = new StringReader(xmlStr);
//以文件流的方式传入这个string
xmlObject = unmarshaller.unmarshal(reader);
if (null != reader) {
reader.close();
}*/
}
/* headers
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
if(responseEntity.getBody().contains("<SendSMSResult>-6</SendSMSResult>")){
log.info("发送短信成功");
} else if(responseEntity.getBody().contains("<SendSMSResult>-7</SendSMSResult>")){
throw new BaseException(CommonEnum.SMS_ERROR_TIP_7);
} else if(responseEntity.getBody().contains("<SendSMSResult>-4</SendSMSResult>")){
throw new BaseException(CommonEnum.SMS_ERROR_TIP_4);
} else if(responseEntity.getBody().contains("<SendSMSResult>-3</SendSMSResult>")){
throw new BaseException(CommonEnum.SMS_ERROR_TIP_3);
} else if(responseEntity.getBody().contains("<SendSMSResult>-2</SendSMSResult>")){
throw new BaseException(CommonEnum.SMS_ERROR_TIP_2);
} else if(responseEntity.getBody().contains("<SendSMSResult>-11</SendSMSResult>")){
throw new BaseException(CommonEnum.SMS_ERROR_TIP_11);
} else if(responseEntity.getBody().contains("<SendSMSResult>-12</SendSMSResult>")){
throw new BaseException(CommonEnum.SMS_ERROR_TIP_12);
}*/
}
}
package io.office.modules.manage.webservice;
/**
*
* 
 @description:
*
* @author wudi
* @date 10:10 2021/11/18
*/
public class WebServiceXmlTemplate {
public static String SEND_MESSAGE_TEMPLATE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <soap:Header>\n" +
" <requestHeader xmlns=\"http://gepir4.ws.gs1.org/\">\n" +
" <requesterGLN xmlns=\"\">6900000000007</requesterGLN>\n" +
" <onBehalfOfGLN xmlns=\"\">6900000000007</onBehalfOfGLN>\n" +
" <isAuthenticated xmlns=\"\">true</isAuthenticated>\n" +
" <cascade xmlns=\"\">${cascade}</cascade>\n" +
" </requestHeader>\n" +
" </soap:Header>\n" +
" <soap:Body>\n" +
" <getPrefixLicensee xmlns=\"http://gepir4.ws.gs1.org/\">\n" +
" <getPrefixLicensee xmlns=\"\">\n" +
" <getPrefixLicensee>\n" +
" <requestedKeyCode>${requestedKeyCode}</requestedKeyCode>\n" +
" <requestedKeyValue>${requestedKeyValue}</requestedKeyValue>\n" +
" <requestedLanguage>${requestedLanguage}</requestedLanguage>\n" +
" </getPrefixLicensee>\n" +
" </getPrefixLicensee>\n" +
" </getPrefixLicensee>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment