| | |
| | | |
| | | 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"); |
| | |
| | | |
| | | 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 { |
| | | |
| | |
| | | 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; |
| | |
| | | * @param uid |
| | | * @throws IOException |
| | | */ |
| | | @PostMapping("/auth/wechat/login") |
| | | |
| | | @PostMapping("/wxlogin") |
| | | @ApiOperation("微信登录") |
| | | @ResponseBody |
| | | public Result wechatLogin(String code,String number) { |
| | | JSONObject sessionKeyOrOpenId = wechatService.getSessionKeyOrOpenId(code); |
| | | String phone = wechatService.getNumber(number); |
| | | String hql = "from User where deleteFlag is false and mobilePhone = ? "; |
| | | List<Object> params = CollectionUtils.newList(phone); |
| | | User user = commonDAO.findUnique(hql,params, User.class); |
| | | if(user==null){ |
| | | User user1=new User(); |
| | | user1.setMobilePhone(phone); |
| | | commonDAO.save(user1); |
| | | 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 new Result(true,"cg",user); |
| | | // return new Result(true,"token",securityProperties.getTokenStartWith() + token,"user",user); |
| | | } |
| | | 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"; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | JSONObject getSessionKeyOrOpenId(String code); |
| | | |
| | | String getNumber(String number); |
| | | Result getNumber(String tonken, String number); |
| | | |
| | | JSONObject gettoken(String appid,String secret); |
| | | // Result isBindWx(String userId); |
| | | |
| | | // Result getSignature(String url); |
| | |
| | | package com.qxueyou.scc.wx.service.impl; |
| | | |
| | | import cn.hutool.http.HttpUtil; |
| | | 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; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getNumber(String number) { |
| | | String requestUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"; |
| | | 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("access_token", "access_token"); |
| | | requestUrlParam.put("grant_type", "client_credential"); |
| | | |
| | | requestUrlParam.put("code", number); |
| | | requestUrlParam.put("appid", appid); |
| | | |
| | | String s = HttpClientUtil.doPost(requestUrl, requestUrlParam); |
| | | requestUrlParam.put("secret", secret); |
| | | |
| | | JSONObject s = JSON.parseObject(HttpClientUtil.doGet(requestUrl, requestUrlParam)); |
| | | |
| | | return s; |
| | | } |
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; |
| | | |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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))); |
| | | } |
| | | // 模拟表单 |
| | |
| | | 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); |
| | | } |