From 03c2a0e5e66fe9c76a154d4071885bf64feb0d91 Mon Sep 17 00:00:00 2001 From: lujiang Date: Fri, 3 Jan 2025 21:53:27 +0800 Subject: [PATCH] =?UTF-8?q?pc=E7=AB=AF=E6=89=AB=E7=A0=81=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/mobile/WxScanController.java | 34 ++++++++++--- .../ics-web/src/main/resources/tips.html | 50 +++++++++++++++++++ 2 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 shoot-hand/ics-web/src/main/resources/tips.html diff --git a/shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxScanController.java b/shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxScanController.java index 94d72f6..f28f565 100644 --- a/shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxScanController.java +++ b/shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxScanController.java @@ -13,6 +13,7 @@ import com.ics.system.service.IRoleService; import com.ics.system.service.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ClassPathResource; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -22,7 +23,9 @@ import org.wf.jwtp.provider.Token; import org.wf.jwtp.provider.TokenStore; import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.URLEncoder; import java.util.List; import java.util.UUID; @@ -70,6 +73,12 @@ public class WxScanController { private final static String OAUTH2_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; + private static String tipsHtml; + + static { + tipsHtml = readHtml("tips.html"); + } + /** * 获取认证标识及url,有效期1小时 * 返回 @@ -80,7 +89,7 @@ public class WxScanController { @RequestMapping("/get") public R index() throws IOException { String uuid = UUID.randomUUID().toString().replaceAll("-", ""); - redis.set("QR:" + uuid, "",3600); + redis.set("QR:" + uuid, "", 3600); String redirectUrl = access + "/wxscan/goin/" + uuid; String encodedUrl = URLEncoder.encode(redirectUrl, "UTF-8"); String url = String.format(OAUTH2_URL, appid, encodedUrl); @@ -117,10 +126,10 @@ public class WxScanController { redis.set("QR:" + unique, token.getAccessToken(), 3600);//存储token值 return "扫码成功"; } else { - return "未在公众号绑定手机号或者小程序账号与PC账号未关联"; + return String.format(tipsHtml, "小程序账号与PC账号端未关联"); } } else { //未绑定 - return "请先在公众号绑定手机号"; + return String.format(tipsHtml, "在下面小程序注册后,再绑定手机号"); } // System.out.println("**************************"); // System.out.println(sToken); @@ -136,9 +145,8 @@ public class WxScanController { * 轮询是否登录 * 参数:unique 认证标识,为get接口获取的字符串 * 返回: - * code 为500时表示未成功扫码 - * code 为0 时,表示已经成功扫码登录,可以获取token值 - * + * code 为500时表示未成功扫码 + * code 为0 时,表示已经成功扫码登录,可以获取token值 */ @Ignore @RequestMapping("/isLogin/{unique}") @@ -148,5 +156,17 @@ public class WxScanController { return R.ok().put("token", token); } - + private static String readHtml(String fileName) { + StringBuilder sb = new StringBuilder(); + ClassPathResource resource = new ClassPathResource(fileName); + try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()))) { + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + return sb.toString(); + } } diff --git a/shoot-hand/ics-web/src/main/resources/tips.html b/shoot-hand/ics-web/src/main/resources/tips.html new file mode 100644 index 0000000..3c62eb1 --- /dev/null +++ b/shoot-hand/ics-web/src/main/resources/tips.html @@ -0,0 +1,50 @@ + + + + + + + 提示 + + + + +
+ +
+ +