package com.v1.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.hai.common.Base64Util;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.IOUtil;
import com.hai.common.pay.util.XmlUtil;
import com.hai.common.security.AESEncodeUtil;
import com.hai.common.utils.*;
import com.hai.config.CommonSysConst;
import com.hai.config.WeChatQrcodeUtils;
import com.hai.config.WxMsgConfig;
import com.hai.entity.HighUser;
import com.hai.enum_type.WxQrCodeTypeEnum;
import com.hai.model.HighMerchantStoreModel;
import com.hai.model.ResponseData;
import com.hai.service.HighMerchantStoreService;
import com.hai.service.HighUserService;
import com.hai.service.impl.OutRechargeOrderServiceImpl;
import com.v1.config.SysConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import me.chanjar.weixin.common.error.WxErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

import static org.apache.catalina.manager.Constants.CHARSET;

/**
 * @author sum1dream
 */

@Controller
@RequestMapping(value = "/wxMsg")
@Api(value = "微信")
public class WxMsgController {

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



    @Autowired
    private WeChatQrcodeUtils weChatQrcodeUtils;

    @Resource
    private HighMerchantStoreService merchantStoreService;

    @Resource
    private HighUserService highUserService;

    @Resource
    private RedisUtil redisUtil;

//    @RequestMapping(value = "/verifyWxToken", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation(value = "验证servlet")
//    public String verifyWxToken(
//            @RequestParam(name = "signature", required = false) String signature,
//            @RequestParam(name = "timestamp", required = false) String timestamp,
//            @RequestParam(name = "nonce", required = false) String nonce,
//            @RequestParam(name = "echostr", required = false) String echostr
//    )  {
//
//        try {
//
//            String signatureStr = WxUtils.getSHA1("RgAWdnR5oEOLBdyEjfr4" , timestamp , nonce);
//            log.info("signatureStr！！！！！" + signatureStr);
//            log.info("signature！！！！！" + signature);
//            if (signature.equals(signatureStr)) {
//                log.info("验证通过！！！！！");
//                return echostr;
//            }
//            log.info("验证失败！！！！！");
//            return null;
//        } catch (Exception e) {
//            return null;
//        }
//
//    }
    @RequestMapping(value = "/verifyWxToken", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "验证servlet")
    public void verifyWxToken(HttpServletRequest request , HttpServletResponse response)  {

        try {
            log.info("进入公众号！！！！！！！");
            // 微信支付系统发送的数据（<![CDATA[product_001]]>格式）
            String notifyXml;
            notifyXml = IOUtil.inputStreamToString(request.getInputStream(), "UTF-8");
            log.info("微信系统发送的数据：" + notifyXml);
            SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8");
            Map<String,Object> mapQrCode = new HashMap<>();
            // openId
            String userOpenId = map.get("FromUserName");
            // 微信账号
            String userName = map.get("ToUserName");
            // 事件
            String event = map.get("Event");
            // 区分消息类型
            String msgType = map.get("MsgType");
            // 二维码参数
            String eventKey = map.get("EventKey");
            log.info("二维码参数：" + eventKey);

            String linkContent = "";
            String content = "";



            log.info("二维码参数：" + eventKey);
            // 普通消息
            if ("text".equals(msgType)) {
                // todo 处理文本消息
            } else if ("image".equals(msgType)) {
                // todo 处理图片消息
            } else if ("voice".equals(msgType)) {
                // todo 处理语音消息
            } else if ("video".equals(msgType)) {
                // todo 处理视频消息
            }
            // 事件推送消息
            else if ("event".equals(msgType)) {
                // 用户关注公众号
                if ("subscribe".equals(event)) {
                    if (eventKey != null && eventKey.length() != 0) {
                        JSONObject object = weChatQrcodeUtils.paramPars(eventKey);
                        // type = 1 推广扫码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type1.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type1.getType())) {
                            linkContent =
                                    "欢迎加入我们\uD83D\uDC97\n\n"
                                            + "<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=0000017&key=&code="
                                            + object.getString("code")
                                            + "'>点击加入我们</a>\n\n"
                                            + "走得更远，看得更美的风景！[太阳]\n\n";
                            // todo 推广扫码
                        }
                        // type = 2 在线加油门店扫码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type2.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type2.getType())){
                            // 商户门店
                            HighMerchantStoreModel store = merchantStoreService.getMerchantStoreByKey(object.getString("code"));
                            linkContent =
                                    "<a href='"+CommonSysConst.getSysConfig().getHsgDomainName()+"/hsgH5?accountId=000000&gasKey="
                                            + object.getString("code") + "&staffCode='>欢迎来到" + store.getStoreName()+"</a>"
                                            + "[哇][哇][哇]\n\n<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=000000&gasKey="
                                            + object.getString("code")
                                            + "&staffCode='>点击这里一键加油</a>\n\n";
                        }
                        //  3：查看视频教程
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type3.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type3.getType())){
                            // 重庆
                            if ( Objects.equals(object.getString("code"), "1")) {
                                linkContent =
                                        "加油优惠选我们，你的出行不再忧愁\uD83D\uDC97\n\n"
                                                + "<a href='https://mp.weixin.qq.com/s/Il-r_ZfTZOQDyQWgfnck1A'>查看中石油操作流程</a>\n\n"
                                                + "走得更远，看得更美的风景，加油添生活！[太阳]\n\n"
                                                + "好车要好油,优惠更加牛！[發]\n\n";
                            }
                            // 贵州
                            if (Objects.equals(object.getString("code"), "2")) {
                                linkContent =
                                        "加满好油,一路畅游!✨✨\n\n"
                                                + "<a href='https://mp.weixin.qq.com/s/4kj9XV-K_s88uji3ZrXqgg'>查看中石化操作流程</a>\n\n"
                                                + "用心为您着想，诚意为您服务。\uD83C\uDF39\n\n"
                                                + "油客来自五湖四海，在这里祝您一路顺风。\n\n";

                            }

                        }
                        //  4:支付码牌扫码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type4.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type4.getType())){
                            //  支付码码牌上的二维码
                            if (Objects.equals(object.getString("codeType"), "PAYMENT_CODE")) {
                                linkContent =
                                        "点击领取优惠券，享受更多优惠[礼物]\n\n"
                                                + "<a href='" +
                                                CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=0000014&key=&code="
                                                + object.getString("code")
                                                + "'>立即领取优惠券</a>\n\n";


                            }

                            // 支付成功生成的二维码
                            if (Objects.equals(object.getString("codeType"), "PAYMENT_SUCCESS")) {
                                linkContent =
                                        "支付分享，享受更高优惠[礼物]\n\n"
                                                + "<a href='"
                                                + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=0000012&key=&code="
                                                + object.getString("code")
                                                + "'>分享好友</a>\n\n";
                            }
                            // 扫码分享二维码进入
                            if (Objects.equals(object.getString("codeType"), "SHARE")) {
                                linkContent =
                                        "支付分享，享受更高优惠[礼物]\n\n"
                                                + "<a href='"
                                                + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=0000012&key=&code="
                                                + object.getString("code")
                                                + "'>分享好友</a>\n\n";
                            }
                        }

