|
@@ -63,7 +63,7 @@ public class WxpayController {
|
|
|
private ProjectRecodeService projectRecodeService;
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(WxpayController.class);
|
|
|
- private static String redirectUrl = "http://5087452.nat123.cc/wxpay/redirectUrl";
|
|
|
+ private static String redirectUrl = "http://lj.ubtob.com/wxpay/redirectUrl";
|
|
|
//private String orderNumber = NumberGenerator.generateId();
|
|
|
|
|
|
/**
|
|
@@ -80,6 +80,7 @@ public class WxpayController {
|
|
|
projectRecode = this.createProjectRecode(jsonStr);
|
|
|
} catch (Exception e) {
|
|
|
response.getWriter().write(e.getMessage());
|
|
|
+ logger.error("生成商户订单错误,原因:{}", e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -104,6 +105,7 @@ public class WxpayController {
|
|
|
projectRecode = this.createProjectRecode(jsonStr);
|
|
|
} catch (Exception e) {
|
|
|
response.getWriter().write(e.getMessage());
|
|
|
+ logger.error("生成商户订单错误,原因:{}", e.getMessage());
|
|
|
map.put("error", "参数错误");
|
|
|
return map;
|
|
|
}
|
|
@@ -154,6 +156,7 @@ public class WxpayController {
|
|
|
projectRecode = this.createProjectRecode(jsonStr);
|
|
|
} catch (Exception e) {
|
|
|
response.getWriter().write(e.getMessage());
|
|
|
+ logger.error("生成商户订单错误,原因:{}", e.getMessage());
|
|
|
map.put("error", "参数错误");
|
|
|
return map;
|
|
|
}
|
|
@@ -234,6 +237,10 @@ public class WxpayController {
|
|
|
try {
|
|
|
String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
|
|
|
WxPayOrderNotifyResult result = wxPayApi.parseOrderNotifyResult(xmlResult);
|
|
|
+
|
|
|
+ //商户系统订单默认支付状态
|
|
|
+ short projectRecodePayStatus = 1;
|
|
|
+
|
|
|
if ("SUCCESS".equals(result.getReturnCode())) {
|
|
|
if ("SUCCESS".equals(result.getResultCode())) {
|
|
|
returnResult = setXml("SUCCESS", "OK");
|
|
@@ -247,21 +254,33 @@ public class WxpayController {
|
|
|
|
|
|
//校验返回的订单金额是否与商户侧的订单金额一致
|
|
|
//TODO 先注释这两句
|
|
|
-// ProjectRecode projectRecode = projectRecodeService.findOne(Long.parseLong(result.getOutTradeNo()));
|
|
|
-// if (!(projectRecode != null && ((int) (projectRecode.getAmount()*100)) == result.getTotalFee().intValue())) {
|
|
|
- if (false) {
|
|
|
+ ProjectRecode projectRecode = projectRecodeService.findOne(Long.parseLong(result.getOutTradeNo()));
|
|
|
+ if (!(projectRecode != null && ((int) (projectRecode.getAmount()*100)) == result.getTotalFee().intValue())) {
|
|
|
logger.warn("防止数据泄漏导致出现“假通知”,以免造成资金损失");
|
|
|
map.put("warning", "防止数据泄漏导致出现“假通知”,以免造成资金损失");
|
|
|
returnResult = setXml("FAIL", "商户侧的订单金额与返回的订单金额不一致");
|
|
|
+
|
|
|
+ projectRecodePayStatus = 3;
|
|
|
+ projectRecode.setStatus(projectRecodePayStatus);
|
|
|
+ projectRecode.setExceptionMsg("{'AmountMsg' : '支付宝返回金额(单位分)与订单金额不相等', 'notifyTotalFee' : " + result.getTotalFee().intValue() + "}");
|
|
|
+
|
|
|
} else {
|
|
|
WxPayOrderQueryResult wxPayOrderQueryResult = wxPayApi.queryOrder(result.getTransactionId(),null);//二选一填
|
|
|
if (wxPayOrderQueryResult != null) {
|
|
|
- map.put("tradeState", wxPayOrderQueryResult.getTradeState());
|
|
|
- map.put("tradeStateDesc", wxPayOrderQueryResult.getTradeStateDesc());
|
|
|
+ map.put("tradeState", wxPayOrderQueryResult.getTradeState());//微信订单状态
|
|
|
+ map.put("tradeStateDesc", wxPayOrderQueryResult.getTradeStateDesc());//微信订单状态详情
|
|
|
}
|
|
|
- wechatOrder = wechatOrderService.save(WechatOrder.WxPayOrderNotifyResultToConvert(result, (short) 1, wxPayOrderQueryResult));
|
|
|
+
|
|
|
+ if ("SUCCESS".equals(wxPayOrderQueryResult.getTradeState())) {
|
|
|
+ projectRecodePayStatus = 2;
|
|
|
+ projectRecode.setStatus(projectRecodePayStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ wechatOrderService.save(WechatOrder.WxPayOrderNotifyResultToConvert(result, (short) 1, wxPayOrderQueryResult));
|
|
|
returnResult = setXml("SUCCESS", "OK");
|
|
|
}
|
|
|
+ //更新订单状态
|
|
|
+ projectRecodeService.update(projectRecode);
|
|
|
}
|
|
|
//String totalFee = WxPayBaseResult.feeToYuan(result.getTotalFee());
|
|
|
} else {
|
|
@@ -330,6 +349,8 @@ public class WxpayController {
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/getUserInfo")
|
|
|
public String getOpenId(HttpServletRequest request){
|
|
|
try {
|
|
|
//TODO 授权方式 是否需要电话号码 名字等信息
|
|
@@ -449,7 +470,8 @@ public class WxpayController {
|
|
|
wxPayUnifiedOrderRequest.setTotalFee((int)(projectRecode.getAmount() * 100));//是 订单总金额,只能为整数
|
|
|
|
|
|
//wxPayUnifiedOrderRequest.setSpbillCreateIp(IpUtils.getIpFromRequest(request));//是 APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP
|
|
|
- wxPayUnifiedOrderRequest.setSpbillCreateIp("218.17.158.219");
|
|
|
+ wxPayUnifiedOrderRequest.setSpbillCreateIp(getIp(request));
|
|
|
+ //wxPayUnifiedOrderRequest.setSpbillCreateIp("10.10.100.200");
|
|
|
|
|
|
//wxPayUnifiedOrderRequest.setTimeStart(null);//否 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。
|
|
|
//wxPayUnifiedOrderRequest.setTimeExpire(null);//否 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。
|
|
@@ -477,4 +499,22 @@ public class WxpayController {
|
|
|
ProjectRecode newProjectRecode = projectRecodeService.join(projectRecode);
|
|
|
return newProjectRecode;
|
|
|
}
|
|
|
+
|
|
|
+ public String getIp(HttpServletRequest request) {
|
|
|
+
|
|
|
+ String ip = request.getHeader("X-Forwarded-For");
|
|
|
+ if(ip!=null && !"unKnown".equalsIgnoreCase(ip)){
|
|
|
+ int index = ip.indexOf(",");
|
|
|
+ if(index != -1){
|
|
|
+ return ip.substring(0,index);
|
|
|
+ }else{
|
|
|
+ return ip;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ip = request.getHeader("X-Real-IP");
|
|
|
+ if(ip!=null && !"unKnown".equalsIgnoreCase(ip)){
|
|
|
+ return ip;
|
|
|
+ }
|
|
|
+ return request.getRemoteAddr();
|
|
|
+ }
|
|
|
}
|