package com.ruoyi.web.modules.pay.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.web.modules.pay.service.IWeChatPayService;

/**
 * 微信支付回调（公网 HTTPS · 无需登录）
 */
@RestController
@RequestMapping("/api/pay/wechat")
public class WeChatPayNotifyController
{
    @Autowired
    private IWeChatPayService weChatPayService;

    @Anonymous
    @PostMapping("/notify")
    public Map<String, String> notify(@RequestBody String rawBody,
            @RequestHeader(value = "Wechatpay-Timestamp", required = false) String timestamp,
            @RequestHeader(value = "Wechatpay-Nonce", required = false) String nonce,
            @RequestHeader(value = "Wechatpay-Signature", required = false) String signature)
    {
        weChatPayService.handleNotify(rawBody, timestamp, nonce, signature);
        Map<String, String> resp = new HashMap<>();
        resp.put("code", "SUCCESS");
        resp.put("message", "成功");
        return resp;
    }
}
