Parcourir la source

修改回调接口

Seven il y a 6 mois
Parent
commit
7071c92c25

+ 45 - 0
web/open-api/src/main/java/pay/platform/api/controller/CallbackController.java

@@ -1,11 +1,56 @@
 package pay.platform.api.controller;
 
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.internal.util.AlipaySignature;
+import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
+import pay.platform.alipay.enums.AliPayApi;
+
+import java.util.Map;
 
 @Slf4j
 @RestController
 @RequestMapping("/api/")
 public class CallbackController {
+
+    /**
+     * 支付宝同步回调
+     *
+     * @param request 请求
+     * @param appId   app_id
+     * @return 返回结果
+     */
+    @RequestMapping(value = "/return_url/{appId}")
+    @ResponseBody
+    public String returnUrl(HttpServletRequest request, @PathVariable String appId) {
+        try {
+            // 获取支付宝GET过来反馈信息
+            Map<String, String> map = AliPayApi.toMap(request);
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                log.info("参数:{} - 值: {}", entry.getKey(), entry.getValue());
+            }
+
+            // 服务商 - 公钥
+            String publicKey = "";
+
+            boolean verifyResult = AlipaySignature.rsaCheckV1(map, publicKey, "UTF-8", "RSA2");
+
+            if (verifyResult) {
+                // TODO 请在这里加上商户的业务逻辑程序代码
+                log.info("return_url 验证成功");
+
+                return "success";
+            } else {
+                log.warn("return_url 验证失败");
+                return "failure";
+            }
+        } catch (AlipayApiException e) {
+            log.error("支付宝同步回调异常", e);
+            return "failure";
+        }
+    }
 }