| @@ -10,12 +10,16 @@ import com.simple.service.WxRefundOrderService; | |||||
| import com.simple.utils.XmlUtil; | import com.simple.utils.XmlUtil; | ||||
| import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.jdom.JDOMException; | |||||
| import org.springframework.http.MediaType; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import java.io.ByteArrayOutputStream; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||
| import java.util.LinkedHashMap; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.SortedMap; | import java.util.SortedMap; | ||||
| import java.util.TreeMap; | import java.util.TreeMap; | ||||
| @@ -40,22 +44,36 @@ public class WxPayController extends BaseController { | |||||
| * @return 接收微信异步通知 | * @return 接收微信异步通知 | ||||
| * @throws Exception 可能产生的任何异常 | * @throws Exception 可能产生的任何异常 | ||||
| */ | */ | ||||
| @RequestMapping(value = "/pay") | |||||
| public String _payNotify(HttpServletRequest request) throws Exception { | |||||
| @RequestMapping(value = "/pay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | |||||
| @ResponseBody | |||||
| public String _payNotify(HttpServletRequest request) throws IOException, JDOMException { | |||||
| logger.info("微信支付回调"); | |||||
| InputStream inStream = request.getInputStream(); | |||||
| ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||||
| byte[] buffer = new byte[1024]; | |||||
| int len = 0; | |||||
| while ((len = inStream.read(buffer)) != -1) { | |||||
| outSteam.write(buffer, 0, len); | |||||
| } | |||||
| String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||||
| logger.info(resultxml); | |||||
| outSteam.close(); | |||||
| inStream.close(); | |||||
| Map<String, String> paramMap = null; | Map<String, String> paramMap = null; | ||||
| try { | try { | ||||
| String xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||||
| paramMap = WxPayment.xmlToMap(xml); | |||||
| logger.info("payment wxpay, notify, param: " + paramMap.toString() ); | |||||
| paramMap = WxPayment.xmlToMap(resultxml); | |||||
| logger.info("微信支付回调, notify, param: " + paramMap.toString() ); | |||||
| String response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | String response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | ||||
| logger.info("payment wxpay, notify success, req : " + paramMap.toString() + ", resp: " + response.toString()); | |||||
| logger.info("微信支付回调, notify success, req : " + paramMap.toString() + ", resp: " + response.toString()); | |||||
| return response; | return response; | ||||
| } catch (BizMessageException e) { | } catch (BizMessageException e) { | ||||
| if (paramMap == null) { | if (paramMap == null) { | ||||
| logger.error("payment wxpay, order create error, e: " + e.getMessage()); | |||||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||||
| } else { | } else { | ||||
| logger.error("payment wxpay, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| logger.error("微信支付回调, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| } | } | ||||
| SortedMap resultMap = new TreeMap<>(); | SortedMap resultMap = new TreeMap<>(); | ||||
| resultMap.put("return_code", "FAIL"); | resultMap.put("return_code", "FAIL"); | ||||
| @@ -63,9 +81,9 @@ public class WxPayController extends BaseController { | |||||
| return XmlUtil.getRequestXml(resultMap); | return XmlUtil.getRequestXml(resultMap); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| if (paramMap == null) { | if (paramMap == null) { | ||||
| logger.error("payment wxpay, order create error, e: " + e.getMessage()); | |||||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||||
| } else { | } else { | ||||
| logger.error("payment wxpay, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| logger.error("微信支付回调, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| } | } | ||||
| SortedMap resultMap = new TreeMap<>(); | SortedMap resultMap = new TreeMap<>(); | ||||
| resultMap.put("return_code", "FAIL"); | resultMap.put("return_code", "FAIL"); | ||||
| @@ -73,9 +91,9 @@ public class WxPayController extends BaseController { | |||||
| return XmlUtil.getRequestXml(resultMap); | return XmlUtil.getRequestXml(resultMap); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| if (paramMap == null) { | if (paramMap == null) { | ||||
| logger.error("payment wxpay, order create error, e: " + e.getMessage()); | |||||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||||
| } else { | } else { | ||||
| logger.error("payment wxpay, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| logger.error("微信支付回调, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| } | } | ||||
| SortedMap resultMap = new TreeMap(); | SortedMap resultMap = new TreeMap(); | ||||
| resultMap.put("return_code", "FAIL"); | resultMap.put("return_code", "FAIL"); | ||||