|
|
@@ -0,0 +1,170 @@
|
|
|
+package com.izouma.awesomeadmin.web;
|
|
|
+
|
|
|
+import com.github.kevinsawicki.http.HttpRequest;
|
|
|
+import com.izouma.awesomeadmin.enums.PayApiErrCode;
|
|
|
+import com.izouma.awesomeadmin.model.PayCodeInfo;
|
|
|
+import com.izouma.awesomeadmin.model.UserInfo;
|
|
|
+import com.izouma.awesomeadmin.service.PayCodeInfoService;
|
|
|
+import com.izouma.awesomeadmin.service.UserInfoService;
|
|
|
+import com.izouma.awesomeadmin.util.MbappUtil;
|
|
|
+import com.izouma.awesomeadmin.util.PayApiUtil;
|
|
|
+import com.izouma.awesomeadmin.util.PropertiesFileLoader;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping("/payApi")
|
|
|
+public class PayApiController {
|
|
|
+
|
|
|
+ private static Logger logger = Logger.getLogger(PayApiController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserInfoService userInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PayCodeInfoService payCodeInfoService;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/testPush", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public String testPush(@RequestParam(required = true, value = "abc") String abc) {
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+ String nonceStr = MbappUtil.create_nonce_str();
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, String> params = new TreeMap<>();
|
|
|
+ params.put("mch_id", PropertiesFileLoader.getProperties("leyunfu_mch_id")); //商户号
|
|
|
+ params.put("nonce_str", nonceStr); //随机串
|
|
|
+ params.put("abc", abc); //商户系统内部的订单号
|
|
|
+ String sign = PayApiUtil.generateSignature(params, abc);
|
|
|
+ params.put("sign_type", "MD5"); //签名方式
|
|
|
+ params.put("sign", sign); //签名
|
|
|
+
|
|
|
+ String response = HttpRequest.post("http://192.168.50.121:8080/payApi/notify")
|
|
|
+ .form(params).body();
|
|
|
+
|
|
|
+
|
|
|
+ return response;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("leyunfu查询订单失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping(value = "/notify", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public String notify(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ logger.error("lyf:notify");
|
|
|
+ try {
|
|
|
+
|
|
|
+ Map<String, String> notifyMap = getRequstParameter(request);
|
|
|
+
|
|
|
+ if (!PayApiUtil.isPayResultNotifySignatureValid(notifyMap, notifyMap.get("abc"))) {
|
|
|
+ return "签名失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("微信支付回调异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return "SUCCESS";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取支付码列表
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/payCodeList", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public Map payCodeList(HttpServletRequest request) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("return_code", "FAIL");
|
|
|
+ result.put("return_msg", PayApiErrCode.INVALID_REQUEST);
|
|
|
+ try {
|
|
|
+
|
|
|
+ Map<String, String> reqDataMap = getRequstParameter(request);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(reqDataMap.get("mch_id"))) {
|
|
|
+ result.put("return_code", "FAIL");
|
|
|
+ result.put("return_msg", PayApiErrCode.LACK_PARAMS);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ UserInfo userInfo = new UserInfo();
|
|
|
+ userInfo.setPhone(reqDataMap.get("mch_id"));
|
|
|
+ userInfo = userInfoService.getSingleUserInfo(userInfo);
|
|
|
+
|
|
|
+ if (userInfo == null) {
|
|
|
+ result.put("return_code", "FAIL");
|
|
|
+ result.put("return_msg", PayApiErrCode.MCHID_NOT_EXIST);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String mch_key = userInfo.getApikey();
|
|
|
+
|
|
|
+
|
|
|
+ if (!PayApiUtil.isPayResultNotifySignatureValid(reqDataMap, mch_key)) {
|
|
|
+ result.put("return_code", "FAIL");
|
|
|
+ result.put("return_msg", PayApiErrCode.SIGNERROR);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ int userId = userInfo.getId();
|
|
|
+
|
|
|
+
|
|
|
+ PayCodeInfo payCodeInfo = new PayCodeInfo();
|
|
|
+ payCodeInfo.setUserId(userId);
|
|
|
+
|
|
|
+ List<PayCodeInfo> payCodeInfoList = payCodeInfoService.getPayCodeInfoList(payCodeInfo);
|
|
|
+
|
|
|
+
|
|
|
+ result.put("return_code", "SUCCESS");
|
|
|
+ result.put("return_msg", "成功");
|
|
|
+ result.put("return_data", payCodeInfoList);
|
|
|
+ return result;
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("获取支付码列表异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> getRequstParameter(HttpServletRequest request) {
|
|
|
+ Map<String, String> reqDataMap = new HashMap<>();
|
|
|
+
|
|
|
+ Enumeration enu = request.getParameterNames();
|
|
|
+ while (enu.hasMoreElements()) {
|
|
|
+ String paraName = (String) enu.nextElement();
|
|
|
+ System.out.println(paraName + ": " + request.getParameter(paraName));
|
|
|
+ reqDataMap.put(paraName, request.getParameter(paraName));
|
|
|
+ }
|
|
|
+
|
|
|
+ return reqDataMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|