commit
8ab3d59f80
@ -0,0 +1,20 @@ |
|||||||
|
package com.dxhy.erp.dao; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.dxhy.erp.entity.BaseTDxTaxCurrent; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* |
||||||
|
* 企业税务信息表dao |
||||||
|
* |
||||||
|
* |
||||||
|
* @author peipei.li |
||||||
|
* @date 2019-04-23 |
||||||
|
*/ |
||||||
|
@SuppressWarnings("AlibabaClassNamingShouldBeCamel") |
||||||
|
@Mapper |
||||||
|
public interface BaseTDxTaxCurrentDao extends BaseMapper<BaseTDxTaxCurrent> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,106 @@ |
|||||||
|
package com.dxhy.erp.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* |
||||||
|
* 企业税务信息表 |
||||||
|
* |
||||||
|
* @author peipei.li |
||||||
|
* @date 2019-04-23 |
||||||
|
*/ |
||||||
|
@SuppressWarnings("AlibabaClassNamingShouldBeCamel") |
||||||
|
@Data |
||||||
|
@TableName("t_dx_tax_current") |
||||||
|
public class BaseTDxTaxCurrent implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = -6721685467254429845L; |
||||||
|
|
||||||
|
/** |
||||||
|
* id |
||||||
|
*/ |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** |
||||||
|
* 税号 |
||||||
|
*/ |
||||||
|
private String taxno; |
||||||
|
|
||||||
|
/** |
||||||
|
* 企业名称 |
||||||
|
*/ |
||||||
|
private String taxname; |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前税款所属期 |
||||||
|
*/ |
||||||
|
private String currentTaxPeriod; |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前税款所属期可勾选发票的起始开票日期 |
||||||
|
*/ |
||||||
|
private String selectStartDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前税款所属期可勾选发票的截止开票日期 |
||||||
|
*/ |
||||||
|
private String selectEndDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前税款所属期可勾选发票操作截止日期 |
||||||
|
*/ |
||||||
|
private String operationEndDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 企业旧税号 |
||||||
|
*/ |
||||||
|
private String oldTaxNo; |
||||||
|
|
||||||
|
/** |
||||||
|
* 申报周期,值为3-季度/1-月 |
||||||
|
*/ |
||||||
|
private String declarePeriod; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信用等级,值为a/b/c/d或者空 |
||||||
|
*/ |
||||||
|
private String creditRating; |
||||||
|
|
||||||
|
/** |
||||||
|
* update_time |
||||||
|
*/ |
||||||
|
private Date updateTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* create_time |
||||||
|
*/ |
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 锁定状态:0否;1是 |
||||||
|
*/ |
||||||
|
private String latchStatus; |
||||||
|
|
||||||
|
/** |
||||||
|
* 抵扣限额 |
||||||
|
*/ |
||||||
|
private BigDecimal limitDkse; |
||||||
|
|
||||||
|
private String bussiPwd; |
||||||
|
|
||||||
|
private String newBussiPwd; |
||||||
|
|
||||||
|
private String companyType; |
||||||
|
private String oilType; |
||||||
|
private String taxpayerType; |
||||||
|
private String syncTime; |
||||||
|
private String indexInfo; |
||||||
|
private String periodIndexInfo; |
||||||
|
private String monthIndexInfo; |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.dxhy.erp.entity.kfpt; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by rei on 2021/8/26. |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ApiCheckInvoiceSingleRequest { |
||||||
|
|
||||||
|
private String fpdm; |
||||||
|
private String fphm; |
||||||
|
private String fpje; |
||||||
|
private String jym; |
||||||
|
private String kprq; |
||||||
|
private String fpzl; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package com.dxhy.erp.entity.kfpt; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by rei on 2021/8/26. |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ApiRequest { |
||||||
|
|
||||||
|
private String zipCode; |
||||||
|
private String encryptCode; |
||||||
|
private String dataExchangeId; |
||||||
|
private String entCode; |
||||||
|
private String content; |
||||||
|
|
||||||
|
public ApiRequest() { |
||||||
|
zipCode = "0"; |
||||||
|
encryptCode = "0"; |
||||||
|
dataExchangeId = UUID.randomUUID().toString().replace("-", ""); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.dxhy.erp.entity.kfpt; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by rei on 2021/8/26. |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ApiResponse { |
||||||
|
|
||||||
|
private String zipCode; |
||||||
|
private String encryptCode; |
||||||
|
private String dataExchangeId; |
||||||
|
private String entCode; |
||||||
|
private String content; |
||||||
|
private ApiReturnStateInfo returnStateInfo; |
||||||
|
private String status; |
||||||
|
private String error; |
||||||
|
private String message; |
||||||
|
private String timestamp; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.dxhy.erp.entity.kfpt; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by rei on 2021/8/26. |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ApiReturnStateInfo { |
||||||
|
|
||||||
|
private String returnCode; |
||||||
|
private String returnMessage; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.dxhy.erp.entity.kfpt; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by rei on 2021/8/26. |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class TokenRequest { |
||||||
|
|
||||||
|
private String appKey; |
||||||
|
private String appSecret; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.dxhy.erp.entity.kfpt; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by rei on 2021/8/26. |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class TokenResponse { |
||||||
|
|
||||||
|
private String access_token; |
||||||
|
private String token_type; |
||||||
|
private String expires_in; |
||||||
|
private String scope; |
||||||
|
private String error; |
||||||
|
private String error_description; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
package com.dxhy.erp.utils; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.dxhy.erp.entity.kfpt.ApiRequest; |
||||||
|
import com.dxhy.erp.entity.kfpt.ApiResponse; |
||||||
|
import com.dxhy.erp.entity.kfpt.TokenRequest; |
||||||
|
import com.dxhy.erp.entity.kfpt.TokenResponse; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang.StringUtils; |
||||||
|
import org.joda.time.DateTime; |
||||||
|
import org.joda.time.Duration; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* 接口工具类 |
||||||
|
* |
||||||
|
* @author REI |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
public class ApiUtils { |
||||||
|
|
||||||
|
@Value("${params.api.tokenUrl}") |
||||||
|
private String tokenUrl; |
||||||
|
@Value("${params.api.connTimeout}") |
||||||
|
private int connTimeout; |
||||||
|
@Value("${params.api.readTimeout}") |
||||||
|
private int readTimeout; |
||||||
|
private String contentType = "application/json"; |
||||||
|
private String charset = "UTF-8"; |
||||||
|
|
||||||
|
private TokenResponse callToken(String url, TokenRequest tokenRequest) { |
||||||
|
final DateTime start = DateTime.now(); |
||||||
|
String body = JSONObject.toJSONString(tokenRequest); |
||||||
|
String result = null; |
||||||
|
try { |
||||||
|
result = HttpClientUtils.post(url, body, contentType, charset, connTimeout, readTimeout); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("<线程" + Thread.currentThread().getId() + ">调用开放平台获取token异常:", e); |
||||||
|
} finally { |
||||||
|
log.info("<线程{}>interface={}|param={}|result={}|responseTime={}", |
||||||
|
Thread.currentThread().getId(), url, body, result, new Duration(start, DateTime.now()).getMillis()); |
||||||
|
} |
||||||
|
return JSONObject.parseObject(result, TokenResponse.class); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public ApiResponse callApi(String url, String entCode, Object content, String accessToken, String requestId) { |
||||||
|
final DateTime start = DateTime.now(); |
||||||
|
ApiRequest apiRequest = new ApiRequest(); |
||||||
|
apiRequest.setContent(Base64.encode(JSONObject.toJSONBytes(content))); |
||||||
|
apiRequest.setEntCode(entCode); |
||||||
|
apiRequest.setDataExchangeId(requestId); |
||||||
|
String body = JSONObject.toJSONString(apiRequest); |
||||||
|
url = url + accessToken; |
||||||
|
String result = null; |
||||||
|
try { |
||||||
|
result = HttpClientUtils.post(url, body, contentType, charset, connTimeout, readTimeout); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("<线程" + Thread.currentThread().getId() + ">调用开放平台业务接口异常:", e); |
||||||
|
} finally { |
||||||
|
log.info("<线程{}>interface={}|param={}|result={}|responseTime={}", |
||||||
|
Thread.currentThread().getId(), url, body, result, new Duration(start, DateTime.now()).getMillis()); |
||||||
|
} |
||||||
|
ApiResponse apiResponse = JSONObject.parseObject(result, ApiResponse.class); |
||||||
|
return apiResponse; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public TokenResponse getToken(String appKey, String appSecret) { |
||||||
|
TokenRequest tokenRequest = new TokenRequest(); |
||||||
|
tokenRequest.setAppKey(appKey); |
||||||
|
tokenRequest.setAppSecret(appSecret); |
||||||
|
TokenResponse tokenResponse = callToken(tokenUrl, tokenRequest); |
||||||
|
if (tokenResponse != null && StringUtils.isEmpty(tokenResponse.getError())) { |
||||||
|
return tokenResponse; |
||||||
|
} else { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,271 @@ |
|||||||
|
package com.dxhy.erp.utils; |
||||||
|
|
||||||
|
public final class Base64 { |
||||||
|
|
||||||
|
static private final int BASELENGTH = 128; |
||||||
|
static private final int LOOKUPLENGTH = 64; |
||||||
|
static private final int TWENTYFOURBITGROUP = 24; |
||||||
|
static private final int EIGHTBIT = 8; |
||||||
|
static private final int SIXTEENBIT = 16; |
||||||
|
static private final int SIXBIT = 6; |
||||||
|
static private final int FOURBYTE = 4; |
||||||
|
static private final int SIGN = -128; |
||||||
|
static private final char PAD = '='; |
||||||
|
static private final boolean fDebug = false; |
||||||
|
static final private byte [] base64Alphabet = new byte[BASELENGTH]; |
||||||
|
static final private char [] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; |
||||||
|
|
||||||
|
static { |
||||||
|
|
||||||
|
for (int i = 0; i < BASELENGTH; ++i) { |
||||||
|
base64Alphabet[i] = -1; |
||||||
|
} |
||||||
|
for (int i = 'Z'; i >= 'A'; i--) { |
||||||
|
base64Alphabet[i] = (byte) (i-'A'); |
||||||
|
} |
||||||
|
for (int i = 'z'; i>= 'a'; i--) { |
||||||
|
base64Alphabet[i] = (byte) ( i-'a' + 26); |
||||||
|
} |
||||||
|
|
||||||
|
for (int i = '9'; i >= '0'; i--) { |
||||||
|
base64Alphabet[i] = (byte) (i-'0' + 52); |
||||||
|
} |
||||||
|
|
||||||
|
base64Alphabet['+'] = 62; |
||||||
|
base64Alphabet['/'] = 63; |
||||||
|
|
||||||
|
for (int i = 0; i<=25; i++) |
||||||
|
lookUpBase64Alphabet[i] = (char)('A'+i); |
||||||
|
|
||||||
|
for (int i = 26, j = 0; i<=51; i++, j++) |
||||||
|
lookUpBase64Alphabet[i] = (char)('a'+ j); |
||||||
|
|
||||||
|
for (int i = 52, j = 0; i<=61; i++, j++) |
||||||
|
lookUpBase64Alphabet[i] = (char)('0' + j); |
||||||
|
lookUpBase64Alphabet[62] = (char)'+'; |
||||||
|
lookUpBase64Alphabet[63] = (char)'/'; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
protected static boolean isWhiteSpace(char octect) { |
||||||
|
return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); |
||||||
|
} |
||||||
|
|
||||||
|
protected static boolean isPad(char octect) { |
||||||
|
return (octect == PAD); |
||||||
|
} |
||||||
|
|
||||||
|
protected static boolean isData(char octect) { |
||||||
|
return (octect < BASELENGTH && base64Alphabet[octect] != -1); |
||||||
|
} |
||||||
|
|
||||||
|
protected static boolean isBase64(char octect) { |
||||||
|
return (isWhiteSpace(octect) || isPad(octect) || isData(octect)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Encodes hex octects into Base64 |
||||||
|
* |
||||||
|
* @param binaryData Array containing binaryData |
||||||
|
* @return Encoded Base64 array |
||||||
|
*/ |
||||||
|
public static String encode(byte[] binaryData) { |
||||||
|
|
||||||
|
if (binaryData == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
int lengthDataBits = binaryData.length*EIGHTBIT; |
||||||
|
if (lengthDataBits == 0) { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
int fewerThan24bits = lengthDataBits%TWENTYFOURBITGROUP; |
||||||
|
int numberTriplets = lengthDataBits/TWENTYFOURBITGROUP; |
||||||
|
int numberQuartet = fewerThan24bits != 0 ? numberTriplets+1 : numberTriplets; |
||||||
|
char encodedData[] = null; |
||||||
|
|
||||||
|
encodedData = new char[numberQuartet*4]; |
||||||
|
|
||||||
|
byte k=0, l=0, b1=0,b2=0,b3=0; |
||||||
|
|
||||||
|
int encodedIndex = 0; |
||||||
|
int dataIndex = 0; |
||||||
|
if (fDebug) { |
||||||
|
System.out.println("number of triplets = " + numberTriplets ); |
||||||
|
} |
||||||
|
|
||||||
|
for (int i=0; i<numberTriplets; i++) { |
||||||
|
b1 = binaryData[dataIndex++]; |
||||||
|
b2 = binaryData[dataIndex++]; |
||||||
|
b3 = binaryData[dataIndex++]; |
||||||
|
|
||||||
|
if (fDebug) { |
||||||
|
System.out.println( "b1= " + b1 +", b2= " + b2 + ", b3= " + b3 ); |
||||||
|
} |
||||||
|
|
||||||
|
l = (byte)(b2 & 0x0f); |
||||||
|
k = (byte)(b1 & 0x03); |
||||||
|
|
||||||
|
byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0); |
||||||
|
|
||||||
|
byte val2 = ((b2 & SIGN)==0)?(byte)(b2>>4):(byte)((b2)>>4^0xf0); |
||||||
|
byte val3 = ((b3 & SIGN)==0)?(byte)(b3>>6):(byte)((b3)>>6^0xfc); |
||||||
|
|
||||||
|
if (fDebug) { |
||||||
|
System.out.println( "val2 = " + val2 ); |
||||||
|
System.out.println( "k4 = " + (k<<4)); |
||||||
|
System.out.println( "vak = " + (val2 | (k<<4))); |
||||||
|
} |
||||||
|
|
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ]; |
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ val2 | ( k<<4 )]; |
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ (l <<2 ) | val3 ]; |
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ b3 & 0x3f ]; |
||||||
|
} |
||||||
|
|
||||||
|
// form integral number of 6-bit groups
|
||||||
|
if (fewerThan24bits == EIGHTBIT) { |
||||||
|
b1 = binaryData[dataIndex]; |
||||||
|
k = (byte) ( b1 &0x03 ); |
||||||
|
if (fDebug) { |
||||||
|
System.out.println("b1=" + b1); |
||||||
|
System.out.println("b1<<2 = " + (b1>>2) ); |
||||||
|
} |
||||||
|
byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0); |
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ]; |
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ k<<4 ]; |
||||||
|
encodedData[encodedIndex++] = PAD; |
||||||
|
encodedData[encodedIndex++] = PAD; |
||||||
|
} else if (fewerThan24bits == SIXTEENBIT) { |
||||||
|
b1 = binaryData[dataIndex]; |
||||||
|
b2 = binaryData[dataIndex +1 ]; |
||||||
|
l = ( byte ) ( b2 &0x0f ); |
||||||
|
k = ( byte ) ( b1 &0x03 ); |
||||||
|
|
||||||
|
byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0); |
||||||
|
byte val2 = ((b2 & SIGN)==0)?(byte)(b2>>4):(byte)((b2)>>4^0xf0); |
||||||
|
|
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ]; |
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ val2 | ( k<<4 )]; |
||||||
|
encodedData[encodedIndex++] = lookUpBase64Alphabet[ l<<2 ]; |
||||||
|
encodedData[encodedIndex++] = PAD; |
||||||
|
} |
||||||
|
|
||||||
|
return new String(encodedData); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Decodes Base64 data into octects |
||||||
|
* |
||||||
|
* @param encoded string containing Base64 data |
||||||
|
* @return Array containind decoded data. |
||||||
|
*/ |
||||||
|
public static byte[] decode(String encoded) { |
||||||
|
|
||||||
|
if (encoded == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
char[] base64Data = encoded.toCharArray(); |
||||||
|
// remove white spaces
|
||||||
|
int len = removeWhiteSpace(base64Data); |
||||||
|
|
||||||
|
if (len%FOURBYTE != 0) { |
||||||
|
return null;//should be divisible by four
|
||||||
|
} |
||||||
|
|
||||||
|
int numberQuadruple = (len/FOURBYTE ); |
||||||
|
|
||||||
|
if (numberQuadruple == 0) |
||||||
|
return new byte[0]; |
||||||
|
|
||||||
|
byte decodedData[] = null; |
||||||
|
byte b1=0,b2=0,b3=0,b4=0; |
||||||
|
char d1=0,d2=0,d3=0,d4=0; |
||||||
|
|
||||||
|
int i = 0; |
||||||
|
int encodedIndex = 0; |
||||||
|
int dataIndex = 0; |
||||||
|
decodedData = new byte[ (numberQuadruple)*3]; |
||||||
|
|
||||||
|
for (; i<numberQuadruple-1; i++) { |
||||||
|
|
||||||
|
if (!isData( (d1 = base64Data[dataIndex++]) )|| |
||||||
|
!isData( (d2 = base64Data[dataIndex++]) )|| |
||||||
|
!isData( (d3 = base64Data[dataIndex++]) )|| |
||||||
|
!isData( (d4 = base64Data[dataIndex++]) )) |
||||||
|
return null;//if found "no data" just return null
|
||||||
|
|
||||||
|
b1 = base64Alphabet[d1]; |
||||||
|
b2 = base64Alphabet[d2]; |
||||||
|
b3 = base64Alphabet[d3]; |
||||||
|
b4 = base64Alphabet[d4]; |
||||||
|
|
||||||
|
decodedData[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ) ; |
||||||
|
decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); |
||||||
|
decodedData[encodedIndex++] = (byte)( b3<<6 | b4 ); |
||||||
|
} |
||||||
|
|
||||||
|
if (!isData( (d1 = base64Data[dataIndex++]) ) || |
||||||
|
!isData( (d2 = base64Data[dataIndex++]) )) { |
||||||
|
return null;//if found "no data" just return null
|
||||||
|
} |
||||||
|
|
||||||
|
b1 = base64Alphabet[d1]; |
||||||
|
b2 = base64Alphabet[d2]; |
||||||
|
|
||||||
|
d3 = base64Data[dataIndex++]; |
||||||
|
d4 = base64Data[dataIndex++]; |
||||||
|
if (!isData( (d3 ) ) || |
||||||
|
!isData( (d4 ) )) {//Check if they are PAD characters
|
||||||
|
if (isPad( d3 ) && isPad( d4)) { //Two PAD e.g. 3c[Pad][Pad]
|
||||||
|
if ((b2 & 0xf) != 0)//last 4 bits should be zero
|
||||||
|
return null; |
||||||
|
byte[] tmp = new byte[ i*3 + 1 ]; |
||||||
|
System.arraycopy( decodedData, 0, tmp, 0, i*3 ); |
||||||
|
tmp[encodedIndex] = (byte)( b1 <<2 | b2>>4 ) ; |
||||||
|
return tmp; |
||||||
|
} else if (!isPad( d3) && isPad(d4)) { //One PAD e.g. 3cQ[Pad]
|
||||||
|
b3 = base64Alphabet[ d3 ]; |
||||||
|
if ((b3 & 0x3 ) != 0)//last 2 bits should be zero
|
||||||
|
return null; |
||||||
|
byte[] tmp = new byte[ i*3 + 2 ]; |
||||||
|
System.arraycopy( decodedData, 0, tmp, 0, i*3 ); |
||||||
|
tmp[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ); |
||||||
|
tmp[encodedIndex] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); |
||||||
|
return tmp; |
||||||
|
} else { |
||||||
|
return null;//an error like "3c[Pad]r", "3cdX", "3cXd", "3cXX" where X is non data
|
||||||
|
} |
||||||
|
} else { //No PAD e.g 3cQl
|
||||||
|
b3 = base64Alphabet[ d3 ]; |
||||||
|
b4 = base64Alphabet[ d4 ]; |
||||||
|
decodedData[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ) ; |
||||||
|
decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); |
||||||
|
decodedData[encodedIndex++] = (byte)( b3<<6 | b4 ); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
return decodedData; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* remove WhiteSpace from MIME containing encoded Base64 data. |
||||||
|
* |
||||||
|
* @param data the byte array of base64 data (with WS) |
||||||
|
* @return the new length |
||||||
|
*/ |
||||||
|
protected static int removeWhiteSpace(char[] data) { |
||||||
|
if (data == null) |
||||||
|
return 0; |
||||||
|
|
||||||
|
// count characters that's not whitespace
|
||||||
|
int newSize = 0; |
||||||
|
int len = data.length; |
||||||
|
for (int i = 0; i < len; i++) { |
||||||
|
if (!isWhiteSpace(data[i])) |
||||||
|
data[newSize++] = data[i]; |
||||||
|
} |
||||||
|
return newSize; |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,228 @@ |
|||||||
|
package com.dxhy.erp.utils; |
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils; |
||||||
|
import org.apache.commons.lang.StringUtils; |
||||||
|
import org.apache.http.HttpEntity; |
||||||
|
import org.apache.http.HttpResponse; |
||||||
|
import org.apache.http.client.HttpClient; |
||||||
|
import org.apache.http.client.config.RequestConfig; |
||||||
|
import org.apache.http.client.config.RequestConfig.Builder; |
||||||
|
import org.apache.http.client.methods.HttpGet; |
||||||
|
import org.apache.http.client.methods.HttpPost; |
||||||
|
import org.apache.http.conn.ConnectTimeoutException; |
||||||
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
||||||
|
import org.apache.http.conn.ssl.SSLContextBuilder; |
||||||
|
import org.apache.http.conn.ssl.TrustStrategy; |
||||||
|
import org.apache.http.conn.ssl.X509HostnameVerifier; |
||||||
|
import org.apache.http.entity.ContentType; |
||||||
|
import org.apache.http.entity.StringEntity; |
||||||
|
import org.apache.http.impl.client.CloseableHttpClient; |
||||||
|
import org.apache.http.impl.client.HttpClients; |
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext; |
||||||
|
import javax.net.ssl.SSLException; |
||||||
|
import javax.net.ssl.SSLSession; |
||||||
|
import javax.net.ssl.SSLSocket; |
||||||
|
import java.io.IOException; |
||||||
|
import java.net.SocketTimeoutException; |
||||||
|
import java.security.GeneralSecurityException; |
||||||
|
import java.security.cert.CertificateException; |
||||||
|
import java.security.cert.X509Certificate; |
||||||
|
|
||||||
|
public class HttpClientUtils { |
||||||
|
|
||||||
|
public static final int connTimeout = 10000; |
||||||
|
public static final int readTimeout = 10000; |
||||||
|
public static final String charset = "UTF-8"; |
||||||
|
private static HttpClient client = null; |
||||||
|
|
||||||
|
static { |
||||||
|
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); |
||||||
|
cm.setMaxTotal(1000); |
||||||
|
cm.setDefaultMaxPerRoute(500); |
||||||
|
client = HttpClients.custom().setConnectionManager(cm).build(); |
||||||
|
} |
||||||
|
|
||||||
|
public static String postParameters(String url, String parameterStr) throws ConnectTimeoutException, SocketTimeoutException, Exception { |
||||||
|
return post(url, parameterStr, "application/json", charset, connTimeout, readTimeout); |
||||||
|
} |
||||||
|
|
||||||
|
public static String get(String url) throws Exception { |
||||||
|
return get(url, charset, null, null); |
||||||
|
} |
||||||
|
|
||||||
|
public static String get(String url, String charset) throws Exception { |
||||||
|
return get(url, charset, connTimeout, readTimeout); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 发送一个 Post 请求, 使用指定的字符集编码. |
||||||
|
* |
||||||
|
* @param url |
||||||
|
* @param body RequestBody |
||||||
|
* @param mimeType 例如 application/xml "application/x-www-form-urlencoded" a=1&b=2&c=3 |
||||||
|
* @param charset 编码 |
||||||
|
* @param connTimeout 建立链接超时时间,毫秒. |
||||||
|
* @param readTimeout 响应超时时间,毫秒. |
||||||
|
* @return ResponseBody, 使用指定的字符集编码. |
||||||
|
* @throws ConnectTimeoutException 建立链接超时异常 |
||||||
|
* @throws SocketTimeoutException 响应超时 |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static String post(String url, String body, String mimeType, String charset, Integer connTimeout, Integer readTimeout) |
||||||
|
throws ConnectTimeoutException, SocketTimeoutException, Exception { |
||||||
|
HttpClient client = null; |
||||||
|
HttpPost post = new HttpPost(url); |
||||||
|
String result = ""; |
||||||
|
try { |
||||||
|
if (StringUtils.isNotBlank(body)) { |
||||||
|
HttpEntity entity = new StringEntity(body, ContentType.create(mimeType, charset)); |
||||||
|
post.setEntity(entity); |
||||||
|
} |
||||||
|
// 设置参数
|
||||||
|
Builder customReqConf = RequestConfig.custom(); |
||||||
|
if (connTimeout != null) { |
||||||
|
customReqConf.setConnectTimeout(connTimeout); |
||||||
|
} |
||||||
|
if (readTimeout != null) { |
||||||
|
customReqConf.setSocketTimeout(readTimeout); |
||||||
|
} |
||||||
|
post.setConfig(customReqConf.build()); |
||||||
|
|
||||||
|
HttpResponse res; |
||||||
|
if (url.startsWith("https")) { |
||||||
|
// 执行 Https 请求.
|
||||||
|
client = createSSLInsecureClient(); |
||||||
|
res = client.execute(post); |
||||||
|
} else { |
||||||
|
// 执行 Http 请求.
|
||||||
|
client = HttpClientUtils.client; |
||||||
|
res = client.execute(post); |
||||||
|
} |
||||||
|
result = IOUtils.toString(res.getEntity().getContent(), charset); |
||||||
|
} finally { |
||||||
|
post.releaseConnection(); |
||||||
|
if (url.startsWith("https") && client != null && client instanceof CloseableHttpClient) { |
||||||
|
((CloseableHttpClient) client).close(); |
||||||
|
} |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 发送一个 GET 请求 |
||||||
|
* |
||||||
|
* @param url |
||||||
|
* @param charset |
||||||
|
* @param connTimeout 建立链接超时时间,毫秒. |
||||||
|
* @param readTimeout 响应超时时间,毫秒. |
||||||
|
* @return |
||||||
|
* @throws ConnectTimeoutException 建立链接超时 |
||||||
|
* @throws SocketTimeoutException 响应超时 |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static String get(String url, String charset, Integer connTimeout, Integer readTimeout) |
||||||
|
throws ConnectTimeoutException, SocketTimeoutException, Exception { |
||||||
|
|
||||||
|
HttpClient client = null; |
||||||
|
HttpGet get = new HttpGet(url); |
||||||
|
get.setHeader("Authorization", "pq8fTpZWeWv8"); |
||||||
|
String result = ""; |
||||||
|
try { |
||||||
|
// 设置参数
|
||||||
|
Builder customReqConf = RequestConfig.custom(); |
||||||
|
if (connTimeout != null) { |
||||||
|
customReqConf.setConnectTimeout(connTimeout); |
||||||
|
} |
||||||
|
if (readTimeout != null) { |
||||||
|
customReqConf.setSocketTimeout(readTimeout); |
||||||
|
} |
||||||
|
get.setConfig(customReqConf.build()); |
||||||
|
|
||||||
|
HttpResponse res = null; |
||||||
|
|
||||||
|
if (url.startsWith("https")) { |
||||||
|
// 执行 Https 请求.
|
||||||
|
client = createSSLInsecureClient(); |
||||||
|
res = client.execute(get); |
||||||
|
} else { |
||||||
|
// 执行 Http 请求.
|
||||||
|
client = HttpClientUtils.client; |
||||||
|
res = client.execute(get); |
||||||
|
} |
||||||
|
|
||||||
|
result = IOUtils.toString(res.getEntity().getContent(), charset); |
||||||
|
} finally { |
||||||
|
get.releaseConnection(); |
||||||
|
if (url.startsWith("https") && client != null && client instanceof CloseableHttpClient) { |
||||||
|
((CloseableHttpClient) client).close(); |
||||||
|
} |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 从 response 里获取 charset |
||||||
|
* |
||||||
|
* @param ressponse |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@SuppressWarnings("unused") |
||||||
|
private static String getCharsetFromResponse(HttpResponse ressponse) { |
||||||
|
// Content-Type:text/html; charset=GBK
|
||||||
|
if (ressponse.getEntity() != null && ressponse.getEntity().getContentType() != null && ressponse.getEntity().getContentType().getValue() != null) { |
||||||
|
String contentType = ressponse.getEntity().getContentType().getValue(); |
||||||
|
if (contentType.contains("charset=")) { |
||||||
|
return contentType.substring(contentType.indexOf("charset=") + 8); |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建 SSL连接 |
||||||
|
* |
||||||
|
* @return |
||||||
|
* @throws GeneralSecurityException |
||||||
|
*/ |
||||||
|
private static CloseableHttpClient createSSLInsecureClient() throws GeneralSecurityException { |
||||||
|
try { |
||||||
|
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { |
||||||
|
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
||||||
|
return true; |
||||||
|
} |
||||||
|
}).build(); |
||||||
|
|
||||||
|
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean verify(String arg0, SSLSession arg1) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void verify(String host, SSLSocket ssl) |
||||||
|
throws IOException { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void verify(String host, X509Certificate cert) |
||||||
|
throws SSLException { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void verify(String host, String[] cns, |
||||||
|
String[] subjectAlts) throws SSLException { |
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
return HttpClients.custom().setSSLSocketFactory(sslsf).build(); |
||||||
|
|
||||||
|
} catch (GeneralSecurityException e) { |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package com.dxhy.erp.utils; |
||||||
|
|
||||||
|
import com.dxhy.erp.entity.kfpt.ApiCheckInvoiceSingleRequest; |
||||||
|
import com.dxhy.erp.entity.kfpt.ApiResponse; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
public class IcpUtils { |
||||||
|
|
||||||
|
@Value("${params.api.invoiceCheckSingleUrl}") |
||||||
|
private String invoiceCheckSingleUrl; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ApiUtils apiUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* 调用开放平台单张发票查验 |
||||||
|
* |
||||||
|
* @param requestId |
||||||
|
* @param singleInvoiceRequest |
||||||
|
* @param taxpayerId |
||||||
|
* @return InvoiceCheckResponse |
||||||
|
*/ |
||||||
|
public ApiResponse callSingleCheck(String requestId, ApiCheckInvoiceSingleRequest singleInvoiceRequest, String taxpayerId, String access_token) { |
||||||
|
ApiResponse apiResponse = apiUtils.callApi(invoiceCheckSingleUrl, taxpayerId, singleInvoiceRequest, access_token, requestId); |
||||||
|
return apiResponse; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,18 +0,0 @@ |
|||||||
package com.dxhy.erp.utils; |
|
||||||
|
|
||||||
import java.util.regex.Matcher; |
|
||||||
import java.util.regex.Pattern; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author dxhy |
|
||||||
*/ |
|
||||||
public class IpUtil { |
|
||||||
|
|
||||||
/** * 判断是否为合法IP * @return the ip */ |
|
||||||
public static boolean isboolIp(String ipAddress) { |
|
||||||
String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}"; |
|
||||||
Pattern pattern = Pattern.compile(ip); |
|
||||||
Matcher matcher = pattern.matcher(ipAddress); |
|
||||||
return matcher.matches(); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue