package com.njzscloud.supervisory.wxPay.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.supervisory.wxPay.param.TemplateMessageParam;
import com.njzscloud.supervisory.wxPay.service.WechatTemplateMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 支付相关接口
 * 使用微信支付官方SDK的生产级实现
 */
@Slf4j
@RestController
@RequestMapping("/wechatTemplateMessage")
@RequiredArgsConstructor
public class WechatTemplateMessageController {

    private final WechatTemplateMessageService wechatTemplateMessageService;

    /**
     * 绑定微信openid
     */
    @GetMapping("/bind")
    public R<?> bind(@RequestParam String code) {
        wechatTemplateMessageService.bind(code);
        return R.success();
    }

    /**
     * key
     */
    @GetMapping("/key")
    public R<?> key(@RequestParam String code) {
        return R.success(wechatTemplateMessageService.key(code));
    }

    @PostMapping("/send-order-notice")
    public String sendOrderNotice(@RequestBody TemplateMessageParam param) {
        try {
            // 发送模板消息
            wechatTemplateMessageService.sendTemplateMessage(param);
            return "发送成功";
        } catch (Exception e) {
            return "发送失败: " + e.getMessage();
        }
    }

}
