| | |
| | | import com.dsh.other.util.TokenUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** 对外下载引导页与 App 扫码解析接口。 */ |
| | | @RestController |
| | | @Api(tags = "APP下载引导与场地二维码") |
| | | public class AppGuideController { |
| | | @Autowired private AppGuideConfigMapper appGuideConfigMapper; |
| | | @Autowired private AppGuideBannerMapper appGuideBannerMapper; |
| | | @Autowired private QrLinkMapper qrLinkMapper; |
| | | @Autowired private TokenUtil tokenUtil; |
| | | @Autowired |
| | | private AppGuideConfigMapper appGuideConfigMapper; |
| | | |
| | | @Autowired |
| | | private AppGuideBannerMapper appGuideBannerMapper; |
| | | |
| | | @Autowired |
| | | private QrLinkMapper qrLinkMapper; |
| | | |
| | | @Autowired |
| | | private TokenUtil tokenUtil; |
| | | |
| | | // @GetMapping("/q/{shortCode}") |
| | | // public void guidePage(@PathVariable String shortCode, HttpServletRequest request, |
| | |
| | | @ApiOperation("获取下载引导页配置(无需登录)") |
| | | public ResultUtil<Map<String, Object>> guideConfig(String code) { |
| | | AppGuideConfig config = appGuideConfigMapper.selectOne(new QueryWrapper<AppGuideConfig>() |
| | | .eq("enabled", EnableStatusEnum.ENABLED.getCode()).orderByDesc("updateTime").last("limit 1")); |
| | | if (config == null) return ResultUtil.error("下载引导页尚未配置"); |
| | | .eq("enabled", EnableStatusEnum.ENABLED.getCode()) |
| | | .orderByDesc("updateTime") |
| | | .last("limit 1")); |
| | | if (config == null) { |
| | | return ResultUtil.error("下载引导页尚未配置"); |
| | | } |
| | | QrLink link = validLink(code); |
| | | if (code != null && !code.isEmpty() && link == null) return ResultUtil.error("二维码无效或已失效"); |
| | | if (code != null && !code.isEmpty() && link == null) { |
| | | return ResultUtil.error("二维码无效或已失效"); |
| | | } |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("appName", config.getAppName()); |
| | | data.put("androidPackage", config.getAndroidPackage()); |
| | | data.put("iosPackage", config.getIosPackage()); |
| | | data.put("appName", StringUtils.isNotBlank(config.getAppName()) ? config.getAppName() : "玩湃生活"); |
| | | data.put("androidPackage", StringUtils.isNotBlank(config.getAndroidPackage()) ? config.getAndroidPackage() : "com.sinata.wepark"); |
| | | data.put("iosPackage", StringUtils.isNotBlank(config.getIosPackage()) ? config.getIosPackage() : "com.sinata.WeParkLife"); |
| | | data.put("iosStoreUrl", config.getIosStoreUrl()); |
| | | data.put("apkUrl", config.getApkUrl()); |
| | | data.put("androidDeepLink", config.getAndroidDeepLink()); |
| | | data.put("iosDeepLink", config.getIosDeepLink()); |
| | | data.put("androidDeepLink", config.getAndroidDeepLink() + (StringUtils.isNotBlank(code) ? "?route=" + code : "")); |
| | | data.put("iosDeepLink", "weparklife://app" + (StringUtils.isNotBlank(code) ? "?code=" + code : "")); |
| | | data.put("banners", appGuideBannerMapper.selectList(new QueryWrapper<AppGuideBanner>() |
| | | .eq("enabled", EnableStatusEnum.ENABLED.getCode()).orderByAsc("sort").orderByDesc("id"))); |
| | | .eq("enabled", EnableStatusEnum.ENABLED.getCode()) |
| | | .orderByAsc("sort") |
| | | .orderByDesc("id"))); |
| | | // if (link != null) data.put("target", target(link)); |
| | | return ResultUtil.success(data); |
| | | } |
| | |
| | | @ApiOperation("App扫码解析二维码") |
| | | public ResultUtil<Map<String, Object>> resolve(String code) { |
| | | QrLink link = validLink(code); |
| | | if (link == null) return ResultUtil.error("二维码无效或已失效"); |
| | | if (link == null) { |
| | | return ResultUtil.error("二维码无效或已失效"); |
| | | } |
| | | return ResultUtil.success(target(link)); |
| | | } |
| | | |
| | | private QrLink validLink(String code) { |
| | | if (code == null || !code.matches("[A-Za-z0-9]{6,32}")) return null; |
| | | QrLink link = qrLinkMapper.selectOne(new QueryWrapper<QrLink>().eq("shortCode", code).last("limit 1")); |
| | | if (code == null || !code.matches("[A-Za-z0-9]{6,32}")) { |
| | | return null; |
| | | } |
| | | QrLink link = qrLinkMapper.selectOne(new QueryWrapper<QrLink>() |
| | | .eq("shortCode", code) |
| | | .last("limit 1")); |
| | | if (link == null || !Integer.valueOf(1).equals(link.getEnabled()) |
| | | || (link.getExpiresAt() != null && link.getExpiresAt().before(new Date()))) return null; |
| | | || (link.getExpiresAt() != null && link.getExpiresAt().before(new Date()))) { |
| | | return null; |
| | | } |
| | | return link; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private Object parseJson(String text) { |
| | | if (text == null || text.trim().isEmpty()) return Collections.emptyMap(); |
| | | try { return JSON.parseObject(text); } catch (Exception ignored) { return Collections.emptyMap(); } |
| | | if (text == null || text.trim().isEmpty()) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | try { |
| | | return JSON.parseObject(text); |
| | | } catch (Exception ignored) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | } |
| | | } |