Merge remote-tracking branch 'origin/master'
| | |
| | | <classifier>jdk15</classifier><!-- 指定jdk版本 --> |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>org.apache.httpcomponents</groupId> |
| | | <artifactId>httpclient</artifactId> |
| | | <version>4.5.2</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | <build> |
| | | <plugins> |
New file |
| | |
| | | package com.qxueyou.scc.Sensitive; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | public class List extends ArrayList<Word> { |
| | | public Word get(char c){ |
| | | for(Word w :this){ |
| | | if(w.c == c) return w; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 二分查找,必须先升序排序 |
| | | * @param c 需要查找的字符 |
| | | * @return Word对象:如果找到 null:如果没找到 |
| | | */ |
| | | public Word binaryGet(char c){ |
| | | int left,right,key; |
| | | Word word; |
| | | left = 0;right = this.size()-1; |
| | | while (left <= right){ |
| | | key = (left + right) / 2; |
| | | word = get(key); |
| | | if(word.c == c){ |
| | | return word; |
| | | }else if(word.c > c){ |
| | | right = key - 1; |
| | | }else { |
| | | left = key + 1; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public Word add(char c){ |
| | | Word word = new Word(c); |
| | | super.add(word); |
| | | return word; |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.Sensitive; |
| | | |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | |
| | | |
| | | public final class SensitiveWordFilter { |
| | | public static List wordList; |
| | | private final static char replace = '*'; // 替代字符 |
| | | private final static char[] skip = new char[]{ // 遇到这些字符就会跳过,例如,如果"AB"是敏感词,那么"A B","A=B"也会被屏蔽 |
| | | '!','*','-','+','_','=',',','.','@' |
| | | }; |
| | | |
| | | /** |
| | | * 敏感词替换 |
| | | * @param text 待替换文本 |
| | | * @return 替换后的文本 |
| | | */ |
| | | public static String Filter(String text){ |
| | | if(wordList == null || wordList.size() == 0) return text; |
| | | char[] __char__ = text.toCharArray(); // 把String转化成char数组,便于遍历 |
| | | int i,j; |
| | | Word word; |
| | | boolean flag; // 是否需要替换 |
| | | for(i=0;i<__char__.length;i++){ // 遍历所有字符 |
| | | char c = __char__[i]; |
| | | word = wordList.binaryGet(c); // 使用二分查找来寻找字符,提高效率 |
| | | if(word != null){ // word != null说明找到了 |
| | | flag = false; |
| | | j = i+1; |
| | | while (j < __char__.length){ // 开始逐个比较后面的字符 |
| | | if(skip(__char__[j])) { // 跳过空格之类的无关字符 |
| | | j++; |
| | | continue; |
| | | } |
| | | if(word.next != null){ // 字符串尚未结束,不确定是否存在敏感词 |
| | | /* |
| | | 以下代码并没有使用二分查找,因为以同一个字符开头的敏感词较少 |
| | | 例如,wordList中记录了所有敏感词的开头第一个字,它的数量通常会有上千个 |
| | | 假如现在锁定了字符“T”开头的敏感词,而“T”开头的敏感词只有10个,这时使用二分查找的效率反而低于顺序查找 |
| | | */ |
| | | word = word.next.get(__char__[j]); |
| | | if(word == null){ |
| | | break; |
| | | } |
| | | j++; |
| | | }else { // 字符串已结束,存在敏感词汇 |
| | | flag = true; |
| | | break; |
| | | } |
| | | } |
| | | if(word != null && word.next == null){ |
| | | flag = true; |
| | | } |
| | | if(flag){ // 如果flag==true,说明检测出敏感粗,需要替换 |
| | | while (i<j){ |
| | | if(skip(__char__[i])){ // 跳过空格之类的无关字符,如果要把空格也替换成'*',则删除这个if语句 |
| | | i++; |
| | | continue; |
| | | } |
| | | __char__[i] = replace; |
| | | i++; |
| | | } |
| | | i--; |
| | | } |
| | | } |
| | | } |
| | | return new String(__char__); |
| | | } |
| | | |
| | | /** |
| | | * 加载敏感词列表 |
| | | * @param words 敏感词数组 |
| | | */ |
| | | public static void loadWord(ArrayList<String> words){ |
| | | if(words == null) return; |
| | | char[] chars; |
| | | List now; |
| | | Word word; |
| | | wordList = new List(); |
| | | for(String __word__:words){ |
| | | if(__word__ == null) continue; |
| | | chars = __word__.toCharArray(); |
| | | now = wordList; |
| | | word = null; |
| | | for(char c:chars){ |
| | | if(word != null) { |
| | | if(word.next == null) word.next = new List(); |
| | | now = word.next; |
| | | } |
| | | word = now.get(c); |
| | | if(word == null) word = now.add(c); |
| | | } |
| | | } |
| | | sort(wordList); |
| | | } |
| | | |
| | | /** |
| | | * 加载敏感词txt文件,每个敏感词独占一行,不可出现空格,空行,逗号等非文字内容,必须使用UTF-8编码 |
| | | * @param path txt文件的绝对地址 |
| | | */ |
| | | public static void loadWordFromFile(String path){ |
| | | String encoding = "UTF-8"; |
| | | File file = new File(path); |
| | | try{ |
| | | if(file.isFile() && file.exists()){ |
| | | InputStreamReader inputStreamReader = new InputStreamReader( |
| | | new FileInputStream(file),encoding |
| | | ); |
| | | BufferedReader bufferedReader = new BufferedReader(inputStreamReader); |
| | | String line; |
| | | ArrayList<String> list = new ArrayList<>(); |
| | | while ((line = bufferedReader.readLine()) != null){ |
| | | list.add(line); |
| | | } |
| | | bufferedReader.close(); |
| | | inputStreamReader.close(); |
| | | loadWord(list); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 对敏感词多叉树递增排序 |
| | | * @param list 待排序List |
| | | */ |
| | | private static void sort(List list){ |
| | | if(list == null) return; |
| | | Collections.sort(list); // 递增排序 |
| | | for(Word word:list){ |
| | | sort(word.next); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断是否跳过当前字符 |
| | | * @param c 待检测字符 |
| | | * @return true:需要跳过 false:不需要跳过 |
| | | */ |
| | | private static boolean skip(char c){ |
| | | for(char c1:skip){ |
| | | if(c1 == c) return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.Sensitive; |
| | | |
| | | public class Word implements Comparable<Word>{ |
| | | public char c; |
| | | public List next = null; |
| | | |
| | | public Word(char c){ |
| | | this.c = c; |
| | | } |
| | | |
| | | @Override |
| | | public int compareTo(Word word) { |
| | | return c - word.c; |
| | | } |
| | | |
| | | public String toString(){ |
| | | return c + "(" + (next == null ? null : next.size()) + ")"; |
| | | } |
| | | } |
| | |
| | | |
| | | package com.qxueyou.scc.base.dao; |
| | | |
| | | import java.beans.Transient; |
| | | import java.io.Serializable; |
| | | import java.math.BigInteger; |
| | | import java.util.ArrayList; |
| | |
| | | |
| | | import com.qxueyou.scc.base.model.Pager; |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * 基础DAO类,自动注入sessionFactory |
| | |
| | | /** |
| | | * 保存或更新对象 |
| | | */ |
| | | @Transactional(readOnly = false) |
| | | public void saveOrUpdate(Object obj) { |
| | | this.getHibernateTemplate().saveOrUpdate(obj); |
| | | } |
| | |
| | | this.success = success; |
| | | } |
| | | |
| | | public Boolean getSuccess() { |
| | | return success; |
| | | } |
| | | |
| | | public String getMsg() { |
| | | return msg; |
| | | } |
| | |
| | | * @author chenjunliang |
| | | */ |
| | | @Api(tags = "资源管理接口") |
| | | @CrossOrigin |
| | | @RestController |
| | | @RequestMapping(value = "/teach/res") |
| | | public class ResController { |
| | |
| | | String startTime1 = simpleDateFormat.format(new Date(startTime)); |
| | | String endTime1 = simpleDateFormat.format(new Date(endTime)); |
| | | //调用第三方直播接口 |
| | | String s = client.courseAdd(name, "16624662432", startTime1, endTime1, ClientUtils.getUserName(), "222", options); |
| | | String s = client.courseAdd(name, ClientUtils.getUserId(), startTime1, endTime1, ClientUtils.getUserName(), "222", options); |
| | | //json转换拿到courseId |
| | | JSONObject jsonObject = JSON.parseObject(s); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | |
| | | HashMap<Object,Object> options = new HashMap<Object, Object>(); |
| | | options.put("ssl", false); |
| | | |
| | | String res = client.courseLogin("16624662432", MTCloud.ACCOUNT_TYPE_THIRD, options); |
| | | String res = client.courseLogin(ClientUtils.getUserId(),MTCloud.ACCOUNT_TYPE_THIRD, options); |
| | | System.out.println(res); |
| | | JSONObject jsonObject = JSON.parseObject(res); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | |
| | | |
| | | package com.qxueyou.scc.operation.topic.action; |
| | | |
| | | import com.qxueyou.scc.Sensitive.SensitiveWordFilter; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | @GetMapping(value = "addComment") |
| | | public Result addComment(String content, String commentObjectId, String commentParentId, String commentedId, |
| | | String commentedName) { |
| | | return topicService.addComment(content, commentObjectId, commentParentId, commentedId, commentedName); |
| | | SensitiveWordFilter.loadWordFromFile("D:\\工作\\SensitiveWord\\SensitiveWordList.txt"); |
| | | String filter = SensitiveWordFilter.Filter(content); |
| | | return topicService.addComment(filter, commentObjectId, commentParentId, commentedId, commentedName); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | import com.qxueyou.scc.base.util.ClientUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | * |
| | | */ |
| | | @RestController |
| | | @CrossOrigin |
| | | @RequestMapping(value = "/stu/homepage") |
| | | public class HomePageController { |
| | | |
| | |
| | | package com.qxueyou.scc.sys.action; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.qxueyou.scc.base.util.*; |
| | | import com.qxueyou.scc.wx.service.IWechatService; |
| | | import freemarker.template.utility.StringUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.kafka.common.network.LoginType; |
| | | import org.apache.tomcat.util.net.openssl.ciphers.Authentication; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | |
| | | @Autowired |
| | | private IOrganizationService organizationService; |
| | | |
| | | public static String UUNUMBER="QXYUUNUMBER"; |
| | | /** |
| | | * 小程序appID |
| | | */ |
| | | @Value("${wx.appId}") |
| | | private String appId; |
| | | |
| | | |
| | | /** |
| | | * 小程序secret |
| | | */ |
| | | @Value("${wx.secret}") |
| | | private String secret; |
| | | |
| | | |
| | | public static String UUNUMBER="QXYUUNUMBER"; |
| | | |
| | | @Autowired |
| | | IWechatService wechatService; |
| | | |
| | | /** |
| | | * 微信登录 |
| | | * |
| | | * @param uid |
| | | * @throws IOException |
| | | */ |
| | | |
| | | @PostMapping("/wxlogin") |
| | | @ApiOperation("微信登录") |
| | | @ResponseBody |
| | | public Result wechatLogin(String code,String number) { |
| | | JSONObject sessionKeyOrOpenId = wechatService.getSessionKeyOrOpenId(code); |
| | | JSONObject gettoken = wechatService.gettoken(appId, secret); |
| | | Result phone = wechatService.getNumber(gettoken.get("access_token").toString(), number); |
| | | if(phone.getSuccess()){ |
| | | String hql = "from User where deleteFlag is false and mobilePhone = ? "; |
| | | System.out.println(phone.getData()); |
| | | List<Object> params = CollectionUtils.newList(phone.getData()); |
| | | User user = commonDAO.findUnique(hql,params, User.class); |
| | | if(user==null){ |
| | | //新增用户 |
| | | User user1=new User(); |
| | | user1.setMobilePhone(phone.getData().toString()); |
| | | user1.setOpenId(sessionKeyOrOpenId.get("openid").toString()); |
| | | commonDAO.save(user1); |
| | | //新增关联学员 |
| | | String addUserSql = "from User where deleteFlag is false and mobilePhone = ? "; |
| | | List<Object> newParams = CollectionUtils.newList(phone.getData()); |
| | | User newUser = commonDAO.findUnique(addUserSql,newParams, User.class); |
| | | StuStudent stuStudent=new StuStudent(); |
| | | stuStudent.setStatus(StuStudent.STATUS_REGISTER); |
| | | stuStudent.setUserId(newUser.getUserId()); |
| | | stuStudent.setMobilePhone(newUser.getMobilePhone()); |
| | | commonDAO.save(stuStudent); |
| | | } |
| | | if(StringUtils.isEmpty(user.getOpenId())){ |
| | | user.setOpenId(sessionKeyOrOpenId.get("openid").toString()); |
| | | commonDAO.saveOrUpdate(user); |
| | | } |
| | | String studentSql = "from StuStudent where deleteFlag is false and userId = ? "; |
| | | List<Object> stuParams = CollectionUtils.newList(user.getUserId()); |
| | | StuStudent stuStudent = commonDAO.findUnique(studentSql, stuParams, StuStudent.class); |
| | | return new Result(true,"授权成功",CollectionUtils.newObjectMap("user",user,"ClassId",stuStudent.getClassId())); |
| | | } |
| | | return phone; |
| | | } |
| | | |
| | | @ApiOperation(value = "登入接口", notes = "") |
| | | @ApiImplicitParams({ |
| | |
| | | private static final long serialVersionUID = 7504161189427721559L; |
| | | |
| | | /* |
| | | * 状态: 已报名 |
| | | * 状态: 已报名,未激活,已毕业 |
| | | */ |
| | | public static final String STATUS_REGISTER = "register"; |
| | | public static final String STATUS_ACTIVE = "active"; |
| | |
| | | } |
| | | subject.put("percent", new BigDecimal(percentAvg)); |
| | | subject.put("progressValue", new BigDecimal(progressValue)); |
| | | |
| | | subject.put("lectureParentId", map.get("lectureParentId")); |
| | | subject.put("lectureId", map.get("lectureId")); |
| | | subject.put("unCommitExerciseCount", exerciseInfoService.getUnCommitExerciseCount(classId, userId)); |
| | |
| | | String className = "公开课"; |
| | | subjectMap.put("subjectName",subject.getSubjectName()); |
| | | subjectMap.put("subjectId",subject.getSubjectId()); |
| | | |
| | | subjectMap.put("coverPageUrl",subject.getCoverPageUrl()); |
| | | subjectMap.put("percent", new BigDecimal(percentAvg)); |
| | | subjectMap.put("progressValue", new BigDecimal(progressValue)); |
| | | subjectMap.put("className",className); |
| | |
| | | @Column(name = "IMEI", length = 255) |
| | | private String imei; |
| | | |
| | | /** |
| | | * 绑定账号ID |
| | | */ |
| | | @Column(name = "OPENID", length = 255) |
| | | private String openId; |
| | | |
| | | public String getOpenId() { |
| | | return openId; |
| | | } |
| | | |
| | | public void setOpenId(String openId) { |
| | | this.openId = openId; |
| | | } |
| | | |
| | | @ManyToMany(fetch = FetchType.LAZY, mappedBy = "users") |
| | | @JsonIgnore |
| | | private List<UserRole> roles; |
| | |
| | | //是否合法 |
| | | // if(!licenseService.isValid()) { |
| | | // log.debug("license invalid"); |
| | | // forbiddenAsLicense(httpResponse); |
| | | // return; |
| | | // } |
| | | //// forbiddenAsLicense(httpResponse); |
| | | //// return; |
| | | //// } |
| | | |
| | | if (!addClientInfo(httpRequest)) { |
| | | log.debug("非法请求:" + httpRequest.getRequestURI()); |
New file |
| | |
| | | package com.qxueyou.scc.wx.service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.teach.student.model.StuStudent; |
| | | |
| | | import java.util.Map; |
| | | |
| | | public interface IWechatService { |
| | | |
| | | /** |
| | | * 查询用户 |
| | | * @param code |
| | | * @param type |
| | | * @return |
| | | * |
| | | * @author 李岩龙 |
| | | * @date 2021年4月2日 下午3:31:05 |
| | | */ |
| | | |
| | | JSONObject getSessionKeyOrOpenId(String code); |
| | | |
| | | Result getNumber(String tonken, String number); |
| | | |
| | | JSONObject gettoken(String appid,String secret); |
| | | // Result isBindWx(String userId); |
| | | |
| | | // Result getSignature(String url); |
| | | |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.wx.service.impl; |
| | | |
| | | import com.alibaba.druid.util.HttpClientUtils; |
| | | import com.alibaba.druid.util.StringUtils; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.base.service.ICacheService; |
| | | import com.qxueyou.scc.teach.student.model.StuStudent; |
| | | import com.qxueyou.scc.wx.service.IWechatService; |
| | | import com.qxueyou.scc.wx.utils.HttpClientUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URI; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | @Service |
| | | public class WechatService implements IWechatService { |
| | | |
| | | // @Autowired |
| | | // IUserService userService; |
| | | |
| | | /** |
| | | * 小程序appID |
| | | */ |
| | | @Value("${wx.appId}") |
| | | private String appId; |
| | | |
| | | |
| | | /** |
| | | * 小程序secret |
| | | */ |
| | | @Value("${wx.secret}") |
| | | private String secret; |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | private ICacheService cacheService; |
| | | |
| | | private final Logger logger = LogManager.getLogger(); |
| | | |
| | | |
| | | @Override |
| | | public JSONObject getSessionKeyOrOpenId(String code) { |
| | | String requestUrl = "https://api.weixin.qq.com/sns/jscode2session"; |
| | | Map<String, String> requestUrlParam = new HashMap<>(); |
| | | // https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN |
| | | //小程序appId |
| | | requestUrlParam.put("appid", appId); |
| | | //小程序secret |
| | | requestUrlParam.put("secret", secret); |
| | | //小程序端返回的code |
| | | requestUrlParam.put("js_code", code); |
| | | //默认参数 |
| | | requestUrlParam.put("grant_type", "authorization_code"); |
| | | //发送post请求读取调用微信接口获取openid用户唯一标识 |
| | | JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doPost(requestUrl, requestUrlParam)); |
| | | return jsonObject; |
| | | } |
| | | |
| | | @Override |
| | | public Result getNumber(String tonken, String number) { |
| | | JSONObject jsonCode = new JSONObject(); |
| | | |
| | | jsonCode.put("code",number); |
| | | |
| | | |
| | | String resPhone = HttpClientUtil.doPostUrl("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + tonken, jsonCode); |
| | | |
| | | if(StringUtils.isEmpty(resPhone) || !resPhone.contains("phone_info") || !resPhone.contains("phoneNumber")){ |
| | | return new Result(false,"微信官方修改了小程序获取用户手机号码相关接口!"); |
| | | } |
| | | JSONObject resPhoneInfo = JSON.parseObject(resPhone); |
| | | JSONObject phoneInfo=resPhoneInfo.getJSONObject("phone_info"); |
| | | System.out.println(resPhoneInfo); |
| | | System.out.println(phoneInfo); |
| | | String phoneNumber = phoneInfo.get("phoneNumber").toString(); |
| | | |
| | | return new Result(true,"获取手机号成功",phoneNumber); |
| | | // String requestUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+tonken+jsonObject.toJSONString(); |
| | | |
| | | // Map<String, String> requestUrlParam = new HashMap<>(); |
| | | |
| | | |
| | | |
| | | // requestUrlParam.put("code", number); |
| | | |
| | | // JSONObject s =JSON.parseObject(HttpClientUtil.doPost(requestUrl)); |
| | | |
| | | // return s; |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject gettoken(String appid, String secret) { |
| | | String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; |
| | | |
| | | Map<String, String> requestUrlParam = new HashMap<>(); |
| | | |
| | | requestUrlParam.put("grant_type", "client_credential"); |
| | | |
| | | requestUrlParam.put("appid", appid); |
| | | |
| | | requestUrlParam.put("secret", secret); |
| | | |
| | | JSONObject s = JSON.parseObject(HttpClientUtil.doGet(requestUrl, requestUrlParam)); |
| | | |
| | | return s; |
| | | } |
| | | // private String getWechatHeadImgUrl(String unionId) { |
| | | // WechatUserDO wxUser = this.template.findOne(Query.query(condition().and("unionId").is(unionId)), WechatUserDO.class); |
| | | // return wxUser.getHeadImgUrl(); |
| | | // } |
| | | |
| | | // @Override |
| | | // public Result isBindWx(String userId) { |
| | | // UserStudentDO studentDO = read(UserStudentDO.class, userId); |
| | | // boolean status = false; |
| | | // if (StringUtils.isNotBlank(studentDO.getUnionId())) { |
| | | // status = true; |
| | | // } |
| | | // String url = ""; |
| | | // if (status) { |
| | | // url = getWechatHeadImgUrl(studentDO.getUnionId()); |
| | | // } |
| | | // return new Result(true, "status", status, "url", url); |
| | | // } |
| | | // |
| | | // public Result getSignature(String url) { |
| | | // try { |
| | | // long timestamp = System.currentTimeMillis() / 1000; |
| | | // String randomStr = RandomUtils.getRandomStr(); |
| | | // //远程调用获取ticket |
| | | //// String jsapiTicket ="";//getJsapiTicket(false); |
| | | // RestTemplate restTemplate = new RestTemplate(); |
| | | // |
| | | // String jsapiTicket = restTemplate.getForObject("http://192.168.1.111/job/ticket", String.class); |
| | | // |
| | | // String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, |
| | | // "noncestr=" + randomStr, "timestamp=" + timestamp, "url=" + url); |
| | | // WxJsapiSignature jsapiSignature = new WxJsapiSignature(); |
| | | // jsapiSignature.setAppId(wxProperties.getAppId()); |
| | | // jsapiSignature.setTimestamp(timestamp); |
| | | // jsapiSignature.setNonceStr(randomStr); |
| | | // jsapiSignature.setUrl(url); |
| | | // jsapiSignature.setSignature(signature); |
| | | // return new Result(true, jsapiSignature); |
| | | // } catch (Exception e) { |
| | | // log.error(e, e); |
| | | // return new Result(false, "获取签名失败"); |
| | | // } |
| | | // } |
| | | |
| | | // @Override |
| | | // public String getOpenId(String userId) { |
| | | // UserStudentDO user = read(UserStudentDO.class, userId); |
| | | // |
| | | // return user.getOpenId(); |
| | | // } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.wx.utils; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | /** |
| | | * <p> |
| | | * 调用微信接口 返回授权信息~ |
| | | * </p> |
| | | * @author echo lovely |
| | | * @date 2020/12/4 21:56 |
| | | */ |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class Code2Session { |
| | | |
| | | //用户唯一标识 |
| | | private String openid; |
| | | // 会话密钥 |
| | | private String session_key; |
| | | // 用户在开放平台的唯一标识符 |
| | | private String unionid; |
| | | // 错误码 |
| | | private Integer errcode; |
| | | // 错误信息 |
| | | private String errmsg; |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package com.qxueyou.scc.wx.utils; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import net.sf.json.JSONString; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.client.utils.URIBuilder; |
| | | import org.apache.http.entity.ContentType; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.http.util.EntityUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URI; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class HttpClientUtil { |
| | | |
| | | public static String doGet(String url, Map<String, String> param) { |
| | | |
| | | // 创建Httpclient对象 |
| | | CloseableHttpClient httpclient = HttpClients.createDefault(); |
| | | |
| | | String resultString = ""; |
| | | CloseableHttpResponse response = null; |
| | | try { |
| | | // 创建uri |
| | | URIBuilder builder = new URIBuilder(url); |
| | | if (param != null) { |
| | | for (String key : param.keySet()) { |
| | | builder.addParameter(key, param.get(key)); |
| | | } |
| | | } |
| | | URI uri = builder.build(); |
| | | |
| | | // 创建http GET请求 |
| | | HttpGet httpGet = new HttpGet(uri); |
| | | |
| | | // 执行请求 |
| | | response = httpclient.execute(httpGet); |
| | | // 判断返回状态是否为200 |
| | | if (response.getStatusLine().getStatusCode() == 200) { |
| | | resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (response != null) { |
| | | response.close(); |
| | | } |
| | | httpclient.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return resultString; |
| | | } |
| | | |
| | | public static String doGet(String url) { |
| | | return doGet(url, null); |
| | | } |
| | | |
| | | public static String doPost(String url, Map<String, String> param) { |
| | | // 创建Httpclient对象 |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | CloseableHttpResponse response = null; |
| | | String resultString = ""; |
| | | try { |
| | | // 创建Http Post请求 |
| | | HttpPost httpPost = new HttpPost(url); |
| | | // 创建参数列表 |
| | | if (param != null) { |
| | | List<NameValuePair> paramList = new ArrayList<>(); |
| | | for (String key : param.keySet()) { |
| | | System.out.println(key); |
| | | System.out.println(param.get(key)); |
| | | paramList.add(new BasicNameValuePair(key, param.get(key))); |
| | | } |
| | | // 模拟表单 |
| | | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList); |
| | | httpPost.setEntity(entity); |
| | | } |
| | | // 执行http请求 |
| | | response = httpClient.execute(httpPost); |
| | | resultString = EntityUtils.toString(response.getEntity(), "utf-8"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | response.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | return resultString; |
| | | } |
| | | |
| | | public static String doPostUrl(String url, JSONObject jsonCode) { |
| | | // 创建Httpclient对象 |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | CloseableHttpResponse response = null; |
| | | String resultString = ""; |
| | | try { |
| | | // 创建Http Post请求 |
| | | HttpPost httpPost = new HttpPost(url); |
| | | |
| | | String s = jsonCode.toJSONString(jsonCode); |
| | | |
| | | StringEntity entity=new StringEntity(s); |
| | | |
| | | httpPost.setEntity(entity); |
| | | // 执行http请求 |
| | | response = httpClient.execute(httpPost); |
| | | resultString = EntityUtils.toString(response.getEntity(), "utf-8"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | response.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | return resultString; |
| | | } |
| | | |
| | | public static String doPost(String url) { |
| | | return doPost(url, null); |
| | | } |
| | | |
| | | public static String doPostJson(String url, String json) { |
| | | // 创建Httpclient对象 |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | CloseableHttpResponse response = null; |
| | | String resultString = ""; |
| | | try { |
| | | // 创建Http Post请求 |
| | | HttpPost httpPost = new HttpPost(url); |
| | | // 创建请求内容 |
| | | StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); |
| | | httpPost.setEntity(entity); |
| | | // 执行http请求 |
| | | response = httpClient.execute(httpPost); |
| | | resultString = EntityUtils.toString(response.getEntity(), "utf-8"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | response.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | return resultString; |
| | | } |
| | | } |
| | |
| | | # default DefaultExpiration time : 30 minutes(600 seconds) |
| | | spring.redis.default.ttl=600 |
| | | |
| | | |
| | | wx.appId=wx953bf2ed18e7836b |
| | | wx.secret=1d8b00beaddf5c8f36d1fedc14ef7973 |
| | | |
| | | logging.config=classpath:log4j2.xml |