                        // 5:扫码贵州中石化优惠券二维码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type5.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type5.getType())){
                            mapQrCode.put("type", object.getString("encryptType"));
                            // 二维码参数
                            mapQrCode.put("id", object.getString("code"));
                            // 商户门店
                            linkContent =
                                    "山高水远,相伴致远[爱心][爱心]\n\n"
                                            + "<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=0000011&key=&code="
                                            + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(mapQrCode)))
                                            + "'>领取中石化加油券</a>\n\n"
                                            + "您追求实惠的折扣，我们追求高超的品质\uD83D\uDD16\n\n"
                                            + "迎南来北往宾朋尊驾，[福]\n\n"
                                            + "送平安顺遂诚意祝福！[福]\n\n";
                        }
                        // 6:扫码重庆中石油优惠券二维码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type6.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type6.getType())){
                            mapQrCode.put("type", object.getString("encryptType"));
                            // 二维码参数
                            mapQrCode.put("id", object.getString("code"));
                            log.info("map参数：" + mapQrCode);
                            // 商户门店
                            linkContent =
                                    "加好油，添好运，我们更适意[礼物]\n\n"
                                            + "<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=0000011&key=&code="
                                            + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(mapQrCode)))
                                            + "'>领取中石油加油券</a>\n\n"
                                            + "致力于质量与福利，赢得客户心。\n\n"
                                            + "一路精彩,“油”我相伴!\uD83C\uDF1F\n\n";
                        }
                    }
                    else {
                        linkContent = "<a href='" + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5'>点击查看更多优惠</a>\n\n";
                    }
                    content = linkContent + "服务热线：400-023-6806";
