package cn.com.taiji.ats.manager; | package cn.com.taiji.ats.manager; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.concurrent.Callable; | |||||
import java.time.LocalDateTime; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import org.apache.http.NoHttpResponseException; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.web.context.request.RequestContextHolder; | |||||
import org.springframework.web.context.request.ServletRequestAttributes; | |||||
import com.netflix.client.ClientException; | |||||
import cn.com.taiji.common.manager.AbstractManager; | |||||
import cn.com.taiji.common.manager.ManagerException; | import cn.com.taiji.common.manager.ManagerException; | ||||
import cn.com.taiji.common.manager.function.ExceptionBiConsumer; | |||||
import cn.com.taiji.common.manager.function.ExceptionFunction; | |||||
import cn.com.taiji.common.manager.net.http.binclient.ApiRequestException; | |||||
import cn.com.taiji.common.model.BaseModel; | import cn.com.taiji.common.model.BaseModel; | ||||
import cn.com.taiji.common.model.file.FileProtocolSystemError; | import cn.com.taiji.common.model.file.FileProtocolSystemError; | ||||
import cn.com.taiji.common.pub.json.JsonTools; | import cn.com.taiji.common.pub.json.JsonTools; | ||||
import cn.com.taiji.common.web.util.WebTools; | import cn.com.taiji.common.web.util.WebTools; | ||||
import cn.com.taiji.core.manager.comm.client.IOFunction; | import cn.com.taiji.core.manager.comm.client.IOFunction; | ||||
import cn.com.taiji.core.manager.comm.client.feign.FeignClientManager; | |||||
import cn.com.taiji.core.model.comm.protocol.*; | import cn.com.taiji.core.model.comm.protocol.*; | ||||
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | ||||
import com.netflix.client.ClientException; | |||||
import feign.RetryableException; | import feign.RetryableException; | ||||
import org.apache.http.NoHttpResponseException; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import cn.com.taiji.common.manager.AbstractManager; | |||||
import cn.com.taiji.common.manager.net.http.binclient.ApiRequestException; | |||||
import cn.com.taiji.core.manager.comm.client.feign.FeignClientManager; | |||||
import org.springframework.web.context.request.RequestContextHolder; | |||||
import org.springframework.web.context.request.ServletRequestAttributes; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
@Service | |||||
public abstract class AbstractCommManager extends AbstractManager { | public abstract class AbstractCommManager extends AbstractManager { | ||||
public static LocalDateTime TIME1990 = LocalDateTime.parse("1990-01-01T00:00:00"); | |||||
@Autowired | @Autowired | ||||
protected FeignClientManager feignClientManager; | protected FeignClientManager feignClientManager; | ||||
/** | |||||
* <pre> | |||||
* 重复3次提交请求,会将调接口错误的响应转换成前端的响应 | |||||
* </pre> | |||||
*/ | |||||
public <RS extends AbstractSignTypeResponse> RS jsonPostRepeat(AbstractSignTypeRequest<RS> req, String ifCode, | |||||
String accessToken) throws ManagerException { | |||||
return convertException(req, ifCode, r -> jsonPostRepeat(r, 3, ifCode, accessToken)); | |||||
} | |||||
/** | |||||
* <pre> | |||||
* 重复3次提交请求,会将调接口错误的响应转换成前端的响应 | |||||
* </pre> | |||||
*/ | |||||
public <RS extends AbstractSignTypeResponse> RS jsonPostRepeat(AbstractSignTypeRequest<RS> req) | |||||
throws ManagerException { | |||||
return convertException(req, req.getServiceCommand().getIfCode(), r -> jsonPostRepeat(r, 3, null, null)); | |||||
} | |||||
/** | |||||
* <pre> | |||||
* 重复3次提交请求,会将调接口错误的响应转换成前端的响应 | |||||
* </pre> | |||||
*/ | |||||
public <RS> RS jsonPostRepeat(AbstractOldSystemRequest<RS> req, String accessToken) throws ManagerException { | |||||
return convertException(req, req.getIfCode(), r -> jsonPostOldSystemRepeat(r, 3, accessToken)); | |||||
} | |||||
/** | |||||
* 把异常吃掉的方法 | |||||
*/ | |||||
protected <V, E extends Exception> V doRepeatSafe(ExceptionFunction<Integer, V, E> call, int repeat, | |||||
ExceptionBiConsumer<Integer, Exception, E> exceptionHandler) { | |||||
int i = 0; | |||||
while (i < repeat) { | |||||
try { | |||||
return call.apply(i); | |||||
} catch (Exception e) { | |||||
logger.error("第{}次执行Exception:{}", i + 1, e.getMessage()); | |||||
logger.warn("", e); | |||||
if (exceptionHandler != null) { | |||||
try { | |||||
exceptionHandler.accept(i, e); | |||||
} catch (Exception var6) { | |||||
logger.error("", e); | |||||
} | |||||
} | |||||
++i; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 重复提交业务请求 | * 重复提交业务请求 | ||||
* 1、IO异常重试请求,如果一直IO异常返回null | |||||
* 1、IO异常重试请求,如果多次IO错误抛出异常 | |||||
* 2、ApiRequestException 707返回new 创建的response | * 2、ApiRequestException 707返回new 创建的response | ||||
* 3、ApiRequestException 其它错误抛异常 | * 3、ApiRequestException 其它错误抛异常 | ||||
* </pre> | * </pre> | ||||
*/ | */ | ||||
public <RS extends AbstractSignTypeResponse> RS jsonPostRepeat(AbstractSignTypeRequest<RS> req, int repeat) { | |||||
private <RS extends AbstractSignTypeResponse> RS jsonPostRepeat(AbstractSignTypeRequest<RS> req, int repeat, | |||||
String ifCode, String accessToken) throws IOException { | |||||
for (int i = 0; i < repeat; i++) { | for (int i = 0; i < repeat; i++) { | ||||
try { | try { | ||||
return jsonPost(req); | |||||
return feignClientManager.jsonPost(req, req.getResponseType(), ifCode, accessToken); | |||||
} catch (NoHttpResponseException e) { | |||||
logger.error("第 {} NoHttpResponseException:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
logger.error("第 {} 次执行Exception:{}", i + 1, e.getMessage()); | logger.error("第 {} 次执行Exception:{}", i + 1, e.getMessage()); | ||||
// if (logManager != null) { | |||||
// logManager.addConsoleLog(FeeBusinessType.EXCEPTION, req.getFilename(), "error", e.getMessage()); | |||||
// } | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (ApiRequestException e) { | } catch (ApiRequestException e) { | ||||
if (e.getErrCode() == 707) { | if (e.getErrCode() == 707) { | ||||
// 707压住异常 | // 707压住异常 | ||||
return null; | return null; | ||||
} | } | ||||
public <RS extends AbstractSignTypeResponse> RS jsonPost(AbstractSignTypeRequest<RS> req) throws IOException { | |||||
Class<RS> clazz = req.getResponseType(); | |||||
return feignClientManager.jsonPost(req, clazz); | |||||
private <RE extends AbstractOldSystemRequest<RS>, RS> RS jsonPostOldSystemRepeat(RE req, int repeat, | |||||
String accessToken) throws IOException { | |||||
for (int i = 0; i < repeat; i++) { | |||||
try { | |||||
return feignClientManager.jsonPost(req, accessToken); | |||||
} catch (NoHttpResponseException e) { | |||||
logger.error("第 {} NoHttpResponseException:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (IOException e) { | |||||
logger.error("第 {} 次执行Exception:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (ApiRequestException e) { | |||||
logger.error("第 {} 次执行ApiRequestException:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} | |||||
} | |||||
return null; | |||||
} | } | ||||
@Deprecated | @Deprecated | ||||
public <RS> RS jsonPostRepeat(AbstractReqIdTypeRequest req, Class<RS> clazz, String ifCode, String accessToken) | |||||
throws ManagerException { | |||||
return convertException(req, ifCode, r -> jsonPostReqIdRepeat(r, clazz, 3, ifCode, accessToken)); | |||||
} | |||||
/** | |||||
* <pre> | |||||
* 重复3次提交请求,会将调接口错误的响应转换成前端的响应 | |||||
* </pre> | |||||
*/ | |||||
public <RS> RS jsonPostRepeat(AbstractOldSystemRequest<RS> req, String accessToken) throws ManagerException { | |||||
return convertException(req, req.getIfCode(), r -> jsonPostOldSystemRepeat(r, 3, accessToken)); | |||||
} | |||||
/** | |||||
* 当不想自己捕获异常时、当你不对异常做什么处理时可调用该方法 | |||||
* | |||||
* @param businessId | |||||
* 业务id | |||||
*/ | |||||
public <V> V doSafe(Callable<V> call, String businessId) { | |||||
try { | |||||
return call.call(); | |||||
} catch (Exception e) { | |||||
logger.error("", e); | |||||
// if (logManager != null) { | |||||
// logManager.addConsoleLog(FeeBusinessType.EXCEPTION, businessId, "error", e.getMessage()); | |||||
// } | |||||
return null; | |||||
private <RE extends AbstractReqIdTypeRequest, RS> RS jsonPostReqIdRepeat(RE req, Class<RS> clazz, int repeat, | |||||
String ifCode, String accessToken) throws IOException { | |||||
for (int i = 0; i < repeat; i++) { | |||||
try { | |||||
return feignClientManager.jsonPost(req, clazz, ifCode, accessToken); | |||||
} catch (NoHttpResponseException e) { | |||||
logger.error("第 {} NoHttpResponseException:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (IOException e) { | |||||
logger.error("第 {} 次执行Exception:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (ApiRequestException e) { | |||||
if (e.getErrCode() == 707) { | |||||
// 707压住异常 | |||||
try { | |||||
return clazz.getDeclaredConstructor().newInstance(); | |||||
} catch (Exception ex) { | |||||
throw new RuntimeException(ex); | |||||
} | |||||
} | |||||
throw e; | |||||
} | |||||
} | } | ||||
return null; | |||||
} | } | ||||
/** | /** | ||||
} | } | ||||
} | } | ||||
private <RE extends AbstractOldSystemRequest<RS>, RS> RS jsonPostOldSystemRepeat(RE req, int repeat, | |||||
String accessToken) throws IOException { | |||||
for (int i = 0; i < repeat; i++) { | |||||
try { | |||||
return feignClientManager.jsonPost(req, accessToken); | |||||
} catch (NoHttpResponseException e) { | |||||
logger.error("第 {} NoHttpResponseException:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (IOException e) { | |||||
logger.error("第 {} 次执行Exception:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (ApiRequestException e) { | |||||
logger.error("第 {} 次执行ApiRequestException:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
private int location = -1; | private int location = -1; | ||||
private void convertApiRequestException(ApiRequestException e, String ifCode) throws ManagerException { | private void convertApiRequestException(ApiRequestException e, String ifCode) throws ManagerException { | ||||
String uri = getRequestUri(); | |||||
logger.info("调用接口Api业务失败,Controller的url:{}", uri); | |||||
StackTraceElement[] stackTrace = e.getStackTrace(); | StackTraceElement[] stackTrace = e.getStackTrace(); | ||||
if (stackTrace != null) { | if (stackTrace != null) { | ||||
if (location == -1) { | if (location == -1) { | ||||
throw new ManagerException("未知错误:" + jsonRes.getErrorMsg()); | throw new ManagerException("未知错误:" + jsonRes.getErrorMsg()); | ||||
} | } | ||||
private String getRequestUri() { | |||||
try { | |||||
ServletRequestAttributes requestAttributes = | |||||
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | |||||
assert requestAttributes != null; | |||||
HttpServletRequest request = requestAttributes.getRequest(); | |||||
return WebTools.getUri(request); | |||||
} catch (Exception e) { | |||||
return ""; | |||||
} | |||||
} | |||||
private int getMethodLocation(StackTraceElement[] stackTrace) { | private int getMethodLocation(StackTraceElement[] stackTrace) { | ||||
for (int i = 0; i < stackTrace.length; i++) { | for (int i = 0; i < stackTrace.length; i++) { | ||||
if (!stackTrace[i].getClassName().contains("AbstractCommManager") | if (!stackTrace[i].getClassName().contains("AbstractCommManager") | ||||
} | } | ||||
return -1; | return -1; | ||||
} | } | ||||
private SignJsonResponse toJsonResponse(ApiRequestException e) { | private SignJsonResponse toJsonResponse(ApiRequestException e) { | ||||
String responseJson = e.getMessage().substring(0, e.getMessage().length() - 4); | String responseJson = e.getMessage().substring(0, e.getMessage().length() - 4); | ||||
try { | try { | ||||
return null; | return null; | ||||
} | } | ||||
private <RE extends AbstractReqIdTypeRequest,RS> RS jsonPostReqIdRepeat(RE req,Class<RS> clazz, int repeat, String ifCode, String accessToken) | |||||
throws IOException { | |||||
for (int i = 0; i < repeat; i++) { | |||||
try { | |||||
return feignClientManager.jsonPost(req, clazz, ifCode, accessToken); | |||||
} catch (NoHttpResponseException e) { | |||||
logger.error("第 {} NoHttpResponseException:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (IOException e) { | |||||
logger.error("第 {} 次执行Exception:{}", i + 1, e.getMessage()); | |||||
if (i >= repeat - 1) { | |||||
throw e; | |||||
} | |||||
} catch (ApiRequestException e) { | |||||
if (e.getErrCode() == 707) { | |||||
// 707压住异常 | |||||
try { | |||||
return clazz.getDeclaredConstructor().newInstance(); | |||||
} catch (Exception ex) { | |||||
throw new RuntimeException(ex); | |||||
} | |||||
} | |||||
throw e; | |||||
} | |||||
private String getRequestUri() { | |||||
try { | |||||
ServletRequestAttributes requestAttributes = | |||||
(ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); | |||||
assert requestAttributes != null; | |||||
HttpServletRequest request = requestAttributes.getRequest(); | |||||
return WebTools.getUri(request); | |||||
} catch (Exception e) { | |||||
return ""; | |||||
} | } | ||||
return null; | |||||
} | } | ||||
} | } |
package cn.com.taiji.ats.manager.request; | |||||
import cn.com.taiji.core.model.comm.protocol.AbstractReqIdTypeRequest; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
/** | |||||
* @Author ChenChao | |||||
* @Date 2024/10/6 15:42 | |||||
* @Description | |||||
*/ | |||||
@Data | |||||
@EqualsAndHashCode(callSuper=false) | |||||
public class WxMapRequest extends AbstractReqIdTypeRequest { | |||||
private String url; | |||||
private String method; //目前支持GET、POST | |||||
private Object data; | |||||
} | |||||
//package cn.com.taiji.ats.manager.request; | |||||
// | |||||
//import cn.com.taiji.core.model.comm.protocol.AbstractReqIdTypeRequest; | |||||
//import lombok.Data; | |||||
//import lombok.EqualsAndHashCode; | |||||
// | |||||
///** | |||||
// * @Author ChenChao | |||||
// * @Date 2024/10/6 15:42 | |||||
// * @Description | |||||
// */ | |||||
//@Data | |||||
//@EqualsAndHashCode(callSuper=false) | |||||
//public class WxMapRequest extends AbstractReqIdTypeRequest { | |||||
// | |||||
// private String url; | |||||
// private String method; //目前支持GET、POST | |||||
// private Object data; | |||||
//} |
import com.alibaba.fastjson2.JSON; | import com.alibaba.fastjson2.JSON; | ||||
import cn.com.taiji.ats.manager.AbstractCommManager; | import cn.com.taiji.ats.manager.AbstractCommManager; | ||||
import cn.com.taiji.ats.manager.request.WxMapRequest; | |||||
import cn.com.taiji.common.manager.ManagerException; | import cn.com.taiji.common.manager.ManagerException; | ||||
String accessToken = wxRequestAccessTokenUtil.getStableAccessToken(mpAppid, mpSecret, false, MP_ACCESS_STABLE_TOKEN_PREFIX); | String accessToken = wxRequestAccessTokenUtil.getStableAccessToken(mpAppid, mpSecret, false, MP_ACCESS_STABLE_TOKEN_PREFIX); | ||||
//方法二、走中台的http调用接口 | //方法二、走中台的http调用接口 | ||||
// Map<String, Object> responseBody = ifztServiceManager.httpApi(requestMethod, url, postParamBody); | // Map<String, Object> responseBody = ifztServiceManager.httpApi(requestMethod, url, postParamBody); | ||||
WxMapRequest wxMapRequest = new WxMapRequest(); | |||||
wxMapRequest.setUrl(url); | |||||
wxMapRequest.setMethod(requestMethod.name()); | |||||
wxMapRequest.setData(postParamBody); | |||||
// 访问微信服务 | // 访问微信服务 | ||||
String resJson = HttpClientUtil.sendPost(url,JSON.toJSONString(postParamBody),accessToken); | String resJson = HttpClientUtil.sendPost(url,JSON.toJSONString(postParamBody),accessToken); | ||||
// Map<String, Object> responseBody = jsonPostRepeat(wxMapRequest, HashMap.class, ifztNetwork, null); | // Map<String, Object> responseBody = jsonPostRepeat(wxMapRequest, HashMap.class, ifztNetwork, null); |
//package cn.com.taiji.ats.manager.demo; | |||||
// | |||||
//import cn.com.taiji.ats.Application; | |||||
//import cn.com.taiji.ats.manager.weixin.CreatePayOrderV3Manager; | |||||
//import cn.com.taiji.ats.manager.AbstractCommManager; | |||||
//import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||||
//import cn.com.taiji.core.entity.dict.pay.TradeType; | |||||
//import cn.com.taiji.core.model.comm.protocol.ats.AtsCreatPayOrderV3Request; | |||||
//import cn.com.taiji.core.model.comm.protocol.ats.AtsCreatPayOrderV3Response; | |||||
//import org.junit.jupiter.api.Test; | |||||
//import org.springframework.beans.factory.annotation.Autowired; | |||||
//import org.springframework.boot.test.context.SpringBootTest; | |||||
//import org.springframework.boot.test.mock.mockito.MockBean; | |||||
// | |||||
//import javax.annotation.Resource; | |||||
// | |||||
//@SpringBootTest(classes = Application.class) | |||||
//public class TestFeignClientRequest extends AbstractCommManager { | |||||
// | |||||
//// @Test | |||||
//// public void testSampleRequest() { | |||||
//// TypeSampleRequest req = new TypeSampleRequest(); | |||||
//// try { | |||||
//// logger.info("格式校验异常 req:" + req.toJson(true)); | |||||
//// jsonPostRepeat(req, 3); | |||||
//// } catch (ApiRequestException e) { | |||||
//// logger.error("", e); | |||||
//// } | |||||
//// req = new TypeSampleRequest(); | |||||
//// req.setCardId("cardId" + new Random().nextInt(1000000)); | |||||
//// req.setReqStr("hello"); | |||||
//// req.setValid(true); | |||||
//// try { | |||||
//// logger.info("业务校验异常 req:" + req.toJson(true)); | |||||
//// jsonPostRepeat(req, 3); | |||||
//// } catch (ApiRequestException e) { | |||||
//// logger.error("", e); | |||||
//// } | |||||
//// req = new TypeSampleRequest(); | |||||
//// req.setCardId("cardId" + new Random().nextInt(1000000)); | |||||
//// req.setReqStr("hello"); | |||||
//// req.setValid(false); | |||||
//// logger.info("成功 req:" + req.toJson(true)); | |||||
//// TypeSampleResponse res = jsonPostRepeat(req, 1); | |||||
//// logger.info("res:" + res.toJson(true)); | |||||
//// | |||||
//// } | |||||
// @Autowired | |||||
//// @Resource | |||||
//// @MockBean | |||||
// private CreatePayOrderV3Manager createPayOrderV3Manager; | |||||
// @Test | |||||
// public void test1() { | |||||
// AtsCreatPayOrderV3Request request = new AtsCreatPayOrderV3Request(); | |||||
// request.setApiV3Key("yCocgAjiGMqQEfFE4SN4woJYSSfq07fd"); | |||||
// request.setAppid("wx008c60533388527a"); | |||||
// request.setMchid("1495316212");//1535705621 | |||||
//// request.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpU2Z2fk0yDxsj6fYuxFhuqWqZ4HsHpWcxATjjNKgge7aFdSacBZBoO5ZTeHj2zSy1Atx8A0SiJ8FjM39wJFl97C8xcvGZYnIM0xxQsZnCwEkCpYrPUvwx5Fs7gumzmvnNetV8Mux2gzmneQayfrVM8TVkRptLYOsPAupuvyZ6Ygpn8Omd+ZSUkCI9KFm5cY16Uzi9SbUc0dF46NrhujDabvf9IEn6sGaWqkCv+LMU5h2jL79KrgjpMHvvu58i4pMM4SxeV06u8x7T/CRxA+Jwj8FGNv9Og7VUylmZVyISIDwUZz5wYCsr/XEPHt26WWriqUlm0gpV1DaZrIHkkQztAgMBAAECggEAX0Unn4AM2x+Yu6pF86ZRw2HbMt0VHAY6e14erefQuQYiehCiOqL+z0bHnAtqtCJZBzem6rfEBCCuNKyjBWvOVoVvQDlWKmEznnehtN1YkDU0XyLZaTFd6Ix9sIxGBeIqryxvtcPJPB01cT8tP3z/cV0+Fz+K3OyZFQck9E7kzXI1Vc3Dcx6ZGPRmkFyfjgxV2kTQzfQasoYK6rZjQwzQuXyHhLZx3iQuk61Ta8gqJ9O+2Y93koe6i6wUfF2yHgwAGgAuDa5Twx02XtRmTzILedFyLezwaV7Xg3y5KPFzt2u8w6nHjSi7tzTFPeW+QMMzmjsPqegDAfLAK+hW3lWtgQKBgQDf0ErISiCXYCQRw7TaF9J4vlecY/PQENEO8S+1tK5TJdmfsFULT0wS9W1QrmYlq6aeMBYbGsbxy+1+dqOGrkt7ICRXJaLXpVaPW1jaOXZtDs8NR3oCkF/4ePt0X7G7CKHrkjErHhdElTi6PTtyNdRDK0xhiQG2GMueqrxG2HHsnQKBgQDBrSKvVqNgisNntZfgzwM8LYDC+NdsrCKL2GaOgyzb0J9kCcVMRdmDGqLm+R6K6W+pH6mJ9UjZFGmagrqowFxJ93uWGce2sNnhdmy9wgbEpyh3ddZIm+BVTRTUjSy8d1eoMoVPNx+dO/hgqHZS047buhf7EBgUvfVnRnsFXN+okQKBgCjn3uMgeThxf+YnSMSbmgIrd8PDmOosSKlcd4XUUhAsWMwQ5Fo+0f6dEK+wUEcOSlObIk8t47KJvQxiDp0s+eq1Ay9SV6LmOx3UajboTba9ACbDK4+QZ5n4Mq0gWFGA0GdHvujMhSApzcZsLpM/N15XaYxiCAgKHB0Rw3uHT7sZAoGAEhF25OiuQTlw1WIJkz18zcZo9seEQW0lo+pCVxVBwBgMZqbKszzo9+QqQmYHRWpVsm9zv50UeLwAxhtgEpIvie7+ppgtG4wQJ4qGxoUtYHc/vTVPEmMIYKzaPqIVBFgV42kjKqq31lFb8JiGwV9fOnx39EIiHP1Dwai/nVZ2vyECgYEAuJQyqO1QPBG70E3gAy1yQxLYce473V9mizPEAjhV/oBlIOlrT4JpvwKoCuRdOoluDtYOHJpHk3hrSoboMuCl9BIECQIt03/xfaQbJ7YQu2SNf3ADrd6A+r8286aKBXjI9X9oSfwAgXnHQftGKDLqt6OrEyCAl+gsM3/R7eKsOH0="); | |||||
// request.setTradeType(TradeType.NATIVE); | |||||
// request.setCreateType(1); | |||||
// request.setDescription("测试"); | |||||
// request.setOutTradeNo("123456789"); | |||||
// request.setNotifyUrl("https://skx.mynatapp.cc/qtucpaymgt/wxv3/notify/"); | |||||
// request.setTotal(1); | |||||
// request.setCurrency("CNY"); | |||||
// request.setOpenid("oQj1Z5QX3YLzRl5Z0JJYlXQ_1HY8"); | |||||
package cn.com.taiji.ats.manager.demo; | |||||
import cn.com.taiji.ats.Application; | |||||
import cn.com.taiji.ats.manager.AbstractCommManager; | |||||
import cn.com.taiji.ats.manager.weixin.CreatePayOrderV2Manager; | |||||
import cn.com.taiji.ats.manager.weixin.QueryPayResultV2Manager; | |||||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||||
import cn.com.taiji.core.entity.dict.pay.TradeType; | |||||
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.*; | |||||
import org.junit.jupiter.api.Test; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.boot.test.context.SpringBootTest; | |||||
@SpringBootTest(classes = Application.class) | |||||
public class TestFeignClientRequest extends AbstractCommManager { | |||||
// @Test | |||||
// public void testSampleRequest() { | |||||
// TypeSampleRequest req = new TypeSampleRequest(); | |||||
// try { | // try { | ||||
// AtsCreatPayOrderV3Response orderV3Response = createPayOrderV3Manager.serviceHandle(request); | |||||
// } catch (ServiceHandleException e) { | |||||
// | |||||
// logger.info("2313"); | |||||
// logger.info("格式校验异常 req:" + req.toJson(true)); | |||||
// jsonPostRepeat(req, 3); | |||||
// } catch (ApiRequestException e) { | |||||
// logger.error("", e); | |||||
// } | // } | ||||
// System.out.println("234567"); | |||||
// req = new TypeSampleRequest(); | |||||
// req.setCardId("cardId" + new Random().nextInt(1000000)); | |||||
// req.setReqStr("hello"); | |||||
// req.setValid(true); | |||||
// try { | |||||
// logger.info("业务校验异常 req:" + req.toJson(true)); | |||||
// jsonPostRepeat(req, 3); | |||||
// } catch (ApiRequestException e) { | |||||
// logger.error("", e); | |||||
// } | |||||
// req = new TypeSampleRequest(); | |||||
// req.setCardId("cardId" + new Random().nextInt(1000000)); | |||||
// req.setReqStr("hello"); | |||||
// req.setValid(false); | |||||
// logger.info("成功 req:" + req.toJson(true)); | |||||
// TypeSampleResponse res = jsonPostRepeat(req, 1); | |||||
// logger.info("res:" + res.toJson(true)); | |||||
// | |||||
// } | // } | ||||
//} | |||||
@Autowired | |||||
private CreatePayOrderV2Manager createPayOrderV2Manager; | |||||
@Test | |||||
public void testV2() { | |||||
AtsCreatPayOrderV2Request request = new AtsCreatPayOrderV2Request(); | |||||
request.setAppId("wx8fba957179c1329a"); | |||||
request.setMchId("1680098284"); | |||||
request.setBody("测试"); | |||||
request.setOutTradeNo("12345678910"); | |||||
request.setTotalFee(1); | |||||
request.setSpbillCreateIp("127.0.0.1"); | |||||
request.setNotifyUrl("https://skx.mynatapp.cc/qtucpaymgt/wxv3/notify/"); | |||||
request.setTradeType(TradeType.NATIVE); | |||||
request.setProductId("12345678910_20250517"); | |||||
// request.setOpenid("oQj1Z5QX3YLzRl5Z0JJYlXQ_1HY8"); | |||||
request.setMchKey("202FBA21E4B7F55BE060A8C0157A36E9"); | |||||
request.setCreateType(1); | |||||
// request.setSubAppId("wx8fba957179c1329a"); | |||||
// request.setSubMchId("1680098284"); | |||||
// request.setCreateType(2); | |||||
try { | |||||
AtsCreatPayOrderV2Response response = createPayOrderV2Manager.serviceHandle(request); | |||||
logger.info(response.toJson()); | |||||
} catch (ServiceHandleException e) { | |||||
e.printStackTrace(); | |||||
logger.error(e.getMessage()); | |||||
} | |||||
} | |||||
@Autowired | |||||
private QueryPayResultV2Manager queryPayResultV2Manager; | |||||
@Test | |||||
public void testV2Result() { | |||||
AtsQueryPayResultV2Request request = new AtsQueryPayResultV2Request(); | |||||
request.setAppId("wx8fba957179c1329a"); | |||||
request.setMchId("1680098284"); | |||||
request.setOutTradeNo("12345678910"); | |||||
// request.setOpenid("oQj1Z5QX3YLzRl5Z0JJYlXQ_1HY8"); | |||||
request.setMchKey("202FBA21E4B7F55BE060A8C0157A36E9"); | |||||
request.setCreateType(1); | |||||
// request.setSubAppId("wx8fba957179c1329a"); | |||||
// request.setSubMchId("1680098284"); | |||||
// request.setCreateType(2); | |||||
try { | |||||
AtsQueryPayResultV2Response response = queryPayResultV2Manager.serviceHandle(request); | |||||
logger.info(response.toJson()); | |||||
} catch (ServiceHandleException e) { | |||||
e.printStackTrace(); | |||||
logger.error(e.getMessage()); | |||||
} | |||||
} | |||||
} |
package cn.com.taiji.ats.manager.demo; | |||||
import cn.com.taiji.ats.Application; | |||||
import cn.com.taiji.ats.manager.AbstractCommManager; | |||||
import cn.com.taiji.common.manager.ManagerException; | |||||
import cn.com.taiji.core.entity.dict.pay.TradeType; | |||||
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.*; | |||||
import org.junit.jupiter.api.Test; | |||||
import org.springframework.boot.test.context.SpringBootTest; | |||||
/** | |||||
* @Author:ChenChao | |||||
* @Date:2025/6/6 11:36 | |||||
* @Filename:WeiXinTest | |||||
* @description: 微信测试 | |||||
*/ | |||||
@SpringBootTest(classes = Application.class) | |||||
public class WeiXinTest extends AbstractCommManager { | |||||
// CREATEPAYORDERV2("V2统一下单", "creatOrderV2", AtsCreatPayOrderV2Request.class), | |||||
@Test | |||||
public void AtsCreatPayOrderV2Request() { | |||||
AtsCreatPayOrderV2Request request = new AtsCreatPayOrderV2Request(); | |||||
request.setAppId("wx8fba957179c1329a"); | |||||
request.setMchId("1680098284"); | |||||
request.setBody("测试"); | |||||
request.setOutTradeNo("12345678911"); | |||||
request.setTotalFee(1); | |||||
request.setSpbillCreateIp("127.0.0.1"); | |||||
request.setNotifyUrl("https://skx.mynatapp.cc/qtucpaymgt/wxv3/notify/"); | |||||
request.setTradeType(TradeType.NATIVE); | |||||
request.setProductId("12345678910_20250517"); | |||||
// request.setOpenid("oQj1Z5QX3YLzRl5Z0JJYlXQ_1HY8"); | |||||
request.setMchKey("202FBA21E4B7F55BE060A8C0157A36E9"); | |||||
request.setCreateType(1); | |||||
// request.setSubAppId("wx8fba957179c1329a"); | |||||
// request.setSubMchId("1680098284"); | |||||
// request.setCreateType(2); | |||||
try { | |||||
AtsCreatPayOrderV2Response response = jsonPostRepeat(request); | |||||
logger.info("V2统一下单结果:{}", response.toJson(true)); | |||||
} catch (ManagerException e) { | |||||
logger.error("V2统一下单异常:{}", e.getMessage()); | |||||
} | |||||
} | |||||
// QUERYPAYRESULTV2("查询V2支付结果", "queryPayResultV2", AtsQueryPayResultV2Request.class), | |||||
@Test | |||||
public void AtsQueryPayResultV2Request() { | |||||
AtsQueryPayResultV2Request request = new AtsQueryPayResultV2Request(); | |||||
} | |||||
// CREATEPAYORDERV3("V3统一下单", "creatOrderV3",AtsCreatPayOrderV3Request .class), | |||||
@Test | |||||
public void AtsCreatPayOrderV3Request() { | |||||
AtsCreatPayOrderV3Request request = new AtsCreatPayOrderV3Request(); | |||||
request.setAppid("wx008c60533388527a"); | |||||
request.setApiV3Key("yCocgAjiGMqQEfFE4SN4woJYSSfq07fd"); | |||||
request.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpU2Z2fk0yDxsj6fYuxFhuqWqZ4HsHpWcxATjjNKgge7aFdSacBZBoO5ZTeHj2zSy1Atx8A0SiJ8FjM39wJFl97C8xcvGZYnIM0xxQsZnCwEkCpYrPUvwx5Fs7gumzmvnNetV8Mux2gzmneQayfrVM8TVkRptLYOsPAupuvyZ6Ygpn8Omd+ZSUkCI9KFm5cY16Uzi9SbUc0dF46NrhujDabvf9IEn6sGaWqkCv+LMU5h2jL79KrgjpMHvvu58i4pMM4SxeV06u8x7T/CRxA+Jwj8FGNv9Og7VUylmZVyISIDwUZz5wYCsr/XEPHt26WWriqUlm0gpV1DaZrIHkkQztAgMBAAECggEAX0Unn4AM2x+Yu6pF86ZRw2HbMt0VHAY6e14erefQuQYiehCiOqL+z0bHnAtqtCJZBzem6rfEBCCuNKyjBWvOVoVvQDlWKmEznnehtN1YkDU0XyLZaTFd6Ix9sIxGBeIqryxvtcPJPB01cT8tP3z/cV0+Fz+K3OyZFQck9E7kzXI1Vc3Dcx6ZGPRmkFyfjgxV2kTQzfQasoYK6rZjQwzQuXyHhLZx3iQuk61Ta8gqJ9O+2Y93koe6i6wUfF2yHgwAGgAuDa5Twx02XtRmTzILedFyLezwaV7Xg3y5KPFzt2u8w6nHjSi7tzTFPeW+QMMzmjsPqegDAfLAK+hW3lWtgQKBgQDf0ErISiCXYCQRw7TaF9J4vlecY/PQENEO8S+1tK5TJdmfsFULT0wS9W1QrmYlq6aeMBYbGsbxy+1+dqOGrkt7ICRXJaLXpVaPW1jaOXZtDs8NR3oCkF/4ePt0X7G7CKHrkjErHhdElTi6PTtyNdRDK0xhiQG2GMueqrxG2HHsnQKBgQDBrSKvVqNgisNntZfgzwM8LYDC+NdsrCKL2GaOgyzb0J9kCcVMRdmDGqLm+R6K6W+pH6mJ9UjZFGmagrqowFxJ93uWGce2sNnhdmy9wgbEpyh3ddZIm+BVTRTUjSy8d1eoMoVPNx+dO/hgqHZS047buhf7EBgUvfVnRnsFXN+okQKBgCjn3uMgeThxf+YnSMSbmgIrd8PDmOosSKlcd4XUUhAsWMwQ5Fo+0f6dEK+wUEcOSlObIk8t47KJvQxiDp0s+eq1Ay9SV6LmOx3UajboTba9ACbDK4+QZ5n4Mq0gWFGA0GdHvujMhSApzcZsLpM/N15XaYxiCAgKHB0Rw3uHT7sZAoGAEhF25OiuQTlw1WIJkz18zcZo9seEQW0lo+pCVxVBwBgMZqbKszzo9+QqQmYHRWpVsm9zv50UeLwAxhtgEpIvie7+ppgtG4wQJ4qGxoUtYHc/vTVPEmMIYKzaPqIVBFgV42kjKqq31lFb8JiGwV9fOnx39EIiHP1Dwai/nVZ2vyECgYEAuJQyqO1QPBG70E3gAy1yQxLYce473V9mizPEAjhV/oBlIOlrT4JpvwKoCuRdOoluDtYOHJpHk3hrSoboMuCl9BIECQIt03/xfaQbJ7YQu2SNf3ADrd6A+r8286aKBXjI9X9oSfwAgXnHQftGKDLqt6OrEyCAl+gsM3/R7eKsOH0="); | |||||
request.setSerialNo("64A5FAD5B64073087D3285DB6CEDC35FCE35A476"); | |||||
request.setMchid("1535705621"); | |||||
request.setCreateType(1); | |||||
request.setTradeType(TradeType.NATIVE); | |||||
request.setDescription("测试"); | |||||
request.setOutTradeNo("123456789"); | |||||
request.setNotifyUrl("https://skx.mynatapp.cc/qtucpaymgt/wxv3/notify/"); | |||||
request.setTotal(1); | |||||
request.setCurrency("CNY"); | |||||
request.setOpenid("oQj1Z5QX3YLzRl5Z0JJYlXQ_1HY8"); | |||||
try { | |||||
AtsCreatPayOrderV3Response response = jsonPostRepeat(request); | |||||
logger.info("V3统一下单结果:{}", response.toJson(true)); | |||||
} catch (ManagerException e) { | |||||
logger.error("V3统一下单异常:{}", e.getMessage()); | |||||
} | |||||
} | |||||
// QUERYPAYRESULTV3("查询V3支付结果", "queryPayResultV3",AtsQueryPayResultV3Request .class), | |||||
@Test | |||||
public void AtsQueryPayResultV3Request() { | |||||
AtsQueryPayResultV3Request request = new AtsQueryPayResultV3Request(); | |||||
} | |||||
// REFUNDV3("微信V3退款申请", "refundV3", AtsRefundV3Request.class), | |||||
@Test | |||||
public void AtsRefundV3Request() { | |||||
AtsRefundV3Request request = new AtsRefundV3Request(); | |||||
} | |||||
// REFUNDQUERYV3("微信V3退款查询", "refundV3Query", AtsQueryRefundV3Request.class), | |||||
@Test | |||||
public void AtsQueryRefundV3Request() { | |||||
AtsQueryRefundV3Request request = new AtsQueryRefundV3Request(); | |||||
} | |||||
// REFUNDV2("微信V2退款申请", "refundV2", AtsRefundV2Request.class), | |||||
@Test | |||||
public void AtsRefundV2Request() { | |||||
AtsRefundV2Request request = new AtsRefundV2Request(); | |||||
} | |||||
// REFUNDQUERYV2("微信V2退款查询", "refundV2Query", AtsQueryRefundV2Request.class), | |||||
@Test | |||||
public void AtsQueryRefundV2Request() { | |||||
AtsQueryRefundV2Request request = new AtsQueryRefundV2Request(); | |||||
} | |||||
// VEHICLEUSERSTATE("微信车主状态查询及获取签约参数", "vehicleUserState", AtsVehicleUserStateRequest.class), | |||||
@Test | |||||
public void AtsVehicleUserStateRequest() { | |||||
AtsVehicleUserStateRequest request = new AtsVehicleUserStateRequest(); | |||||
request.setAppId("wxcb1388c809fe25a9"); | |||||
request.setSubAppId("wx008c60533388527a"); | |||||
request.setMchId("1500877591"); | |||||
request.setSubMchId("1515327001"); | |||||
request.setSignKey("beijingwuxiangancekejiyouxiangon"); | |||||
request.setPlateNumber("贵Z10035"); | |||||
request.setSubOpenId("3gthr6743"); | |||||
try { | |||||
AtsVehicleUserStateResponse response = jsonPostRepeat(request); | |||||
logger.info("微信车主状态查询及获取签约参数结果:{}", response.toJson(true)); | |||||
} catch (ManagerException e) { | |||||
logger.error("微信车主状态查询及获取签约参数异常:{}", e.getMessage()); | |||||
} | |||||
} | |||||
} |
package cn.com.taiji.ats.manager.wx; | |||||
import cn.com.taiji.ats.manager.handler.wx.WxMessageManager; | |||||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||||
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.WxMpIsSubscribedRequest; | |||||
import org.junit.jupiter.api.Test; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.boot.test.context.SpringBootTest; | |||||
import cn.com.taiji.ats.Application; | |||||
import cn.com.taiji.ats.manager.AbstractCommManager; | |||||
/** | |||||
* @Auther: humh | |||||
* @Description: | |||||
* @Date: 2025/5/12 10:58 | |||||
* @email: huminghao@mail.taiji.com.cn | |||||
* @version: 1.0 | |||||
*/ | |||||
@SpringBootTest(classes = Application.class) | |||||
public class TestWxMpIsSubscribedManager extends AbstractCommManager { | |||||
@Autowired | |||||
private WxMessageManager wxMessageManager; | |||||
@Test | |||||
public void test() throws ServiceHandleException { | |||||
WxMpIsSubscribedRequest request = new WxMpIsSubscribedRequest(); | |||||
request.setClientId("bfc4040bda90473d8ceab246555361a3"); | |||||
request.setOpenId("ogb3at_BW9zRd0GRPrBsNjthwGeA"); | |||||
wxMessageManager.isSubscribed(request); | |||||
} | |||||
} | |||||
//package cn.com.taiji.ats.manager.wx; | |||||
// | |||||
//import cn.com.taiji.ats.manager.handler.wx.WxMessageManager; | |||||
//import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||||
//import cn.com.taiji.core.model.comm.protocol.ats.weiXin.WxMpIsSubscribedRequest; | |||||
//import org.junit.jupiter.api.Test; | |||||
//import org.springframework.beans.factory.annotation.Autowired; | |||||
//import org.springframework.boot.test.context.SpringBootTest; | |||||
// | |||||
//import cn.com.taiji.ats.Application; | |||||
//import cn.com.taiji.ats.manager.AbstractCommManager; | |||||
// | |||||
// | |||||
///** | |||||
// * @Auther: humh | |||||
// * @Description: | |||||
// * @Date: 2025/5/12 10:58 | |||||
// * @email: huminghao@mail.taiji.com.cn | |||||
// * @version: 1.0 | |||||
// */ | |||||
//@SpringBootTest(classes = Application.class) | |||||
//public class TestWxMpIsSubscribedManager extends AbstractCommManager { | |||||
// | |||||
// @Autowired | |||||
// private WxMessageManager wxMessageManager; | |||||
// | |||||
// @Test | |||||
// public void test() throws ServiceHandleException { | |||||
// WxMpIsSubscribedRequest request = new WxMpIsSubscribedRequest(); | |||||
// request.setClientId("bfc4040bda90473d8ceab246555361a3"); | |||||
// request.setOpenId("ogb3at_BW9zRd0GRPrBsNjthwGeA"); | |||||
// wxMessageManager.isSubscribed(request); | |||||
// } | |||||
// | |||||
// | |||||
//} |