//package com.gree.mall.manager.controller.wxCustomer;
//
//
//import cn.hutool.http.HttpUtil;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.gree.mall.manager.annotation.ApiNotAuth;
//import com.gree.mall.manager.logic.common.WorkWechatLogic;
//import com.gree.mall.manager.logic.sop.SopRuleLogic;
//import com.gree.mall.manager.plus.entity.AdminCompanyWechat;
//import com.gree.mall.manager.plus.service.AdminCompanyWechatService;
//import com.gree.mall.manager.utils.wecom.WxCryptUtil;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiModelProperty;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import me.chanjar.weixin.cp.api.WxCpService;
//import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
//import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
//import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author danmo
// * @description 企微回调通知接口
// * @date 2020/11/6 17:31
// **/
//@Api(tags = "企微回调通知")
//@Slf4j
//@RestController
//@RequestMapping("/wx/callback")
//public class WeCallBackController {
//
//    @Autowired
//    private SopRuleLogic sopRuleLogic;
//
//    @Autowired
//    private AdminCompanyWechatService adminCompanyWechatService;
//
//    @Autowired
//    private WorkWechatLogic workWechatLogic;
//
//    @ApiModelProperty("post数据接收")
//    @PostMapping(value = "/recive/{corpId}")
//    @ApiNotAuth
//    public String recive(@RequestBody String msg, @RequestParam(name = "msg_signature") String signature,
//                         String timestamp, String nonce,@PathVariable("corpId") String corpId) {
//        AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.getOne(Wrappers.<AdminCompanyWechat>lambdaQuery().eq(AdminCompanyWechat::getCorpId, corpId).last("limit 1"));
//        WxCryptUtil wxCryptUtil = new WxCryptUtil(adminCompanyWechat.getToken(), adminCompanyWechat.getEncodingaesKey(), corpId);
//        try {
//            String decrypt = wxCryptUtil.decrypt(signature, timestamp, nonce, msg);
//            sopRuleLogic.pushTaskWorker(decrypt,corpId);
//            return decrypt;
//        } catch (Exception e) {
//            e.printStackTrace();;
//            String sRespData = WxCryptUtil.getTextRespData("success");
//            return wxCryptUtil.encrypt(sRespData);
//        }
//    }
//
//    @ApiModelProperty("get数据校验")
//    @GetMapping(value = "/recive/{corpId}")
//    @ApiNotAuth
//    public String recive(HttpServletRequest request,@PathVariable("corpId") String corpId) {
//        // 微信加密签名
//        String sVerifyMsgSig = request.getParameter("msg_signature");
//        // 时间戳
//        String sVerifyTimeStamp = request.getParameter("timestamp");
//        // 随机数
//        String sVerifyNonce = request.getParameter("nonce");
//        // 随机字符串
//        String sVerifyEchoStr = request.getParameter("echostr");
//
//        AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.getOne(Wrappers.<AdminCompanyWechat>lambdaQuery().eq(AdminCompanyWechat::getCorpId, corpId).last("limit 1"));
//        WxCryptUtil wxCryptUtil = new WxCryptUtil(adminCompanyWechat.getToken(), adminCompanyWechat.getEncodingaesKey(), corpId);
//        try {
//            String s = wxCryptUtil.verifyURL(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr);
//            return s;
//        } catch (Exception e) {
//            return "error";
//        }
//    }
//
//}
