package com.bohuikeji.frame.module.admin.controller.wx;

import com.bohuikeji.frame.module.admin.utils.SignUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 微信回调入口类
 * @author 10552
 */
@RestController
@RequestMapping("/wx/callback")
public class CallbackController {

    /**
     * token验证回调
     * @param request
     * @param response
     * @param signature
     * @param timestamp
     * @param nonce
     * @param echostr
     * @return
     * @throws IOException
     */
    @RequestMapping("/token")
    public String wechatGet(HttpServletRequest request,
                          HttpServletResponse response,
                          @RequestParam(value = "signature") String signature,
                          @RequestParam(value = "timestamp") String timestamp,
                          @RequestParam(value = "nonce") String nonce,
                          @RequestParam(value = "echostr") String echostr) throws IOException {
        if (SignUtil.checkSignature("123456abcd", signature, timestamp, nonce)) {
            return echostr;
        }
        return "ERROE";

    }

}
