package ink.wgink.module.wechat.controller.wechat.pay.v3;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.wechat.pojo.pay.v3.PayErrorResponse;
import ink.wgink.module.wechat.service.pay.v3.IPayService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName: PayController
 * @Description: 微信支付
 * @Author: wanggeng
 * @Date: 2021/8/19 9:36 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_WECHAT_PREFIX + "微信公众号")
@RestController
@RequestMapping(ISystemConstant.WECHAT_PREFIX + "/pay")
public class PayController extends DefaultBaseController {

    @Autowired
    private IPayService payService;

    @ApiOperation(value = "通知支付结果", notes = "有微信支付主动发起的支付结果通知接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Wechatpay-Signature", value = "来自微信的签名值", paramType = "header")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = PayErrorResponse.class)})
    @PostMapping("notice")
    @CheckRequestBodyAnnotation
    public void notice(HttpServletRequest request, HttpServletResponse response,
                       @RequestHeader("Wechatpay-Nonce") String nonce,
                       @RequestHeader("Wechatpay-Timestamp") String timestamp,
                       @RequestHeader("Wechatpay-Signature") String wechatpaySignature) throws IOException {
        payService.notice(request, response, nonce, timestamp, wechatpaySignature);
    }

}
