远程调用默认请求头不编码,处理微信支付返现的问题
This commit is contained in:
parent
ad4de70242
commit
10929370db
@ -15,6 +15,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class PayProperties {
|
||||
|
||||
private Boolean active;
|
||||
private String apiUrl;
|
||||
private Boolean produce;
|
||||
private String mchid;
|
||||
private String certificatePath;
|
||||
@ -30,6 +31,14 @@ public class PayProperties {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public String getApiUrl() {
|
||||
return apiUrl == null ? "" : apiUrl.trim();
|
||||
}
|
||||
|
||||
public void setApiUrl(String apiUrl) {
|
||||
this.apiUrl = apiUrl;
|
||||
}
|
||||
|
||||
public Boolean getProduce() {
|
||||
return produce;
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package ink.wgink.common.config;
|
||||
|
||||
import ink.wgink.properties.FileProperties;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
@ -18,6 +21,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/").setViewName("forward:/index");
|
||||
@ -25,6 +31,11 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// 上传文件的直接访问地址
|
||||
if (!StringUtils.isBlank(fileProperties.getUploadPath())) {
|
||||
registry.addResourceHandler("/upload-files/**").addResourceLocations("file:" + fileProperties.getUploadPath());
|
||||
}
|
||||
// 静态资源
|
||||
registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/static/assets/").setCachePeriod(7 * 24 * 3600);
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private Map<String, String> getHeaderVariableParams(Parameter[] parameters, Object[] args) throws UnsupportedEncodingException {
|
||||
private Map<String, String> getHeaderVariableParams(Parameter[] parameters, Object[] args) {
|
||||
Map<String, String> headerVariableParamsMap = new HashMap<>();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
Parameter parameter = parameters[i];
|
||||
@ -224,7 +224,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
||||
if (arg == null) {
|
||||
continue;
|
||||
}
|
||||
headerVariableParamsMap.put(variableName, URLEncoder.encode(arg.toString(), "UTF-8"));
|
||||
headerVariableParamsMap.put(variableName, arg.toString());
|
||||
}
|
||||
return headerVariableParamsMap;
|
||||
}
|
||||
|
@ -156,6 +156,7 @@ public class RestRemoteRequest {
|
||||
* @return
|
||||
*/
|
||||
private HttpEntity<String> getHttpEntity(Map<String, String> headerMap, MultiValueMap<String, Object> formVariableParams, Object jsonBody) {
|
||||
LOG.debug("Request Header: {}", headerMap);
|
||||
HttpEntity<String> httpEntity;
|
||||
if (jsonBody != null) {
|
||||
HttpHeaders httpHeaders = getHttpHeaders(headerMap);
|
||||
|
@ -1,12 +1,10 @@
|
||||
package ink.wgink.module.wechat.remote.pay.v3;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.annotation.rpc.rest.RemoteService;
|
||||
import ink.wgink.annotation.rpc.rest.method.RemoteGetMethod;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteHeaderParams;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteServerParams;
|
||||
import ink.wgink.module.wechat.pojo.pay.v3.certificates.Certificate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: IPayRemoteService
|
||||
@ -22,8 +20,8 @@ public interface IPayRemoteService {
|
||||
String HEADER_WECHATPAY_SERIAL = "Wechatpay-Serial";
|
||||
|
||||
@RemoteGetMethod("/v3/certificates")
|
||||
List<Certificate> listCertificates(@RemoteServerParams String server,
|
||||
@RemoteHeaderParams(HEADER_AUTHORIZATION) String authorization,
|
||||
@RemoteHeaderParams("serialNumber") String serialNumber);
|
||||
JSONObject getCertificates(@RemoteServerParams String server,
|
||||
@RemoteHeaderParams(HEADER_AUTHORIZATION) String authorization,
|
||||
@RemoteHeaderParams(HEADER_WECHATPAY_SERIAL) String serialNumber);
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import java.security.cert.X509Certificate;
|
||||
*/
|
||||
public class BasePayService extends DefaultBaseService {
|
||||
|
||||
public static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com";
|
||||
public static final String PAY_SANDBOXNEW = "sandboxnew";
|
||||
|
||||
@Autowired
|
||||
@ -58,9 +57,9 @@ public class BasePayService extends DefaultBaseService {
|
||||
}
|
||||
if (!payProperties.getProduce()) {
|
||||
// 沙河环境
|
||||
return PAY_BASE_URL + "/" + PAY_SANDBOXNEW;
|
||||
return payProperties.getApiUrl() + "/" + PAY_SANDBOXNEW;
|
||||
}
|
||||
return PAY_BASE_URL;
|
||||
return payProperties.getApiUrl();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ink.wgink.module.wechat.service.pay.v3.certificates.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.module.wechat.enums.PayAuthorizationTypeEnum;
|
||||
import ink.wgink.module.wechat.pojo.pay.v3.certificates.Certificate;
|
||||
@ -38,8 +39,8 @@ public class CertificateServiceImpl extends BasePayService implements ICertifica
|
||||
LOG.debug("获得证书序列号");
|
||||
String serialNumber = getSerialNumber();
|
||||
String authorization = getAuthorization(RequestMethod.GET, urlSuffix, serialNumber, payProperties, "", PayAuthorizationTypeEnum.WECHATPAY2_SHA256_RSA2048);
|
||||
List<Certificate> certificates = payRemoteService.listCertificates(getPayBaseUrl(), authorization, serialNumber);
|
||||
|
||||
JSONObject resultJsonObject = payRemoteService.getCertificates(getPayBaseUrl(), authorization, serialNumber);
|
||||
List<Certificate> certificates = resultJsonObject.getJSONArray("data").toJavaList(Certificate.class);
|
||||
LOG.debug("获取最新的平台证书");
|
||||
Certificate newestCertificate = certificates.get(certificates.size() - 1);
|
||||
LOG.debug("解析密文");
|
||||
|
Loading…
Reference in New Issue
Block a user