package com.fjs.scenic.controller;

import com.fjs.scenic.cyt.utils.Md5Utils;
import com.fjs.scenic.entity.order.Orders;
import com.fjs.scenic.entity.user.User;
import com.fjs.scenic.service.ord.OrdersService;
import com.fjs.scenic.service.user.UserService;
import com.fjs.scenic.utils.AESUtil;
import com.fjs.scenic.utils.Cons;
import com.fjs.scenic.utils.ReturnResult;
import com.fjs.scenic.utils.WXPayUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Map;

/**
 * 微信支付入口
 * @author LF
 * @date 2018-06-20 10:00
 * @version 1.0
 */
@RestController
@RequestMapping("/api/wechat/pay")
public class WeChatPayController {

    private static Logger log = LoggerFactory.getLogger(WeChatPayController.class);

    /**
     * 微信公众号、商户配置
     */
    @Value("${APPID}")
    private String appid;
    @Value("${MCH_ID}")
    private String mchId;
    @Value("${API_KEY}")
    private String apiKey;
    @Value("${CERT_FILE_NAME}")
    private String cert;
    @Value("${NOTIFY_URL}")
    private String notifyUrl;
    @Value("${FEFUND_NOTIFY}")
    private String fefundNotify;


    @PostConstruct
    public void init(){
        WXPayUtil.APPID = this.appid;
        WXPayUtil.MCH_ID = this.mchId;
        WXPayUtil.API_KEY = this.apiKey;
        AESUtil.secretKey = new SecretKeySpec(Md5Utils.MD5Encode(this.apiKey, "UTF-8").toLowerCase().getBytes(), "AES");
        WXPayUtil.CERT_FILE_NAME = this.cert;
        WXPayUtil.NOTIFY_URL = this.notifyUrl;
        WXPayUtil.FEFUND_NOTIFY = this.fefundNotify;
    }
}

