package com.szwl.controller; import cn.com.crbank.ommo.exception.MyException; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.sun.org.apache.regexp.internal.RE; import com.szwl.constant.ResponseCodesEnum; import com.szwl.model.bo.R; //import com.szwl.model.dto.WechatDTO; import com.szwl.model.entity.TAdmin; import com.szwl.model.entity.TWechat; import com.szwl.model.utils.DateUtils; import com.szwl.model.utils.HttpClientUtils; import com.szwl.service.TAdminService; import com.szwl.service.TWechatService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpHeaders; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.LaxRedirectStrategy; import org.apache.http.util.EntityUtils; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.view.RedirectView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.security.MessageDigest; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; /** *
* 前端控制器 *
* * @author wuhs * @since 2023-05-19 */ @Slf4j @Api(value = "/WeChatController", tags = {"微信绑定接口"}) @RestController @RequestMapping("/tWechat") public class TWechatController { @Autowired private TAdminService tAdminService; @Autowired private TWechatService tWechatService; // 从 yml 文件中获取 @Value("${oauth.wx.appid}") private String appid; @Value("${oauth.wx.appsecret}") private String appsecret; @Value("${oauth.callback.http:http://szwltest.sunzee.com.cn:49002}") private String http; @ApiOperation(value = "绑定微信") @GetMapping("/bindWechat") public R bindWechat(@RequestParam Long adminId) throws Exception { if (adminId==null) { throw new MyException("参数为空"); } TAdmin tAdmin = tAdminService.getById(adminId); TWechat tWechat = new TWechat(); if (tAdmin != null) { List