瀏覽代碼

腾讯云sdk接入,短信接口引入人机验证

ZhangWenQiang 5 年之前
父節點
當前提交
a171981c36

+ 502 - 474
happy-job-base-common/src/main/java/com/jeeplus/common/config/Global.java

@@ -1,474 +1,502 @@
-/**
- * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
- */
-package com.jeeplus.common.config;
-
-import java.io.*;
-import java.net.URLDecoder;
-import java.util.Map;
-import java.util.Properties;
-
-import com.jeeplus.common.utils.FileUtils;
-import com.jeeplus.core.web.Servlets;
-import com.jeeplus.modules.sys.security.SystemAuthorizingRealm;
-import com.jeeplus.modules.sys.utils.UserUtils;
-import org.apache.ibatis.io.Resources;
-import org.springframework.core.io.DefaultResourceLoader;
-
-import com.google.common.collect.Maps;
-import com.jeeplus.common.utils.PropertiesLoader;
-import com.jeeplus.common.utils.StringUtils;
-
-/**
- * 全局配置类
- *
- * @author jeeplus
- * @version 2017-06-25
- */
-public class Global {
-
-    /**
-     * 当前对象实例
-     */
-    private static Global global = new Global();
-
-    /**
-     * 保存全局属性值
-     */
-    private static Map<String, String> map = Maps.newHashMap();
-
-    /**
-     * 属性文件加载对象
-     */
-    private static PropertiesLoader loader = new PropertiesLoader("/properties/jeeplus.properties");
-
-    /**
-     * 显示/隐藏
-     */
-    public static final String SHOW = "1";
-    public static final String HIDE = "0";
-
-    /**
-     * 是/否
-     */
-    public static final String YES = "1";
-    public static final String NO = "0";
-
-    /**
-     * 对/错
-     */
-    public static final String TRUE = "true";
-    public static final String FALSE = "false";
-
-    /**
-     * 编码格式
-     */
-    public static final String charset = "utf-8";
-
-    /**
-     * 上传文件到oss的基础虚拟路径
-     */
-    public static final String USERFILES_BASE_URL = "uploadfiles";
-
-    /**
-     * 上传文件到本地的基础虚拟路径
-     */
-    public static final String USERFILES_BASE_LOCALURL = "/uploadfiles/";
-
-    /**
-     * 共享文档物理存储地址
-     *
-     * @return
-     */
-    public static String getShareBaseDir() {
-        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_LOCALURL + "共享文档/";
-        FileUtils.createDirectory(dir);
-        return dir;
-    }
-
-    /**
-     * 共享文档网络访问地址
-     *
-     * @return
-     */
-    public static String getShareBaseUrl() {
-        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
-        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_LOCALURL + "/共享文档/";
-    }
-
-    /**
-     * 我的文档物理存储地址
-     *
-     * @return
-     */
-    public static String getMyDocDir() {
-        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
-        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_LOCALURL + principal + "/我的文档/";
-        FileUtils.createDirectory(dir);
-        return dir;
-    }
-
-    /**
-     * 我的文档网络访问地址
-     *
-     * @return
-     */
-    public static String getMyDocUrl() {
-        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
-        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_LOCALURL + principal + "/我的文档/";
-    }
-
-    /**
-     * 程序附件物理存储地址
-     *
-     * @return
-     */
-    public static String getAttachmentDir() {
-        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
-        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_LOCALURL + principal + "/";
-        FileUtils.createDirectory(dir);
-        return dir;
-    }
-
-    /**
-     * 程序附件网络访问地址
-     *
-     * @return
-     */
-    public static String getAttachmentUrl() {
-
-        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
-        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_LOCALURL + principal + "/";
-    }
-
-    /**
-     * 绝对地址转换为网络地址
-     *
-     * @return
-     */
-    public static String transDirToUrl(String dir) {
-        return Servlets.getRequest().getContextPath() + "/" + dir.substring(Global.getUserfilesBaseDir().length());
-    }
-
-    /**
-     * 获取当前对象实例
-     */
-    public static Global getInstance() {
-        return global;
-    }
-
-    /**
-     * 获取配置
-     */
-    public static String getConfig(String key) {
-        String value = map.get(key);
-        if (value == null) {
-            value = loader.getProperty(key);
-            map.put(key, value != null ? value : StringUtils.EMPTY);
-        }
-        return value;
-    }
-
-    /**
-     * 获取管理端根路径
-     */
-    public static String getAdminPath() {
-        return getConfig("adminPath");
-    }
-
-
-    /**
-     * 获取管理端根路径
-     */
-    public static String getDefaultTheme() {
-        return getConfig("defaultTheme");
-    }
-
-    /**
-     * 获取前端根路径
-     */
-    public static String getFrontPath() {
-        return getConfig("frontPath");
-    }
-
-    /**
-     * 获取URL后缀
-     */
-    public static String getUrlSuffix() {
-        return getConfig("urlSuffix");
-    }
-
-    /**
-     * 253短信账号
-     *
-     * @return
-     */
-    public static String getSmsAccount() {
-
-        return getConfig("sms.account");
-    }
-
-    /**
-     * 253短信密码
-     *
-     * @return
-     */
-    public static String getSmsPassword() {
-        return getConfig("sms.password");
-    }
-
-    /**
-     * 253短信地址
-     *
-     * @return
-     */
-    public static String getSmsUrl() {
-        return getConfig("sms.smsUrl");
-    }
-
-    /**
-     * 当前服务器路径
-     *
-     * @return
-     */
-    public static String getServicePath() {
-        return getConfig("servicePath");
-    }
-
-    /**
-     * 支付域名
-     *
-     * @return
-     */
-    public static String getPayPath() {
-        return getConfig("payPath");
-    }
-
-    /**
-     */
-    public static String getAliyunUrl() {
-        return getConfig("aliyunUrl");
-    }
-
-    /**
-     */
-    public static String getAliDownloadUrl() {
-        return getConfig("aliyunDownloadUrl");
-    }
-
-    /**
-     */
-    public static String getOSSUrl() {
-        return getConfig("oSSUrl");
-    }
-
-    /**
-     */
-    public static String getEndpoint() {
-        return getConfig("endpoint");
-    }
-
-    /**
-     */
-    public static String getAccessKeyId() {
-        return getConfig("accessKeyId");
-    }
-
-    /**
-     */
-    public static String getAccessKeySecret() {
-        return getConfig("accessKeySecret");
-    }
-
-    /**
-     */
-    public static String getBucketName() {
-        return getConfig("bucketName");
-    }
-
-
-    /**
-     * 小程序appid
-     */
-    public static String getAppId() {
-        return getConfig("appid");
-    }
-
-
-    /**
-     */
-    public static String getAppsecret() {
-        return getConfig("appsecret");
-    }
-
-    /**
-     * 微信授权appid
-     */
-    public static String getWxAppId() {
-        return getConfig("wxappid");
-    }
-
-
-    /**
-     */
-    public static String getWxAppsecret() {
-        return getConfig("wxappsecret");
-    }
-
-    /**
-     * crmautodate
-     *
-     * @return
-     */
-    public static String getCrmAutoDate() {
-        return getConfig("crmautodate");
-    }
-
-    /**
-     * 备案号
-     */
-    public static String getBeian() {
-        return getConfig("beian");
-    }
-
-    /**
-     * 253短信签名
-     *
-     * @return
-     */
-    public static String getSmsSign() {
-        String smsSign = getConfig("sms.smsSign");
-        // *.properties文件中的中文默认以ISO-8859-1方式编码,因此需要对中文内容进行重新编码
-        try {
-            return URLDecoder.decode(smsSign, charset);
-        } catch (UnsupportedEncodingException e) {
-            e.printStackTrace();
-        }
-        return smsSign;
-    }
-
-    /**
-     * 未登录描述
-     */
-    public static String getNoLogin() {
-        return getConfig("noLogin");
-    }
-
-    /**
-     * 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
-     */
-    public static Boolean isDemoMode() {
-        String dm = getConfig("demoMode");
-        return "true".equals(dm) || "1".equals(dm);
-    }
-
-    /**
-     * 在修改系统用户和角色时是否同步到Activiti
-     */
-    public static Boolean isSynActivitiIndetity() {
-        String dm = getConfig("activiti.isSynActivitiIndetity");
-        return "true".equals(dm) || "1".equals(dm);
-    }
-
-    /**
-     * 页面获取常量
-     */
-    public static Object getConst(String field) {
-        try {
-            return Global.class.getField(field).get(null);
-        } catch (Exception e) {
-            // 异常代表无配置,这里什么也不做
-        }
-        return null;
-    }
-
-    /**
-     * 获取上传文件的根目录
-     *
-     * @return
-     */
-    public static String getUserfilesBaseDir() {
-        String dir = getConfig("userfiles.basedir");
-        if (StringUtils.isBlank(dir)) {
-            return Servlets.getRequest().getContextPath();
-        }
-        if (!dir.endsWith("/")) {
-            dir += "/";
-        }
-//		System.out.println("userfiles.basedir: " + dir);
-        return dir;
-    }
-
-    /**
-     * 获取工程路径
-     *
-     * @return
-     */
-    public static String getProjectPath() {
-        // 如果配置了工程路径,则直接返回,否则自动获取。
-        String projectPath = Global.getConfig("projectPath");
-        if (StringUtils.isNotBlank(projectPath)) {
-            return projectPath;
-        }
-        try {
-            File file = new DefaultResourceLoader().getResource("").getFile();
-            if (file != null) {
-                while (true) {
-                    File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
-                    if (f == null || f.exists()) {
-                        break;
-                    }
-                    if (file.getParentFile() != null) {
-                        file = file.getParentFile();
-                    } else {
-                        break;
-                    }
-                }
-                projectPath = file.toString();
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return projectPath;
-    }
-
-    /**
-     * 写入properties信息
-     *
-     * @param key   名称
-     * @param value 值
-     */
-    public static void modifyConfig(String key, String value) {
-        try {
-            // 从输入流中读取属性列表(键和元素对)
-            Properties prop = getProperties();
-            prop.setProperty(key, value);
-            String path = Global.class.getResource("/properties/jeeplus.properties").getPath();
-            FileOutputStream outputFile = new FileOutputStream(path);
-            prop.store(outputFile, "modify");
-            outputFile.close();
-            outputFile.flush();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     * 返回 Properties
-     *
-     * @param
-     * @return
-     */
-    public static Properties getProperties() {
-        Properties prop = new Properties();
-        try {
-            Reader reader = Resources.getResourceAsReader("/properties/jeeplus.properties");
-            prop.load(reader);
-        } catch (Exception e) {
-            return null;
-        }
-        return prop;
-    }
-
-
-}
+/**
+ * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
+ */
+package com.jeeplus.common.config;
+
+import java.io.*;
+import java.net.URLDecoder;
+import java.util.Map;
+import java.util.Properties;
+
+import com.jeeplus.common.utils.FileUtils;
+import com.jeeplus.core.web.Servlets;
+import com.jeeplus.modules.sys.security.SystemAuthorizingRealm;
+import com.jeeplus.modules.sys.utils.UserUtils;
+import org.apache.ibatis.io.Resources;
+import org.springframework.core.io.DefaultResourceLoader;
+
+import com.google.common.collect.Maps;
+import com.jeeplus.common.utils.PropertiesLoader;
+import com.jeeplus.common.utils.StringUtils;
+
+/**
+ * 全局配置类
+ *
+ * @author jeeplus
+ * @version 2017-06-25
+ */
+public class Global {
+
+    /**
+     * 当前对象实例
+     */
+    private static Global global = new Global();
+
+    /**
+     * 保存全局属性值
+     */
+    private static Map<String, String> map = Maps.newHashMap();
+
+    /**
+     * 属性文件加载对象
+     */
+    private static PropertiesLoader loader = new PropertiesLoader("/properties/jeeplus.properties");
+
+    /**
+     * 显示/隐藏
+     */
+    public static final String SHOW = "1";
+    public static final String HIDE = "0";
+
+    /**
+     * 是/否
+     */
+    public static final String YES = "1";
+    public static final String NO = "0";
+
+    /**
+     * 对/错
+     */
+    public static final String TRUE = "true";
+    public static final String FALSE = "false";
+
+    /**
+     * 编码格式
+     */
+    public static final String charset = "utf-8";
+
+    /**
+     * 上传文件到oss的基础虚拟路径
+     */
+    public static final String USERFILES_BASE_URL = "uploadfiles";
+
+    /**
+     * 上传文件到本地的基础虚拟路径
+     */
+    public static final String USERFILES_BASE_LOCALURL = "/uploadfiles/";
+
+    /**
+     * 共享文档物理存储地址
+     *
+     * @return
+     */
+    public static String getShareBaseDir() {
+        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_LOCALURL + "共享文档/";
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
+
+    /**
+     * 共享文档网络访问地址
+     *
+     * @return
+     */
+    public static String getShareBaseUrl() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_LOCALURL + "/共享文档/";
+    }
+
+    /**
+     * 我的文档物理存储地址
+     *
+     * @return
+     */
+    public static String getMyDocDir() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_LOCALURL + principal + "/我的文档/";
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
+
+    /**
+     * 我的文档网络访问地址
+     *
+     * @return
+     */
+    public static String getMyDocUrl() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_LOCALURL + principal + "/我的文档/";
+    }
+
+    /**
+     * 程序附件物理存储地址
+     *
+     * @return
+     */
+    public static String getAttachmentDir() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_LOCALURL + principal + "/";
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
+
+    /**
+     * 程序附件网络访问地址
+     *
+     * @return
+     */
+    public static String getAttachmentUrl() {
+
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_LOCALURL + principal + "/";
+    }
+
+    /**
+     * 绝对地址转换为网络地址
+     *
+     * @return
+     */
+    public static String transDirToUrl(String dir) {
+        return Servlets.getRequest().getContextPath() + "/" + dir.substring(Global.getUserfilesBaseDir().length());
+    }
+
+    /**
+     * 获取当前对象实例
+     */
+    public static Global getInstance() {
+        return global;
+    }
+
+    /**
+     * 获取配置
+     */
+    public static String getConfig(String key) {
+        String value = map.get(key);
+        if (value == null) {
+            value = loader.getProperty(key);
+            map.put(key, value != null ? value : StringUtils.EMPTY);
+        }
+        return value;
+    }
+
+    /**
+     * 获取管理端根路径
+     */
+    public static String getAdminPath() {
+        return getConfig("adminPath");
+    }
+
+
+    /**
+     * 获取管理端根路径
+     */
+    public static String getDefaultTheme() {
+        return getConfig("defaultTheme");
+    }
+
+    /**
+     * 获取前端根路径
+     */
+    public static String getFrontPath() {
+        return getConfig("frontPath");
+    }
+
+    /**
+     * 获取URL后缀
+     */
+    public static String getUrlSuffix() {
+        return getConfig("urlSuffix");
+    }
+
+    /**
+     * 253短信账号
+     *
+     * @return
+     */
+    public static String getSmsAccount() {
+
+        return getConfig("sms.account");
+    }
+
+    /**
+     * 253短信密码
+     *
+     * @return
+     */
+    public static String getSmsPassword() {
+        return getConfig("sms.password");
+    }
+
+    /**
+     * 253短信地址
+     *
+     * @return
+     */
+    public static String getSmsUrl() {
+        return getConfig("sms.smsUrl");
+    }
+
+    /**
+     * 当前服务器路径
+     *
+     * @return
+     */
+    public static String getServicePath() {
+        return getConfig("servicePath");
+    }
+
+    /**
+     * 支付域名
+     *
+     * @return
+     */
+    public static String getPayPath() {
+        return getConfig("payPath");
+    }
+
+    /**
+     */
+    public static String getAliyunUrl() {
+        return getConfig("aliyunUrl");
+    }
+
+    /**
+     */
+    public static String getAliDownloadUrl() {
+        return getConfig("aliyunDownloadUrl");
+    }
+
+    /**
+     */
+    public static String getOSSUrl() {
+        return getConfig("oSSUrl");
+    }
+
+    /**
+     */
+    public static String getEndpoint() {
+        return getConfig("endpoint");
+    }
+
+    /**
+     */
+    public static String getAccessKeyId() {
+        return getConfig("accessKeyId");
+    }
+
+    /**
+     */
+    public static String getAccessKeySecret() {
+        return getConfig("accessKeySecret");
+    }
+
+    /**
+     */
+    public static String getBucketName() {
+        return getConfig("bucketName");
+    }
+
+
+    /**
+     * 小程序appid
+     */
+    public static String getAppId() {
+        return getConfig("appid");
+    }
+
+
+    /**
+     */
+    public static String getAppsecret() {
+        return getConfig("appsecret");
+    }
+
+    /**
+     * 微信授权appid
+     */
+    public static String getWxAppId() {
+        return getConfig("wxappid");
+    }
+
+
+    /**
+     */
+    public static String getWxAppsecret() {
+        return getConfig("wxappsecret");
+    }
+
+    /**
+     * crmautodate
+     *
+     * @return
+     */
+    public static String getCrmAutoDate() {
+        return getConfig("crmautodate");
+    }
+
+    /**
+     * 备案号
+     */
+    public static String getBeian() {
+        return getConfig("beian");
+    }
+
+    /**
+     * 腾讯云验证码个人秘钥id
+     */
+    public static String getSecretId() {
+        return getConfig("secretId");
+    }
+
+    /**
+     * 腾讯云验证码个人秘钥
+     */
+    public static String getSecretKey() {
+        return getConfig("secretKey");
+    }
+
+    /**
+     * 腾讯云验证码应用ID
+     */
+    public static String getCaptchaAppId() {
+        return getConfig("captchaAppId");
+    }
+
+    /**
+     * 腾讯云验证码应用秘钥
+     */
+    public static String getCaptchaAppSecret() {
+        return getConfig("captchaAppSecret");
+    }
+
+    /**
+     * 253短信签名
+     *
+     * @return
+     */
+    public static String getSmsSign() {
+        String smsSign = getConfig("sms.smsSign");
+        // *.properties文件中的中文默认以ISO-8859-1方式编码,因此需要对中文内容进行重新编码
+        try {
+            return URLDecoder.decode(smsSign, charset);
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return smsSign;
+    }
+
+    /**
+     * 未登录描述
+     */
+    public static String getNoLogin() {
+        return getConfig("noLogin");
+    }
+
+    /**
+     * 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
+     */
+    public static Boolean isDemoMode() {
+        String dm = getConfig("demoMode");
+        return "true".equals(dm) || "1".equals(dm);
+    }
+
+    /**
+     * 在修改系统用户和角色时是否同步到Activiti
+     */
+    public static Boolean isSynActivitiIndetity() {
+        String dm = getConfig("activiti.isSynActivitiIndetity");
+        return "true".equals(dm) || "1".equals(dm);
+    }
+
+    /**
+     * 页面获取常量
+     */
+    public static Object getConst(String field) {
+        try {
+            return Global.class.getField(field).get(null);
+        } catch (Exception e) {
+            // 异常代表无配置,这里什么也不做
+        }
+        return null;
+    }
+
+    /**
+     * 获取上传文件的根目录
+     *
+     * @return
+     */
+    public static String getUserfilesBaseDir() {
+        String dir = getConfig("userfiles.basedir");
+        if (StringUtils.isBlank(dir)) {
+            return Servlets.getRequest().getContextPath();
+        }
+        if (!dir.endsWith("/")) {
+            dir += "/";
+        }
+//		System.out.println("userfiles.basedir: " + dir);
+        return dir;
+    }
+
+    /**
+     * 获取工程路径
+     *
+     * @return
+     */
+    public static String getProjectPath() {
+        // 如果配置了工程路径,则直接返回,否则自动获取。
+        String projectPath = Global.getConfig("projectPath");
+        if (StringUtils.isNotBlank(projectPath)) {
+            return projectPath;
+        }
+        try {
+            File file = new DefaultResourceLoader().getResource("").getFile();
+            if (file != null) {
+                while (true) {
+                    File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
+                    if (f == null || f.exists()) {
+                        break;
+                    }
+                    if (file.getParentFile() != null) {
+                        file = file.getParentFile();
+                    } else {
+                        break;
+                    }
+                }
+                projectPath = file.toString();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return projectPath;
+    }
+
+    /**
+     * 写入properties信息
+     *
+     * @param key   名称
+     * @param value 值
+     */
+    public static void modifyConfig(String key, String value) {
+        try {
+            // 从输入流中读取属性列表(键和元素对)
+            Properties prop = getProperties();
+            prop.setProperty(key, value);
+            String path = Global.class.getResource("/properties/jeeplus.properties").getPath();
+            FileOutputStream outputFile = new FileOutputStream(path);
+            prop.store(outputFile, "modify");
+            outputFile.close();
+            outputFile.flush();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 返回 Properties
+     *
+     * @param
+     * @return
+     */
+    public static Properties getProperties() {
+        Properties prop = new Properties();
+        try {
+            Reader reader = Resources.getResourceAsReader("/properties/jeeplus.properties");
+            prop.load(reader);
+        } catch (Exception e) {
+            return null;
+        }
+        return prop;
+    }
+
+
+}

+ 44 - 37
happy-job-module-hpjob/pom.xml

@@ -1,38 +1,45 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>happyjob-parent</artifactId>
-        <groupId>com.happyjob</groupId>
-        <version>1.0-SNAPSHOT</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>happy-job-module-hpjob</artifactId>
-    <version>1.0-SNAPSHOT</version>
-    <packaging>jar</packaging>
-
-    <build>
-        <resources>
-            <resource>
-                <directory>src/main/java</directory>
-                <includes>
-                    <include>**/*.xml</include>
-                </includes>
-            </resource>
-            <resource>
-                <directory>src/main/resources</directory>
-            </resource>
-        </resources>
-    </build>
-
-    <dependencies>
-        <dependency>
-            <groupId>com.happyjob</groupId>
-            <artifactId>happy-job-base-common</artifactId>
-            <version>1.0-SNAPSHOT</version>
-        </dependency>
-    </dependencies>
-
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>happyjob-parent</artifactId>
+        <groupId>com.happyjob</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>happy-job-module-hpjob</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/java</directory>
+                <includes>
+                    <include>**/*.xml</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+        </resources>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.happyjob</groupId>
+            <artifactId>happy-job-base-common</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <!--腾讯云sdk-->
+        <dependency>
+            <groupId>com.tencentcloudapi</groupId>
+            <artifactId>tencentcloud-sdk-java</artifactId>
+            <!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询最新版本 -->
+            <version>3.1.88</version>
+        </dependency>
+    </dependencies>
+
 </project>

+ 1 - 1
happy-job-module-hpjob/src/main/java/com/jeeplus/modules/api/sys/LoginAppController.java

@@ -72,7 +72,7 @@ public class LoginAppController extends BaseAppController {
         HashMap<String, String> requestMap = findRequestMap(request);
         Map<String, Object> map = new HashMap<>();
         try {
-            Map<String, Object> returnMap = hpUserService.sendMobileCode(requestMap);
+            Map<String, Object> returnMap = hpUserService.sendMobileCode(requestMap, request);
             if (SMSConst.OKCode.equals(returnMap.get("success"))) {
                 map.put("code", returnMap.get("code"));
                 obj = successResult(ErrorCode.code_1000, "", map);

+ 41 - 2
happy-job-module-hpjob/src/main/java/com/jeeplus/modules/sys/service/HpUserService.java

@@ -13,6 +13,7 @@ import com.jeeplus.common.sms.SMS253Utils;
 import com.jeeplus.common.sms.SMSConst;
 import com.jeeplus.common.utils.CacheUtils;
 import com.jeeplus.common.utils.StringUtils;
+import com.jeeplus.common.utils.api.IPUtil;
 import com.jeeplus.common.utils.api.OtherException;
 import com.jeeplus.core.persistence.Page;
 import com.jeeplus.core.service.CrudService;
@@ -60,6 +61,9 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 /**
@@ -151,18 +155,27 @@ public class HpUserService extends CrudService<HpUserMapper, HpUser> {
     /**
      * 注册发送手机验证码
      */
-    public Map<String, Object> sendMobileCode(HashMap<String, String> hashMap) throws OtherException {
+    public Map<String, Object> sendMobileCode(HashMap<String, String> hashMap, HttpServletRequest request) throws OtherException {
         Map<String, Object> returnMap = new HashMap<String, Object>();
         String mobile = hashMap.get("phone");
         if (StringUtils.isNotEmpty(mobile)) {
             try {
+                //验证码票据验证
+                JSONObject json = getTicketData(hashMap, request);
+                JSONObject jsonObject = TokenUtil.checkTicket(json);
+                logger.info("验证码票据验证========={}", jsonObject.toString());
+                long captchaCode = jsonObject.getLong("CaptchaCode");
+                if (captchaCode != Constants.CAPTCHA_CODE_OK) {
+                    throw new OtherException("10000", "系统内部错误!");
+                }
                 Random random = new Random();
                 String code = "";
                 for (int i = 0; i < 6; i++) {
                     code += random.nextInt(10);
                 }
                 HashMap<String, String> hashMaps = new HashMap<String, String>();
-                hashMaps.put("phone", mobile);// 手机号码
+                // 手机号码
+                hashMaps.put("phone", mobile);
                 hashMaps.put("msg", "亲爱的用户,您的验证码是" + code + ",如非本人操作请忽略!");
                 returnMap = SMS253Utils.sendSms(hashMaps);
                 if (SMSConst.OKCode.equals(returnMap.get("success"))) {
@@ -178,6 +191,31 @@ public class HpUserService extends CrudService<HpUserMapper, HpUser> {
     }
 
     /**
+     * 验证码票据验证请求集合
+     *
+     * @param requestMap
+     * @return
+     */
+    public JSONObject getTicketData(HashMap<String, String> requestMap, HttpServletRequest request) {
+        JSONObject json = new JSONObject();
+        //固定填值:9。可在控制台配置不同验证码类型。
+        json.put("CaptchaType", 9);
+        //前端回调函数返回的用户验证票据
+        String ticket = requestMap.get("ticket");
+        json.put("Ticket", ticket);
+        //用户操作来源的外网 IP
+        json.put("UserIp", IPUtil.getHttpServletRequestIpAddress(request));
+        //前端回调函数返回的随机字符串
+        String randstr = requestMap.get("randstr");
+        json.put("Randstr", randstr);
+        //验证码应用ID
+        json.put("CaptchaAppId", Global.getCaptchaAppId());
+        //验证码票据的验证密钥
+        json.put("AppSecretKey", Global.getCaptchaAppSecret());
+        return json;
+    }
+
+    /**
      * 手机号登录
      *
      * @param requestMap
@@ -2711,6 +2749,7 @@ public class HpUserService extends CrudService<HpUserMapper, HpUser> {
 
     /**
      * 数据看板查询总用户数
+     *
      * @return
      */
     public int findSumUser() {

+ 99 - 90
happy-job-module-hpjob/src/main/java/com/jeeplus/modules/sys/wxUtils/Constants.java

@@ -1,90 +1,99 @@
-package com.jeeplus.modules.sys.wxUtils;
-
-public interface Constants {
-
-    /********************微信小程序接口url************************/
-    /**
-     * 登录地址
-     */
-    public static final String MINA_GETSESSION_URL = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
-
-    /**
-     * 获取微信公众号/小程序:access_token的接口地址(GET) 限2000(次/天)
-     */
-    public static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
-
-    /********************微信服务号接口url************************/
-    /*** 菜单创建(POST) 限100(次/天)*/
-    public static final String MENU_CREATE_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
-    /***菜单查询*/
-    public static final String MENU_GET_URL = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
-    /***菜单删除*/
-    public static final String MENU_DELETE_URL = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
-    /***微信发送消息url*/
-    public static final String SEND_MSG_URL = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";
-    /***获取用户信息*/
-    public static final String USERINFOR_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";
-    //微信发送模板消息url
-    public static String TEMPLATE_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
-
-    /**
-     * 接口只能生成已发布的小程序的二维码
-     * 接口 A 加上接口 C,总共生成的码数量限制为 100,000,请谨慎调用。
-     * 接口 B 调用分钟频率受限(5000次/分钟),如需大量小程序码,建议预生成。
-     */
-    /**
-     * 获取小程序二维码接口 A,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制
-     */
-    public static final String WX_APPLETS_GETWXACODE_URL = "https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN";
-    /**
-     * 获取小程序码接口 C,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制
-     */
-    public static final String WX_APPLETS_CREATEWXAQRCODE_URL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN";
-    /**
-     * 获取小程序码接口 B,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制
-     */
-    public static final String WX_APPLETS_GETWXACODEUNLIMIT_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN";
-
-    /********************app微信授权接口url************************/
-    //获取openid接口和用户access_token
-    public static String OPENID_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=APPSECRET&code=CODE&grant_type=authorization_code";
-    //验证access_token是否有效
-    public static String AUTH_URL = "https://api.weixin.qq.com/sns/auth?access_token=ACCESS_TOKEN&openid=OPENID";
-    //刷新access_token
-    public static String REFRESH_URL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN";
-    /***微信卡券接口中使用的签名凭证api_ticket*/
-    //public static final String JSAPI_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=wx_card";
-    /***微信网页api_ticket*/
-    public static final String JSAPI_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
-    /***下载媒体文件*/
-    public static String DOWNLOAD_MEDIA_URL = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID";
-    /***上传媒体文件*/
-    public static String UPLOAD_MEDIA_URL = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE";
-
-
-    /********************微信服务号返回码值msg************************/
-    public static final String ERRMSG_OK = "ok";
-    /**
-     * 菜单不存在
-     */
-    public static final String ERRMSG_NO_MENU = "menu no exist";
-    /**
-     * 成功
-     */
-    public static final String ERRCODE_0 = "0";
-
-    /**
-     * 微信access_token有效时长 (s)
-     */
-    public static final int WX_ACCESS_TOKEN_AGE = 7150;
-
-    // 编码类型
-    /**
-     * UTF-8
-     */
-    public static final String CODE_TYPE_STR = "utf-8";
-
-    // 小程序二维码宽度
-    public static final int HP_QRCODE_IMAGE_WIDTH = 430;
-
-}
+package com.jeeplus.modules.sys.wxUtils;
+
+public interface Constants {
+
+    /********************微信小程序接口url************************/
+    /**
+     * 登录地址
+     */
+    public static final String MINA_GETSESSION_URL = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
+
+    /**
+     * 获取微信公众号/小程序:access_token的接口地址(GET) 限2000(次/天)
+     */
+    public static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
+
+    /********************微信服务号接口url************************/
+    /*** 菜单创建(POST) 限100(次/天)*/
+    public static final String MENU_CREATE_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
+    /***菜单查询*/
+    public static final String MENU_GET_URL = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
+    /***菜单删除*/
+    public static final String MENU_DELETE_URL = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
+    /***微信发送消息url*/
+    public static final String SEND_MSG_URL = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";
+    /***获取用户信息*/
+    public static final String USERINFOR_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";
+    //微信发送模板消息url
+    public static String TEMPLATE_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
+
+    /**
+     * 接口只能生成已发布的小程序的二维码
+     * 接口 A 加上接口 C,总共生成的码数量限制为 100,000,请谨慎调用。
+     * 接口 B 调用分钟频率受限(5000次/分钟),如需大量小程序码,建议预生成。
+     */
+    /**
+     * 获取小程序二维码接口 A,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制
+     */
+    public static final String WX_APPLETS_GETWXACODE_URL = "https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN";
+    /**
+     * 获取小程序码接口 C,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制
+     */
+    public static final String WX_APPLETS_CREATEWXAQRCODE_URL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN";
+    /**
+     * 获取小程序码接口 B,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制
+     */
+    public static final String WX_APPLETS_GETWXACODEUNLIMIT_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN";
+
+    /********************app微信授权接口url************************/
+    //获取openid接口和用户access_token
+    public static String OPENID_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=APPSECRET&code=CODE&grant_type=authorization_code";
+    //验证access_token是否有效
+    public static String AUTH_URL = "https://api.weixin.qq.com/sns/auth?access_token=ACCESS_TOKEN&openid=OPENID";
+    //刷新access_token
+    public static String REFRESH_URL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN";
+    /***微信卡券接口中使用的签名凭证api_ticket*/
+    //public static final String JSAPI_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=wx_card";
+    /***微信网页api_ticket*/
+    public static final String JSAPI_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
+    /***下载媒体文件*/
+    public static String DOWNLOAD_MEDIA_URL = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID";
+    /***上传媒体文件*/
+    public static String UPLOAD_MEDIA_URL = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE";
+
+
+    /********************腾讯云验证码接口url************************/
+    public static final String CAPTCHA_URL = "https://captcha.tencentcloudapi.com";
+
+    /********************微信服务号返回码值msg************************/
+    public static final String ERRMSG_OK = "ok";
+    /**
+     * 菜单不存在
+     */
+    public static final String ERRMSG_NO_MENU = "menu no exist";
+    /**
+     * 成功
+     */
+    public static final String ERRCODE_0 = "0";
+
+    /**
+     * 微信access_token有效时长 (s)
+     */
+    public static final int WX_ACCESS_TOKEN_AGE = 7150;
+
+    // 编码类型
+    /**
+     * UTF-8
+     */
+    public static final String CODE_TYPE_STR = "utf-8";
+
+    // 小程序二维码宽度
+    public static final int HP_QRCODE_IMAGE_WIDTH = 430;
+
+    /********************腾讯云验证码接口返回状态************************/
+    /**
+     * OK 验证通过
+     */
+    public static final long CAPTCHA_CODE_OK = 0;
+
+}

+ 335 - 296
happy-job-module-hpjob/src/main/java/com/jeeplus/modules/sys/wxUtils/TokenUtil.java

@@ -1,296 +1,335 @@
-package com.jeeplus.modules.sys.wxUtils;
-
-import com.jeeplus.common.utils.FileUtils;
-import com.jeeplus.common.utils.SpringContextHolder;
-import com.jeeplus.modules.sys.entity.HpMember;
-import com.jeeplus.modules.sys.entity.HpUser;
-import com.jeeplus.modules.sys.service.HpMemberService;
-import com.jeeplus.modules.sys.service.HpUserService;
-import net.sf.json.JSONObject;
-import sun.security.krb5.internal.PAData;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-
-/**
- * 微信授权的方法类
- */
-public class TokenUtil {
-    //通过bean机制定义
-    private static HpUserService hpUserService = SpringContextHolder.getBean(HpUserService.class);
-    private static HpMemberService hpMemberService = SpringContextHolder.getBean(HpMemberService.class);
-
-    /**
-     * 验证token有效性
-     *
-     * @param userId
-     * @param token
-     * @return
-     */
-    public static boolean validateToken(String userId, String token) {
-        try {
-            HpUser hpUser = hpUserService.get(userId);
-            if (hpUser != null) {
-                return token.equals(hpUser.getUserToken()) && !hpUser.getUseFlag();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return false;
-    }
-
-    /**
-     * 验证用户是否处于登录态
-     *
-     * @param memberId
-     * @return
-     */
-    public static boolean validateLogin(String memberId, String userId) {
-        try {
-            HpMember hpMember = hpMemberService.get(memberId);
-            if (hpMember != null) {
-                return userId.equals(hpMember.getHpUser().getId());
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return false;
-    }
-
-    /********************app微信授权************************/
-    /**
-     * 验证access_token是否有效
-     *
-     * @param accesstoken
-     * @param user_openid
-     * @return
-     */
-    public static boolean isAccessTokenIsInvalid(String accesstoken, String user_openid) {
-        try {
-            if (accesstoken != null) {
-                String requestUrl = Constants.AUTH_URL.replace("ACCESS_TOKEN", accesstoken).replace("OPENID", user_openid);
-                JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
-                String errcode = result.getString("errcode");
-                if (Constants.ERRCODE_0.equals(errcode)) {
-                    return true;
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return false;
-    }
-
-    /**
-     * 刷新access_token
-     *
-     * @param appid
-     * @param refreshToken
-     * @return
-     */
-    public static JSONObject refreshAccessToken(String appid, String refreshToken) {
-        try {
-            if (refreshToken != null) {
-                String requestUrl = Constants.REFRESH_URL.replace("APPID", appid).replace("REFRESH_TOKEN", refreshToken);
-                JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
-                return result;
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * 日常获取用户access_token
-     *
-     * @param user_id
-     * @return
-     */
-    public static JSONObject getDayAccessToken(String user_id) {
-        JSONObject json_object = new JSONObject();
-        try {
-            HpUser hpUser = hpUserService.get(user_id);
-            if (hpUser != null) {
-                if (hpUser.getAccessTokenEndtime() != null) {
-                    int access_token_endtime = hpUser.getAccessTokenEndtime();
-                    //如果用户access_token有效
-                    if (isAccessTokenIsInvalid(hpUser.getAccessToken(), hpUser.getWxOpenid())
-                            && (int) (System.currentTimeMillis() / 1000) < access_token_endtime) {
-                        json_object.put("access_token", hpUser.getAccessToken());
-                        return json_object;
-                    }
-                    //刷新access_token
-                    json_object = refreshAccessToken(WxAppParamsEnum.PARAMS_APP_JOB.getAppId(), hpUser.getRefreshToken());
-                    return json_object;
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * 用户通过code调用凭证access_token
-     *
-     * @return
-     */
-    public static JSONObject getAccessToken(String code) {
-        try {
-            String requestUrl = Constants.OPENID_URL.replace("APPID", WxAppParamsEnum.PARAMS_APP_JOB.getAppId())
-                    .replace("APPSECRET", WxAppParamsEnum.PARAMS_APP_JOB.getAppSecret()).replace("CODE", code);
-            JSONObject json_object = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
-            return json_object;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * 获取用户信息
-     *
-     * @param accesstoken
-     * @param user_openid
-     * @return
-     */
-    public static JSONObject getWxuser(String accesstoken, String user_openid) {
-        try {
-            String requestUrl = Constants.USERINFOR_URL.replace("ACCESS_TOKEN", accesstoken).replace("OPENID", user_openid);
-            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
-            System.out.println("234ttt---=" + result);
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-
-    /********************小程序授权************************/
-    /**
-     * 小程序获取用户openid
-     *
-     * @param code
-     * @return
-     */
-    public static JSONObject minaGetSession(String code) {
-        try {
-            String requestUrl = Constants.MINA_GETSESSION_URL.replace("APPID", WxAppParamsEnum.PARAMS_APPLETS_JOB.getAppId())
-                    .replace("SECRET", WxAppParamsEnum.PARAMS_APPLETS_JOB.getAppSecret()).replace("JSCODE", code);
-
-            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /********************小程序二维码************************/
-
-    /**
-     * 获取小程序码接口B,适用于需要的码数量极多的业务场景。
-     *
-     * @param accessToken
-     * @param scene
-     * @param page
-     * @param width
-     * @return
-     */
-    public static JSONObject getWXACodeUnlimit(String accessToken, String scene, String page, int width) {
-        try {
-            String requestUrl = Constants.WX_APPLETS_GETWXACODEUNLIMIT_URL.replace("ACCESS_TOKEN", accessToken);
-            JSONObject json = new JSONObject();
-            json.put("scene", scene);
-            json.put("page", page);
-            json.put("width", width);
-            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "POST", json.toString());
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * 获取小程序码接口A,适用于需要的码数量较少的业务场景
-     *
-     * @param accessToken
-     * @param page
-     * @param width
-     * @return
-     */
-    public static JSONObject getWXACode(String accessToken, String page, int width) {
-        try {
-            String requestUrl = Constants.WX_APPLETS_GETWXACODE_URL.replace("ACCESS_TOKEN", accessToken);
-            JSONObject json = new JSONObject();
-            json.put("path", page);
-            json.put("width", width);
-            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "POST", json.toString());
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * 获取小程序码接口C,适用于需要的码数量较少的业务场景
-     *
-     * @param accessToken
-     * @param page
-     * @param width
-     * @return
-     */
-    public static JSONObject getCreateWXACode(String accessToken, String page, int width) {
-        try {
-            String requestUrl = Constants.WX_APPLETS_CREATEWXAQRCODE_URL.replace("ACCESS_TOKEN", accessToken);
-            JSONObject json = new JSONObject();
-            json.put("path", page);
-            json.put("width", width);
-            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "POST", json.toString());
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * 将二进制转换成文件保存
-     *
-     * @param instreams 二进制流
-     * @param imgPath   图片的保存路径
-     * @param imgName   图片的名称
-     * @return 1:保存正常
-     * 0:保存失败
-     */
-    public static int saveToImgByInputStream(InputStream instreams, String imgPath, String imgName) {
-        int stateInt = 1;
-        if (instreams != null) {
-            try {
-                // 文件保存路径
-                // 转存文件
-                FileUtils.createDirectory(imgPath);
-                //可以是任何图片格式.jpg,.png等
-                File file = new File(imgPath, imgName);
-                FileOutputStream fos = new FileOutputStream(file);
-                byte[] b = new byte[1024];
-                int nRead = 0;
-                while ((nRead = instreams.read(b)) != -1) {
-                    fos.write(b, 0, nRead);
-                }
-                fos.flush();
-                fos.close();
-            } catch (Exception e) {
-                stateInt = 0;
-                e.printStackTrace();
-            } finally {
-            }
-        }
-        return stateInt;
-    }
-}
+package com.jeeplus.modules.sys.wxUtils;
+
+import com.jeeplus.common.config.Global;
+import com.jeeplus.common.utils.FileUtils;
+import com.jeeplus.common.utils.SpringContextHolder;
+import com.jeeplus.modules.sys.entity.HpMember;
+import com.jeeplus.modules.sys.entity.HpUser;
+import com.jeeplus.modules.sys.service.HpMemberService;
+import com.jeeplus.modules.sys.service.HpUserService;
+import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
+import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultRequest;
+import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultResponse;
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.common.profile.ClientProfile;
+import com.tencentcloudapi.common.profile.HttpProfile;
+import net.sf.json.JSONObject;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+
+/**
+ * 微信授权的方法类
+ */
+public class TokenUtil {
+    //通过bean机制定义
+    private static HpUserService hpUserService = SpringContextHolder.getBean(HpUserService.class);
+    private static HpMemberService hpMemberService = SpringContextHolder.getBean(HpMemberService.class);
+
+    /**
+     * 验证token有效性
+     *
+     * @param userId
+     * @param token
+     * @return
+     */
+    public static boolean validateToken(String userId, String token) {
+        try {
+            HpUser hpUser = hpUserService.get(userId);
+            if (hpUser != null) {
+                return token.equals(hpUser.getUserToken()) && !hpUser.getUseFlag();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    /**
+     * 验证用户是否处于登录态
+     *
+     * @param memberId
+     * @return
+     */
+    public static boolean validateLogin(String memberId, String userId) {
+        try {
+            HpMember hpMember = hpMemberService.get(memberId);
+            if (hpMember != null) {
+                return userId.equals(hpMember.getHpUser().getId());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    /********************app微信授权************************/
+    /**
+     * 验证access_token是否有效
+     *
+     * @param accesstoken
+     * @param user_openid
+     * @return
+     */
+    public static boolean isAccessTokenIsInvalid(String accesstoken, String user_openid) {
+        try {
+            if (accesstoken != null) {
+                String requestUrl = Constants.AUTH_URL.replace("ACCESS_TOKEN", accesstoken).replace("OPENID", user_openid);
+                JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
+                String errcode = result.getString("errcode");
+                if (Constants.ERRCODE_0.equals(errcode)) {
+                    return true;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    /**
+     * 刷新access_token
+     *
+     * @param appid
+     * @param refreshToken
+     * @return
+     */
+    public static JSONObject refreshAccessToken(String appid, String refreshToken) {
+        try {
+            if (refreshToken != null) {
+                String requestUrl = Constants.REFRESH_URL.replace("APPID", appid).replace("REFRESH_TOKEN", refreshToken);
+                JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
+                return result;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 日常获取用户access_token
+     *
+     * @param user_id
+     * @return
+     */
+    public static JSONObject getDayAccessToken(String user_id) {
+        JSONObject json_object = new JSONObject();
+        try {
+            HpUser hpUser = hpUserService.get(user_id);
+            if (hpUser != null) {
+                if (hpUser.getAccessTokenEndtime() != null) {
+                    int access_token_endtime = hpUser.getAccessTokenEndtime();
+                    //如果用户access_token有效
+                    if (isAccessTokenIsInvalid(hpUser.getAccessToken(), hpUser.getWxOpenid())
+                            && (int) (System.currentTimeMillis() / 1000) < access_token_endtime) {
+                        json_object.put("access_token", hpUser.getAccessToken());
+                        return json_object;
+                    }
+                    //刷新access_token
+                    json_object = refreshAccessToken(WxAppParamsEnum.PARAMS_APP_JOB.getAppId(), hpUser.getRefreshToken());
+                    return json_object;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 用户通过code调用凭证access_token
+     *
+     * @return
+     */
+    public static JSONObject getAccessToken(String code) {
+        try {
+            String requestUrl = Constants.OPENID_URL.replace("APPID", WxAppParamsEnum.PARAMS_APP_JOB.getAppId())
+                    .replace("APPSECRET", WxAppParamsEnum.PARAMS_APP_JOB.getAppSecret()).replace("CODE", code);
+            JSONObject json_object = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
+            return json_object;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 获取用户信息
+     *
+     * @param accesstoken
+     * @param user_openid
+     * @return
+     */
+    public static JSONObject getWxuser(String accesstoken, String user_openid) {
+        try {
+            String requestUrl = Constants.USERINFOR_URL.replace("ACCESS_TOKEN", accesstoken).replace("OPENID", user_openid);
+            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
+            System.out.println("234ttt---=" + result);
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    /********************小程序授权************************/
+    /**
+     * 小程序获取用户openid
+     *
+     * @param code
+     * @return
+     */
+    public static JSONObject minaGetSession(String code) {
+        try {
+            String requestUrl = Constants.MINA_GETSESSION_URL.replace("APPID", WxAppParamsEnum.PARAMS_APPLETS_JOB.getAppId())
+                    .replace("SECRET", WxAppParamsEnum.PARAMS_APPLETS_JOB.getAppSecret()).replace("JSCODE", code);
+
+            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "GET", null);
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /********************小程序二维码************************/
+
+    /**
+     * 获取小程序码接口B,适用于需要的码数量极多的业务场景。
+     *
+     * @param accessToken
+     * @param scene
+     * @param page
+     * @param width
+     * @return
+     */
+    public static JSONObject getWXACodeUnlimit(String accessToken, String scene, String page, int width) {
+        try {
+            String requestUrl = Constants.WX_APPLETS_GETWXACODEUNLIMIT_URL.replace("ACCESS_TOKEN", accessToken);
+            JSONObject json = new JSONObject();
+            json.put("scene", scene);
+            json.put("page", page);
+            json.put("width", width);
+            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "POST", json.toString());
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 获取小程序码接口A,适用于需要的码数量较少的业务场景
+     *
+     * @param accessToken
+     * @param page
+     * @param width
+     * @return
+     */
+    public static JSONObject getWXACode(String accessToken, String page, int width) {
+        try {
+            String requestUrl = Constants.WX_APPLETS_GETWXACODE_URL.replace("ACCESS_TOKEN", accessToken);
+            JSONObject json = new JSONObject();
+            json.put("path", page);
+            json.put("width", width);
+            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "POST", json.toString());
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 获取小程序码接口C,适用于需要的码数量较少的业务场景
+     *
+     * @param accessToken
+     * @param page
+     * @param width
+     * @return
+     */
+    public static JSONObject getCreateWXACode(String accessToken, String page, int width) {
+        try {
+            String requestUrl = Constants.WX_APPLETS_CREATEWXAQRCODE_URL.replace("ACCESS_TOKEN", accessToken);
+            JSONObject json = new JSONObject();
+            json.put("path", page);
+            json.put("width", width);
+            JSONObject result = WxCommonUtil.httpsRequest(requestUrl, "POST", json.toString());
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 将二进制转换成文件保存
+     *
+     * @param instreams 二进制流
+     * @param imgPath   图片的保存路径
+     * @param imgName   图片的名称
+     * @return 1:保存正常
+     * 0:保存失败
+     */
+    public static int saveToImgByInputStream(InputStream instreams, String imgPath, String imgName) {
+        int stateInt = 1;
+        if (instreams != null) {
+            try {
+                // 文件保存路径
+                // 转存文件
+                FileUtils.createDirectory(imgPath);
+                //可以是任何图片格式.jpg,.png等
+                File file = new File(imgPath, imgName);
+                FileOutputStream fos = new FileOutputStream(file);
+                byte[] b = new byte[1024];
+                int nRead = 0;
+                while ((nRead = instreams.read(b)) != -1) {
+                    fos.write(b, 0, nRead);
+                }
+                fos.flush();
+                fos.close();
+            } catch (Exception e) {
+                stateInt = 0;
+                e.printStackTrace();
+            } finally {
+            }
+        }
+        return stateInt;
+    }
+
+    /**
+     * 腾讯云验证码票据验证
+     *
+     * @return
+     */
+    public static JSONObject checkTicket(JSONObject json) {
+        try {
+            //实例化一个认证对象,入参需要传入腾讯云账户 secretId,secretKe
+            Credential cred = new Credential(Global.getSecretId(), Global.getSecretKey());
+
+            HttpProfile httpProfile = new HttpProfile();
+            httpProfile.setEndpoint("captcha.tencentcloudapi.com");
+
+            ClientProfile clientProfile = new ClientProfile();
+            clientProfile.setHttpProfile(httpProfile);
+
+            // 实例化要请求产品(captcha)的 client 对象
+            CaptchaClient client = new CaptchaClient(cred, "", clientProfile);
+
+            String params = "{\"CaptchaType\":9,\"Ticket\":\"" + json.getString("Ticket") + "\",\"UserIp\":\"" + json.getString("UserIp") + "\",\"Randstr\":\"" + json.getString("Randstr") + "\",\"CaptchaAppId\":" + json.getInt("CaptchaAppId") + ",\"AppSecretKey\":\"" + json.getString("AppSecretKey") + "\"}";
+            // 实例化一个请求对象
+            DescribeCaptchaResultRequest req = DescribeCaptchaResultRequest.fromJsonString(params, DescribeCaptchaResultRequest.class);
+            // 通过 client 对象调用想要访问的接口,需要传入请求对象
+            DescribeCaptchaResultResponse resp = client.DescribeCaptchaResult(req);
+
+            return JSONObject.fromObject(DescribeCaptchaResultResponse.toJsonString(resp));
+        } catch (TencentCloudSDKException e) {
+            System.out.println(e.toString());
+        }
+        return null;
+    }
+}