|
|
@@ -1,8 +1,11 @@
|
|
|
package com.cyksj.service.wechat.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.http.ssl.SSLSocketFactoryBuilder;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
@@ -16,6 +19,8 @@ import com.cyksj.mapper.channel.ShopConfigMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
|
import com.cyksj.model.entity.ShopConfig;
|
|
|
import com.cyksj.model.entity.WxApp;
|
|
|
+import com.cyksj.model.response.WxGzhQrCodeTicketRep;
|
|
|
+import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.service.wechat.WxMpAccountOps;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -60,6 +65,8 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
|
|
|
private final ShopConfigMapper shopConfigMapper;
|
|
|
|
|
|
+ private final RedisService redisService;
|
|
|
+
|
|
|
@Override
|
|
|
public String createUrl(String state, String redirectUrl) {
|
|
|
return createUrl(state,redirectUrl,weChatConfig.getAppid(), WeChatAuthRedirectUrl.BASE.getScope());
|
|
|
@@ -471,6 +478,33 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
log.info("------------------- 调用微信申请退款 结束 -------------------");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public WxGzhQrCodeTicketRep getWxGzhQrCode() throws Exception {
|
|
|
+ String gzhQrCodeUrl = String.format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s", this.getAccessToken());
|
|
|
+ //scene_str:场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
|
|
|
+ String scene_str = RandomUtil.randomString(16);
|
|
|
+ DateTime dateTime = DateUtil.offsetSecond(DateTime.now(), 60);
|
|
|
+ String body = String.format("{\"expire_seconds\": %s, \"action_name\": \"%s\", \"action_info\": {\"scene\": {\"scene_str\": %s}}}",
|
|
|
+ 60,
|
|
|
+ "QR_STR_SCENE",
|
|
|
+ scene_str);
|
|
|
+ HttpResponse<String> response = J11HttpC.custom()
|
|
|
+ .url(gzhQrCodeUrl)
|
|
|
+ .ofPost()
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(body))
|
|
|
+ .send(HttpResponse.BodyHandlers.ofString());
|
|
|
+ if (200 != response.statusCode()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("获取微信登录二维码失败: " + response.body());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject re = Jsons.parseObject(response.body(), JSONObject.class);
|
|
|
+ String ticket = re.getStr("ticket");
|
|
|
+ WxGzhQrCodeTicketRep wxGzhQrCodeTicketRep = new WxGzhQrCodeTicketRep();
|
|
|
+ wxGzhQrCodeTicketRep.setQrCodeUrl(String.format("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s", ticket));
|
|
|
+ wxGzhQrCodeTicketRep.setSceneStr(scene_str);
|
|
|
+ wxGzhQrCodeTicketRep.setExpireTime(dateTime.getTime());
|
|
|
+ return wxGzhQrCodeTicketRep;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* sha256_HMAC加密
|