|
@ -0,0 +1,127 @@
|
|
|
|
package com.yihu.wlyy.web.third.ylzpay;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.yihu.wlyy.entity.organization.HospitalMapping;
|
|
|
|
import com.yihu.wlyy.entity.ylz.PayConfigura;
|
|
|
|
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
|
|
|
|
import com.yihu.wlyy.repository.ylz.PayConfiguraDao;
|
|
|
|
import com.yihu.wlyy.service.third.ylz.PayLogService;
|
|
|
|
import com.yihu.wlyy.service.weixin.wxpay.model.Charge;
|
|
|
|
import com.yihu.wlyy.service.weixin.wxpay.service.OnePayService;
|
|
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
|
|
import com.yihu.wlyy.web.WeixinBaseController;
|
|
|
|
import com.ylzinfo.onepay.sdk.OnepayDefaultClient;
|
|
|
|
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
|
|
|
|
import com.ylzinfo.onepay.sdk.exception.PayException;
|
|
|
|
import com.ylzinfo.onepay.sdk.utils.StringUtil;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.util.StreamUtils;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Reece on 2017/8/30/030.
|
|
|
|
*
|
|
|
|
* 供易联众支付类相关业务调用
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(value = "/onepay")
|
|
|
|
@Api(description = "供易联众家庭签约支付调用")
|
|
|
|
public class ThirdOnepayController extends WeixinBaseController {
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ThirdOnepayController.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private OnePayService pay;
|
|
|
|
@Autowired
|
|
|
|
PayLogService logService;
|
|
|
|
@Autowired
|
|
|
|
private PayConfiguraDao configuraDao;
|
|
|
|
@Autowired
|
|
|
|
private HospitalMappingDao mappingDao;
|
|
|
|
@Autowired
|
|
|
|
ObjectMapper objectMapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 支付真正完成,异步回调返回支付参数 后台做数据操作
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param response
|
|
|
|
* @throws IOException
|
|
|
|
* @throws PayException
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/receiveNotify")
|
|
|
|
public void receiveNotify(HttpServletRequest request, HttpServletResponse response) throws IOException, PayException {
|
|
|
|
SimpleDateFormat formatDate = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
PayConfigura config = configuraDao.findWorkConfigura();
|
|
|
|
Boolean isSuccess = false;
|
|
|
|
String error = "";
|
|
|
|
String responses = "";
|
|
|
|
response.setContentType("text/html;charset=utf-8");
|
|
|
|
InputStream inputStream = request.getInputStream();
|
|
|
|
String params = StreamUtils.copyToString(inputStream, Charset.forName("UTF-8"));
|
|
|
|
try {
|
|
|
|
JSONObject json = new JSONObject(params);
|
|
|
|
String appId = json.getString("appId");
|
|
|
|
HospitalMapping hospital = mappingDao.findByAppId(appId);
|
|
|
|
String appSecret = hospital.getAppSecret();
|
|
|
|
|
|
|
|
LOGGER.info("回调参数:{}", params);
|
|
|
|
if (StringUtil.isEmpty(params)) {
|
|
|
|
response.getWriter().write("empty");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 参数转换
|
|
|
|
ResponseParams<?> encryptRes = JSON.parseObject(params, ResponseParams.class);
|
|
|
|
OnepayDefaultClient client = new OnepayDefaultClient("", appId, appSecret, encryptRes.getSignType(), encryptRes.getEncryptType());
|
|
|
|
|
|
|
|
|
|
|
|
LOGGER.info("解密前:{}", JSON.toJSONString(encryptRes));
|
|
|
|
ResponseParams<?> decryptRes = client.decryptNotifyResponse(encryptRes);
|
|
|
|
LOGGER.info("解密后:{}", JSON.toJSONString(decryptRes));
|
|
|
|
boolean isDecrypt = ("-1".equals(decryptRes.getRespCode()) ? false : true); // 是否解密失败
|
|
|
|
if (!isDecrypt) {
|
|
|
|
response.getWriter().write("DECRYPT FAILURE");
|
|
|
|
} else {
|
|
|
|
boolean isVerify = client.verifyResponseSign(decryptRes);
|
|
|
|
LOGGER.info("验签结果:{}", isVerify);
|
|
|
|
if (!isVerify) {
|
|
|
|
response.getWriter().write("FAILURE");
|
|
|
|
} else {
|
|
|
|
// 业务逻辑代码
|
|
|
|
isSuccess = true;
|
|
|
|
responses = JSON.toJSONString(decryptRes);
|
|
|
|
JSONObject requestParam = new JSONObject(responses);//业务出参
|
|
|
|
JSONObject responseParam = requestParam.getJSONObject("param");
|
|
|
|
Charge chargeView = objectMapper.readValue(responseParam.toString(), Charge.class);
|
|
|
|
pay.saveToWlyyCharge(chargeView);
|
|
|
|
|
|
|
|
response.getWriter().write("SUCCESS");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
response.getWriter().write(e.getMessage());
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
e.printStackTrace(pw);
|
|
|
|
error = sw.toString();
|
|
|
|
}
|
|
|
|
// 记录log日志到数据库
|
|
|
|
logService.saveHttpLog(isSuccess, config.getReceiveNotify(), "异步支付通知", "POST", null, params, responses, error, logService.onepayType);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|