|
|
@@ -0,0 +1,68 @@
|
|
|
+package com.izouma.nineth.web;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alipay.api.AlipayApiException;
|
|
|
+import com.alipay.api.internal.util.AlipaySignature;
|
|
|
+import com.izouma.nineth.config.AlipayProperties;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import static com.alibaba.fastjson.serializer.SerializerFeature.PrettyFormat;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Controller
|
|
|
+@RequestMapping("/notify")
|
|
|
+@AllArgsConstructor
|
|
|
+public class OrderNotifyController {
|
|
|
+
|
|
|
+ private final AlipayProperties alipayProperties;
|
|
|
+
|
|
|
+ @PostMapping("/order/alipay")
|
|
|
+ @ResponseBody
|
|
|
+ public String notify(HttpServletRequest request) throws AlipayApiException {
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ Set<Map.Entry<String, String[]>> entrySet = request.getParameterMap().entrySet();
|
|
|
+ for (Map.Entry<String, String[]> entry : entrySet) {
|
|
|
+ String name = entry.getKey();
|
|
|
+ String[] values = entry.getValue();
|
|
|
+ int valLen = values.length;
|
|
|
+
|
|
|
+ if (valLen == 1) {
|
|
|
+ params.put(name, values[0]);
|
|
|
+ } else if (valLen > 1) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (String val : values) {
|
|
|
+ sb.append(",").append(val);
|
|
|
+ }
|
|
|
+ params.put(name, sb.substring(1));
|
|
|
+ } else {
|
|
|
+ params.put(name, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("支付宝回调 {}", JSON.toJSONString(params, PrettyFormat));
|
|
|
+ AlipaySignature.rsaCheckV1(params, alipayProperties.getAliPublicKey(), "UTF-8", "RSA2");
|
|
|
+ if (MapUtils.getString(params, "trade_status").equals("TRADE_SUCCESS")) {
|
|
|
+ JSONObject body = JSON.parseObject(params.get("body"));
|
|
|
+ String type = body.getString("type");
|
|
|
+ switch (type) {
|
|
|
+ case "deposit":
|
|
|
+ break;
|
|
|
+ case "recharge":
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ return "error";
|
|
|
+ }
|
|
|
+}
|