//                    content =
//                            "您好，感谢关注嗨森逛商城！\n\n" +
//                                    linkContent +
//                             "服务热线：400-023-6806"
//                            ;

                }
                // 用户扫码进入公众号
                else if ("SCAN".equals(event)) {
                    if (eventKey != null && eventKey.length() != 0) {
                        JSONObject object = weChatQrcodeUtils.paramPars(eventKey);
                        // type = 1 推广扫码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type1.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type1.getType())) {
                            linkContent =
                                    "欢迎加入我们\uD83D\uDC97\n\n"
                                            + "<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=0000017&key=&code="
                                            + object.getString("code")
                                            + "'>点击加入我们</a>\n\n"
                                            + "走得更远，看得更美的风景！[太阳]\n\n";
                            // todo 推广扫码
                        }
                        // type = 2 在线加油门店扫码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type2.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type2.getType())){
                            // 商户门店
                            HighMerchantStoreModel store = merchantStoreService.getMerchantStoreByKey(object.getString("code"));
                            linkContent =
                                    "<a href='"+CommonSysConst.getSysConfig().getHsgDomainName()+"/hsgH5?accountId=000000&gasKey="
                                            + object.getString("code") + "&staffCode='>欢迎来到" + store.getStoreName()+"</a>"
                                            + "[哇][哇][哇]\n\n<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=000000&gasKey="
                                            + object.getString("code")
                                            + "&staffCode='>点击这里一键加油</a>\n\n";
                        }
                        //  3：查看视频教程
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type3.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type3.getType())){
                            // 重庆
                            if ( Objects.equals(object.getString("code"), "1")) {
                                linkContent =
                                        "加油优惠选我们，你的出行不再忧愁\uD83D\uDC97\n\n"
                                                + "<a href='https://mp.weixin.qq.com/s/Il-r_ZfTZOQDyQWgfnck1A'>查看中石油操作流程</a>\n\n"
                                                + "走得更远，看得更美的风景，加油添生活！[太阳]\n\n"
                                                + "好车要好油,优惠更加牛！[發]\n\n";
                            }
                            // 贵州
                            if (Objects.equals(object.getString("code"), "2")) {
                                linkContent =
                                        "加满好油,一路畅游!✨✨\n\n"
                                                + "<a href='https://mp.weixin.qq.com/s/4kj9XV-K_s88uji3ZrXqgg'>查看中石化操作流程</a>\n\n"
                                                + "用心为您着想，诚意为您服务。\uD83C\uDF39\n\n"
                                                + "油客来自五湖四海，在这里祝您一路顺风。\n\n";

                            }

                        }
                        //  4:支付码牌扫码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type4.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type4.getType())){
                            //  支付码码牌上的二维码
                            if (Objects.equals(object.getString("codeType"), "PAYMENT_CODE")) {
                                linkContent =
                                        "点击领取优惠券，享受更多优惠[礼物]\n\n"
                                                + "<a href='" +
                                        CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=0000014&key=&code="
                                                + object.getString("code")
                                                + "'>立即领取优惠券</a>\n\n";


                            }

                            // 支付成功生成的二维码
                            if (Objects.equals(object.getString("codeType"), "PAYMENT_SUCCESS")) {
                                linkContent =
                                        "支付分享，享受更高优惠[礼物]\n\n"
                                                + "<a href='"
                                        + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=0000012&key=&code="
                                                + object.getString("code")
                                                + "'>分享好友</a>\n\n";
                            }
                            // 扫码分享二维码进入
                            if (Objects.equals(object.getString("codeType"), "SHARE")) {
                                linkContent =
                                        "支付分享，享受更高优惠[礼物]\n\n"
                                                + "<a href='"
                                        + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=0000012&key=&code="
                                                + object.getString("code")
                                                + "'>分享好友</a>\n\n";
                            }
                        }

                        // 5:扫码贵州中石化优惠券二维码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type5.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type5.getType())){
                            mapQrCode.put("type", object.getString("encryptType"));
                            // 二维码参数
                            mapQrCode.put("id", object.getString("code"));
                            // 商户门店
                            linkContent =
                                    "山高水远,相伴致远[爱心][爱心]\n\n"
                                            + "<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=0000011&key=&code="
                                            + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(mapQrCode)))
                                            + "'>领取中石化加油券</a>\n\n"
                                            + "您追求实惠的折扣，我们追求高超的品质\uD83D\uDD16\n\n"
                                            + "迎南来北往宾朋尊驾，[福]\n\n"
                                            + "送平安顺遂诚意祝福！[福]\n\n";
                        }
                        // 6:扫码重庆中石油优惠券二维码
                        if (Objects.equals(object.getString("qrscene_type"), WxQrCodeTypeEnum.type6.getType()) || Objects.equals(object.getString("type"), WxQrCodeTypeEnum.type6.getType())){
                            mapQrCode.put("type", object.getString("encryptType"));
                            // 二维码参数
                            mapQrCode.put("id", object.getString("code"));
                            log.info("map参数：" + mapQrCode);
                            // 商户门店
                            linkContent =
                                    "加好油，添好运，我们更适意[礼物]\n\n"
                                            + "<a href='"
                                            + CommonSysConst.getSysConfig().getHsgDomainName()
                                            + "/hsgH5?accountId=0000011&key=&code="
                                            + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(mapQrCode)))
                                            + "'>领取中石油加油券</a>\n\n"
                                            + "致力于质量与福利，赢得客户心。\n\n"
                                            + "一路精彩,“油”我相伴!\uD83C\uDF1F\n\n";
                        }
                    }
                    else {
                        linkContent = "<a href='" + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5'>点击查看更多优惠</a>\n\n";
                    }
                    content = linkContent + "服务热线：400-023-6806";

                }else if ("unsubscribe".equals(event)) {
                    // todo 取消关注 业务处理
                }else if ("CLICK".equals(event)) {
                    content = linkContent + "服务热线：400-023-6806";
                }
                map.put("content" , content);
                String mapToXml = weChatQrcodeUtils.handleEventSubscribe(map);
                response.setCharacterEncoding("UTF-8");
                response.getWriter().print(mapToXml);

            }
        } catch (Exception e) {
//            return null;
        }

    }

    @RequestMapping(value = "/getWxToken", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取微信token")
    public ResponseData getWxToken() {
        try {

            return ResponseMsgUtil.success(weChatQrcodeUtils.getWxToken(false));

        } catch (Exception e) {
            return ResponseMsgUtil.exception(e);
        }
    }

    /**
     * <pre>
     * @desc: 创建生成二维码
     * @auth: cao_wencao
     * @date: 2019/4/10 14:00
     * </pre>
     */

    @RequestMapping(value = "/createQrcode", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "创建生成二维码")
    public ResponseData createQrcode(@RequestParam(name = "type", required = false) String type,
                                     @RequestParam(name = "code", required = false) String code) {
        try {

            String jsonData;
            String sceneId;

            if (Objects.equals(type, "5")) {
                jsonData = AESEncodeUtil.aesDecrypt(Base64Util.decode(code));

                JSONObject jsonObject = JSON.parseObject(jsonData);
                Long id = jsonObject.getLong("id");

                sceneId = "type=" + type + "&code=" + id;
            } else {
                sceneId = "type=" + type + "&code=" + code;
            }

            String ticket = weChatQrcodeUtils.qrCodeCreateLastTicket(sceneId).getTicket();

            return ResponseMsgUtil.success(weChatQrcodeUtils.qrCodePictureUrl(ticket));
        } catch (Exception e) {
            return ResponseMsgUtil.exception(e);
        }
    }


    @RequestMapping(value = "/qrCodeImgUrl", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "二维码地址解析")
    public ResponseData qrCodeImgUrl(@RequestParam(name = "type", required = false) String type,
                                     @RequestParam(name = "code", required = false) String code) {
        try {

            return ResponseMsgUtil.success(weChatQrcodeUtils.qrCodeImgUrl(type , code , "DISCOUNT"));
        } catch (Exception e) {
            return ResponseMsgUtil.exception(e);
        }
    }

    /**
     * <pre>
     * @desc: 通过ticket获取二维码（长链接URL）
     * @auth: cao_wencao
     * @date: 2019/4/10 14:00
     * </pre>
     */
    @RequestMapping(value = "/getQrcodeUrl", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "创建生成二维码")
    public ResponseData getQrcodeUrl(@RequestParam(name = "ticket", required = false) String ticket) {
        try {
            return ResponseMsgUtil.success(weChatQrcodeUtils.qrCodePictureUrl(ticket));
        } catch (WxErrorException e) {
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value = "/verifyWx", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "微信签名")
    public ResponseData verifyWx(@RequestParam(value = "url", required = true) String url)  {

        try {

            JSONObject jsapiTicket = weChatQrcodeUtils.getTicket(false);
            log.info("获取jsapiTicket"+ jsapiTicket);
            // 拼接签名
            Map<String, Object> map = new HashMap<>();
            map.put("noncestr", WxUtils.makeNonStr());
            map.put("jsapi_ticket",jsapiTicket.getString("ticket"));
            map.put("timestamp", new Date().getTime());
            map.put("url",url);

            log.info("拼接map"+ map);

            Map<String, Object> objectMap = new HashMap<>();
            objectMap.put("appId" , SysConst.getSysConfig().getWxH5AppId());
            objectMap.put("timestamp" , map.get("timestamp"));
            objectMap.put("nonceStr" , map.get("noncestr"));
            objectMap.put("signature" , WxUtils.getSHA1(map));

            log.info("拼接objectMap"+ objectMap);

            return ResponseMsgUtil.success(objectMap);
        } catch (Exception e) {
            return null;
        }

    }

    @RequestMapping(value = "/getScheme", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取小程序scheme码")
    public ResponseData getSchemeCode()  {

        try {

            JSONObject postObject = new JSONObject();
            postObject.put("expire_type" ,1);
            postObject.put("expire_interval" ,30);
            JSONObject object = HttpsUtils.doPost("https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + weChatQrcodeUtils.getWxToken(false), postObject);
            return ResponseMsgUtil.success(object);
        } catch (Exception e) {
            return null;
        }

    }

    @RequestMapping(value = "/createMenu", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "创建菜单")
    public ResponseData createMenu(@RequestBody JSONObject object) {
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("appid", SysConst.getSysConfig().getWxH5AppId());
            params.put("secret", SysConst.getSysConfig().getWxH5AppSecret());
            params.put("grant_type", "client_credential");

            JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params);
            if (accessTokenObject == null) {
                log.error("getH5UserInfo error!", "获取微信access_token失败"  );
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取微信access_token失败");
            }

            JSONObject jsonObject = HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessTokenObject.getString("access_token"), object);

            return ResponseMsgUtil.success(jsonObject);

        } catch (Exception e) {
            return ResponseMsgUtil.exception(e);
        }
    }



//    @RequestMapping(value = "/verifyWx", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation(value = "微信签名")
//    public String verifyWx()  {
//
//        try {
//
//            Map<String, Object> params = new HashMap<>();
//            params.put("appid", SysConst.getSysConfig().getWxH5AppId());
//            params.put("secret", SysConst.getSysConfig().getWxH5AppSecret());
//            params.put("grant_type", "client_credential");
//
//            JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params);
//
//            Map<String, Object> map = new HashMap<>();
//            map.put("noncestr","Wm3WZYTPz0wzccnW");
//            map.put("jsapi_ticket",accessTokenObject.getString("ticket"));
//            map.put("timestamp","1414587457");
//            map.put("url","http://mp.weixin.qq.com?params=value");
//
//            return WxUtils.getSHA1(map);
//        } catch (Exception e) {
//            return null;
//        }
//
//    }


}
