Giter Club home page Giter Club logo

spay's Introduction

spay's People

Contributors

1711680493 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

spay's Issues

回调报错,请求类型不支持,这个怎么解决呢

作者你好,请教一下我这回调错误是咋回事呢

图片
图片

package com.lys.spay.service;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PayService {
    @GetMapping("/payment_config")
    public Object getPaymentConfig() {
        return new Object() {
            public String code = "10000";
            public Object msg = new Object() {
                public Object paystr = new Object() {
                    public Object 微信 = new Object() {
                        public boolean isUp = true;
                        public String[] packName = {"com.tencent.mm"};
                        public Object[] list = {
                                new Object() {
                                    public boolean isTitle = false;
                                    public String start = "微信支付收款";
                                    public String end = "元";
                                },
                                new Object() {
                                    public boolean isTitle = false;
                                    public String start = "收款";
                                    public String end = "元";
                                }
                        };
                    };
                };
                public String purl = "http://8.134.189.49:8080/payment_callback";
            };
        };
    }

    @PostMapping("/payment_callback")
    public Object processPaymentCallback(@RequestBody CallbackRequest request) {
        String priKey = "lys"; // 请替换为实际的私钥

        // 验证priKey和time
        long currentTime = System.currentTimeMillis() / 1000; // 当前时间戳(秒)
        if (!priKey.equals(request.getPriKey()) || currentTime - request.getTime() > 150) {
            return new Response("20001", "权限验证失败");
        }

        // 根据amount和type确认订单,完成支付逻辑
        // 这里可以添加具体的订单处理逻辑

        // 响应结果
        return new Response("10000", "支付回调成功");
    }

    static class CallbackRequest {
        private int amount;
        private String type;
        private String priKey;
        private long time;

        // 省略getter和setter方法

        public int getAmount() {
            return amount;
        }

        public void setAmount(int amount) {
            this.amount = amount;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getPriKey() {
            return priKey;
        }

        public void setPriKey(String priKey) {
            this.priKey = priKey;
        }

        public long getTime() {
            return time;
        }

        public void setTime(long time) {
            this.time = time;
        }
    }

    static class Response {
        private String code;
        private String msg;

        public Response(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        // 省略getter和setter方法

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }
}

这个回调接口的接收参数的类型是用@requestbody

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.