|
@@ -2,6 +2,7 @@ package com.zhongzheng.framework.web.service;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -20,7 +21,9 @@ import com.zhongzheng.common.utils.*;
|
|
|
import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
import com.zhongzheng.modules.alisms.service.IAliSmsService;
|
|
|
+import com.zhongzheng.modules.course.bo.SectionWatchPerBo;
|
|
|
import com.zhongzheng.modules.course.domain.CourseMenu;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseSectionWatchPer;
|
|
|
import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
|
|
|
import com.zhongzheng.modules.user.bo.UserAddBo;
|
|
|
import com.zhongzheng.modules.user.bo.UserWxFollowAddBo;
|
|
@@ -64,8 +67,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
* @author zhongzheng
|
|
|
*/
|
|
|
@Component
|
|
|
-public class WxLoginService implements IWxLoginService
|
|
|
-{
|
|
|
+public class WxLoginService implements IWxLoginService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(WxLoginService.class);
|
|
|
|
|
|
@Autowired
|
|
@@ -117,6 +119,10 @@ public class WxLoginService implements IWxLoginService
|
|
|
|
|
|
private String small_wxSendTpParam = "access_token=%s";
|
|
|
|
|
|
+ private String small_wxEnCodeUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit";
|
|
|
+
|
|
|
+ private String small_wxEnCodeParam = "access_token=%s";
|
|
|
+
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
|
|
@@ -133,23 +139,23 @@ public class WxLoginService implements IWxLoginService
|
|
|
private IUserWxFollowService iUserWxFollowService;
|
|
|
|
|
|
|
|
|
- public Map<String,String> test_login() {
|
|
|
+ public Map<String, String> test_login() {
|
|
|
String unionId = "oQ2yp56PgQ-PfwN4vxTZhR5eTpzk";
|
|
|
User user = iUserService.queryByUnionId(unionId);
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
loginUser.setUser(user);
|
|
|
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
- map.put(Constants.TOKEN,wxTokenService.createToken(loginUser));
|
|
|
- map.put("union_id",loginUser.getUser().getUnionId());
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
|
|
|
+ map.put("union_id", loginUser.getUser().getUnionId());
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- public Map<String,Object> pcLoginUrl(){
|
|
|
+ public Map<String, Object> pcLoginUrl() {
|
|
|
String scanCode = ToolsUtils.getCharAndNumr(6);
|
|
|
- String key = "SCAN_LOGIN_"+scanCode;
|
|
|
- String keyStatus = "SCAN_LOGIN_STATUS_"+scanCode; //0未扫码 1已扫码 2已登录
|
|
|
- String codeUrl = scanLoginHost+"pc/login/"+scanCode;
|
|
|
+ String key = "SCAN_LOGIN_" + scanCode;
|
|
|
+ String keyStatus = "SCAN_LOGIN_STATUS_" + scanCode; //0未扫码 1已扫码 2已登录
|
|
|
+ String codeUrl = scanLoginHost + "pc/login/" + scanCode;
|
|
|
String urlBase64 = null;
|
|
|
try {
|
|
|
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
|
@@ -164,90 +170,89 @@ public class WxLoginService implements IWxLoginService
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- redisCache.setCacheObject(key, 0L,180, TimeUnit.SECONDS);//180秒锁定
|
|
|
- redisCache.setCacheObject(keyStatus, 0L,180, TimeUnit.SECONDS);//180秒锁定
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("scanCode",scanCode);
|
|
|
- map.put("urlBase64",urlBase64);
|
|
|
- return map;
|
|
|
+ redisCache.setCacheObject(key, 0L, 180, TimeUnit.SECONDS);//180秒锁定
|
|
|
+ redisCache.setCacheObject(keyStatus, 0L, 180, TimeUnit.SECONDS);//180秒锁定
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("scanCode", scanCode);
|
|
|
+ map.put("urlBase64", urlBase64);
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* PC检查是否小程序登录成功
|
|
|
+ *
|
|
|
* @param scanCode
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String,Object> checkPcLogin(String scanCode) {
|
|
|
- String key = "SCAN_LOGIN_"+scanCode;
|
|
|
- String keyStatus = "SCAN_LOGIN_STATUS_"+scanCode; //0未扫码 1已扫码 2已登录
|
|
|
+ public Map<String, Object> checkPcLogin(String scanCode) {
|
|
|
+ String key = "SCAN_LOGIN_" + scanCode;
|
|
|
+ String keyStatus = "SCAN_LOGIN_STATUS_" + scanCode; //0未扫码 1已扫码 2已登录
|
|
|
Long userId = redisCache.getCacheObject(key);
|
|
|
Long status = redisCache.getCacheObject(keyStatus);
|
|
|
- if(Validator.isNotEmpty(status)&&status.equals(1L)){
|
|
|
+ if (Validator.isNotEmpty(status) && status.equals(1L)) {
|
|
|
throw new CustomException("小程序已扫码");
|
|
|
- }
|
|
|
- else if(Validator.isNotEmpty(status)&&status.equals(2L)){
|
|
|
+ } else if (Validator.isNotEmpty(status) && status.equals(2L)) {
|
|
|
User user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getUserId, userId).last("limit 1"));
|
|
|
- if(Validator.isEmpty(user)){
|
|
|
+ if (Validator.isEmpty(user)) {
|
|
|
throw new CustomException("暂未登录");
|
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
loginUser.setUser(user);
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put(Constants.TOKEN,wxTokenService.createToken(loginUser));
|
|
|
- map.put("user_account",loginUser.getUser().getUserAccount());
|
|
|
- map.put("full_info",Validator.isEmpty(user.getIdCard())?false:true); //是否完善身份信息
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
|
|
|
+ map.put("user_account", loginUser.getUser().getUserAccount());
|
|
|
+ map.put("full_info", Validator.isEmpty(user.getIdCard()) ? false : true); //是否完善身份信息
|
|
|
return map;
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
throw new CustomException("暂未登录");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Map<String,Object> login(WxLoginBody loginBody) {
|
|
|
+ public Map<String, Object> login(WxLoginBody loginBody) {
|
|
|
User user = getWxUnionIdUser(loginBody);
|
|
|
- if(user==null){
|
|
|
+ if (user == null) {
|
|
|
throw new CustomException("登录错误");
|
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
loginUser.setUser(user);
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put(Constants.TOKEN,wxTokenService.createToken(loginUser));
|
|
|
- map.put("user_account",loginUser.getUser().getUserAccount());
|
|
|
- map.put("full_info",Validator.isEmpty(user.getIdCard())?false:true); //是否完善身份信息
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
|
|
|
+ map.put("user_account", loginUser.getUser().getUserAccount());
|
|
|
+ map.put("full_info", Validator.isEmpty(user.getIdCard()) ? false : true); //是否完善身份信息
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Map<String,String> smallTel(WxLoginBody loginBody) {
|
|
|
+ public Map<String, String> smallTel(WxLoginBody loginBody) {
|
|
|
User user = getWxUnionIdUser(loginBody);
|
|
|
- if(user==null){
|
|
|
+ if (user == null) {
|
|
|
throw new CustomException("登录错误");
|
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
loginUser.setUser(user);
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
- map.put(Constants.TOKEN,wxTokenService.createToken(loginUser));
|
|
|
- map.put("union_id",loginUser.getUser().getUnionId());
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
|
|
|
+ map.put("union_id", loginUser.getUser().getUnionId());
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- public Map<String,String> gzh_login(WxLoginBody loginBody) {
|
|
|
+ public Map<String, String> gzh_login(WxLoginBody loginBody) {
|
|
|
User user = getWxGzhUnionIdUser(loginBody);
|
|
|
- if(user==null){
|
|
|
+ if (user == null) {
|
|
|
throw new CustomException("登录错误");
|
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
loginUser.setUser(user);
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
- map.put(Constants.TOKEN,wxTokenService.createToken(loginUser));
|
|
|
- map.put("union_id",loginUser.getUser().getUnionId());
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
|
|
|
+ map.put("union_id", loginUser.getUser().getUnionId());
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
public String refreshToken(String userAccount) {
|
|
|
User user = iUserService.queryByAccount(userAccount);
|
|
|
- if(user==null){
|
|
|
+ if (user == null) {
|
|
|
throw new CustomException("userAccount不存在");
|
|
|
}
|
|
|
user.setLastLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
@@ -260,12 +265,13 @@ public class WxLoginService implements IWxLoginService
|
|
|
|
|
|
/**
|
|
|
* 小程序注册
|
|
|
+ *
|
|
|
* @param openId
|
|
|
* @param unionId
|
|
|
* @param tel
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean register_small(String openId,String unionId,String tel,String inviteCode) {
|
|
|
+ public Boolean register_small(String openId, String unionId, String tel, String inviteCode) {
|
|
|
User bo = new User();
|
|
|
bo.setOpenId(openId);
|
|
|
bo.setUnionId(unionId);
|
|
@@ -283,21 +289,22 @@ public class WxLoginService implements IWxLoginService
|
|
|
bo.setLastLoginTime(DateUtils.getNowTime());
|
|
|
bo.setCreateTime(DateUtils.getNowTime());
|
|
|
bo.setUpdateTime(DateUtils.getNowTime());
|
|
|
- String pwd = ToolsUtils.getSmsCode(); // 随机密码
|
|
|
+ String pwd = ToolsUtils.getSmsCode(); // 随机密码
|
|
|
bo.setPassword(SecurityUtils.encryptPassword(pwd));
|
|
|
- if(inviteCode!=null){
|
|
|
+ if (inviteCode != null) {
|
|
|
User inviteUser = iUserService.queryByAccount(inviteCode);
|
|
|
- if(inviteUser!=null){
|
|
|
+ if (inviteUser != null) {
|
|
|
bo.setInviteUserAccount(inviteCode);
|
|
|
}
|
|
|
}
|
|
|
- if(iUserService.save(bo)){
|
|
|
- iSmsService.sendPwdSms(bo.getTelphone(),pwd);
|
|
|
+ if (iUserService.save(bo)) {
|
|
|
+ iSmsService.sendPwdSms(bo.getTelphone(), pwd);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
//小程序获取用户openid
|
|
|
- public String getWxOpenId(WxLoginBody loginBody,Long userId) {
|
|
|
+ public String getWxOpenId(WxLoginBody loginBody, Long userId) {
|
|
|
LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
|
|
|
lqw.eq(User::getUserId, userId);
|
|
|
User user = iUserService.getOne(lqw);
|
|
@@ -305,7 +312,7 @@ public class WxLoginService implements IWxLoginService
|
|
|
|
|
|
//每次更新最新openid
|
|
|
String param = String.format(wxAuthParam, appid, appsrcret, loginBody.getCode());
|
|
|
- String resultString = HttpUtils.sendGet(wxAuthUrl,param);
|
|
|
+ String resultString = HttpUtils.sendGet(wxAuthUrl, param);
|
|
|
//解析json
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
String session_key = String.valueOf(jsonObject.get("session_key"));
|
|
@@ -319,32 +326,32 @@ public class WxLoginService implements IWxLoginService
|
|
|
//小程序获取用户信息
|
|
|
public User getWxUnionIdUser(WxLoginBody loginBody) {
|
|
|
String param = String.format(wxAuthParam, appid, appsrcret, loginBody.getCode());
|
|
|
- String resultString = HttpUtils.sendGet(wxAuthUrl,param);
|
|
|
+ String resultString = HttpUtils.sendGet(wxAuthUrl, param);
|
|
|
//解析json
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
String session_key = String.valueOf(jsonObject.get("session_key"));
|
|
|
String openId = String.valueOf(jsonObject.get("openid"));
|
|
|
String unionId = null;
|
|
|
- if(jsonObject.containsKey("unionid")){ //当没绑定开放平台
|
|
|
+ if (jsonObject.containsKey("unionid")) { //当没绑定开放平台
|
|
|
unionId = String.valueOf(jsonObject.get("unionid"));
|
|
|
}
|
|
|
- String phoneNumber = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),session_key);
|
|
|
- if(Validator.isEmpty(phoneNumber)){
|
|
|
- throw new CustomException("该微信没有绑定手机号码"+resultString);
|
|
|
+ String phoneNumber = obtainWxPhone(loginBody.getIv(), loginBody.getEncryptedData(), session_key);
|
|
|
+ if (Validator.isEmpty(phoneNumber)) {
|
|
|
+ throw new CustomException("该微信没有绑定手机号码" + resultString);
|
|
|
}
|
|
|
User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getTelphone,phoneNumber).last("limit 1"));
|
|
|
- if(Validator.isNotEmpty(user)){
|
|
|
+ .eq(User::getTelphone, phoneNumber).last("limit 1"));
|
|
|
+ if (Validator.isNotEmpty(user)) {
|
|
|
user.setOpenId(openId);
|
|
|
user.setUnionId(unionId);
|
|
|
user.setLastLoginTime(DateUtils.getNowTime());
|
|
|
user.setUpdateTime(DateUtils.getNowTime());
|
|
|
iUserService.updateById(user);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//手机匹配不上再匹配openid
|
|
|
user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getOpenId,openId).last("limit 1"));
|
|
|
- if(Validator.isNotEmpty(user)){
|
|
|
+ .eq(User::getOpenId, openId).last("limit 1"));
|
|
|
+ if (Validator.isNotEmpty(user)) {
|
|
|
user.setTelphone(phoneNumber);
|
|
|
user.setUnionId(unionId);
|
|
|
user.setUpdateTime(DateUtils.getNowTime());
|
|
@@ -352,12 +359,12 @@ public class WxLoginService implements IWxLoginService
|
|
|
iUserService.updateById(user);
|
|
|
}
|
|
|
}
|
|
|
- if(user==null){
|
|
|
- if(!register_small(openId,unionId,phoneNumber,loginBody.getInviteCode())){
|
|
|
+ if (user == null) {
|
|
|
+ if (!register_small(openId, unionId, phoneNumber, loginBody.getInviteCode())) {
|
|
|
throw new CustomException("注册失败");
|
|
|
}
|
|
|
user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getTelphone,phoneNumber).last("limit 1"));
|
|
|
+ .eq(User::getTelphone, phoneNumber).last("limit 1"));
|
|
|
}
|
|
|
return user;
|
|
|
}
|
|
@@ -365,17 +372,17 @@ public class WxLoginService implements IWxLoginService
|
|
|
public String getWxSmallAccessToken() {
|
|
|
String key = "WX_SMALL_ACCESS_TOKEN";
|
|
|
String accessToken = redisCache.getCacheObject(key);
|
|
|
- if(Validator.isEmpty(accessToken)||accessToken.equals("null")){
|
|
|
+ if (Validator.isEmpty(accessToken) || accessToken.equals("null")) {
|
|
|
String param = String.format(gzh_wxTokenParam, appid, appsrcret);
|
|
|
- String resultString = HttpUtils.sendGet(gzh_wxTokenUrl,param);
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxTokenUrl, param);
|
|
|
//解析json
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
- if(jsonObject.containsKey("access_token")){
|
|
|
+ if (jsonObject.containsKey("access_token")) {
|
|
|
accessToken = String.valueOf(jsonObject.get("access_token"));
|
|
|
- if(Validator.isNotEmpty(accessToken)&&!accessToken.equals("null")){
|
|
|
- redisCache.setCacheObject(key, accessToken,7100, TimeUnit.SECONDS);//7200有效期
|
|
|
+ if (Validator.isNotEmpty(accessToken) && !accessToken.equals("null")) {
|
|
|
+ redisCache.setCacheObject(key, accessToken, 7100, TimeUnit.SECONDS);//7200有效期
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
@@ -385,18 +392,18 @@ public class WxLoginService implements IWxLoginService
|
|
|
public String getWxGzhAccessToken() {
|
|
|
String key = "WX_GZH_ACCESS_TOKEN";
|
|
|
String accessToken = redisCache.getCacheObject(key);
|
|
|
- if(Validator.isEmpty(accessToken)||accessToken.equals("null")){
|
|
|
+ if (Validator.isEmpty(accessToken) || accessToken.equals("null")) {
|
|
|
String param = String.format(gzh_wxTokenParam, gzh_appid, gzh_appsrcret);
|
|
|
- String resultString = HttpUtils.sendGet(gzh_wxTokenUrl,param);
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxTokenUrl, param);
|
|
|
System.out.println(resultString);
|
|
|
//解析json
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
- if(jsonObject.containsKey("access_token")){
|
|
|
+ if (jsonObject.containsKey("access_token")) {
|
|
|
accessToken = String.valueOf(jsonObject.get("access_token"));
|
|
|
- if(Validator.isNotEmpty(accessToken)&&!accessToken.equals("null")){
|
|
|
- redisCache.setCacheObject(key, accessToken,7100, TimeUnit.SECONDS);//7200有效期
|
|
|
+ if (Validator.isNotEmpty(accessToken) && !accessToken.equals("null")) {
|
|
|
+ redisCache.setCacheObject(key, accessToken, 7100, TimeUnit.SECONDS);//7200有效期
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
@@ -405,49 +412,50 @@ public class WxLoginService implements IWxLoginService
|
|
|
|
|
|
public String getWxGzhUserList(String nextOpenid) {
|
|
|
String accessToken = getWxGzhAccessToken();
|
|
|
- if(Validator.isEmpty(accessToken)){
|
|
|
+ if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("accessToken 错误");
|
|
|
}
|
|
|
String param = String.format(gzh_wxUserListParam, accessToken);
|
|
|
- if(Validator.isNotEmpty(nextOpenid)){
|
|
|
- param += "&next_openid="+nextOpenid;
|
|
|
- }else{
|
|
|
+ if (Validator.isNotEmpty(nextOpenid)) {
|
|
|
+ param += "&next_openid=" + nextOpenid;
|
|
|
+ } else {
|
|
|
iUserWxFollowService.cleanAllData();
|
|
|
}
|
|
|
- String resultString = HttpUtils.sendGet(gzh_wxUserListUrl,param);
|
|
|
- if(Validator.isNotEmpty(resultString)){
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxUserListUrl, param);
|
|
|
+ if (Validator.isNotEmpty(resultString)) {
|
|
|
JSONObject userInfoJSON = null;
|
|
|
userInfoJSON = JSON.parseObject(resultString);
|
|
|
- if(userInfoJSON.containsKey("total")){
|
|
|
+ if (userInfoJSON.containsKey("total")) {
|
|
|
Integer total = Integer.valueOf(String.valueOf(userInfoJSON.get("total")));
|
|
|
Integer count = Integer.valueOf(String.valueOf(userInfoJSON.get("count")));
|
|
|
String nextOpenidBack = String.valueOf(userInfoJSON.get("next_openid"));
|
|
|
- if(Validator.isNotEmpty(nextOpenidBack)&&!nextOpenidBack.equals("")){
|
|
|
+ if (Validator.isNotEmpty(nextOpenidBack) && !nextOpenidBack.equals("")) {
|
|
|
getWxGzhUserList(nextOpenidBack);
|
|
|
}
|
|
|
- if(userInfoJSON.containsKey("data")){
|
|
|
- List<String> openIdList = JSONArray.parseArray(userInfoJSON.getJSONObject("data").getJSONArray("openid").toJSONString(),String.class);
|
|
|
+ if (userInfoJSON.containsKey("data")) {
|
|
|
+ List<String> openIdList = JSONArray.parseArray(userInfoJSON.getJSONObject("data").getJSONArray("openid").toJSONString(), String.class);
|
|
|
List<List<String>> lists = ToolsUtils.splitListBycapacity(openIdList, 1000);
|
|
|
- for (List<String> listSub:lists) {
|
|
|
+ for (List<String> listSub : lists) {
|
|
|
iUserWxFollowService.insertByBatchAddBo(listSub);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // System.out.println(resultString);
|
|
|
return resultString;
|
|
|
}
|
|
|
|
|
|
public String getWxGzhUserCgiInfo(String openid) {
|
|
|
String accessToken = getWxGzhAccessToken();
|
|
|
- if(Validator.isEmpty(accessToken)){
|
|
|
+ if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("accessToken 错误");
|
|
|
}
|
|
|
- String param = String.format(gzh_wxUserCgiInfoParam, accessToken,openid);
|
|
|
- String resultString = HttpUtils.sendGet(gzh_wxUserCgiInfoUrl,param);
|
|
|
- if(Validator.isNotEmpty(resultString)){
|
|
|
+ String param = String.format(gzh_wxUserCgiInfoParam, accessToken, openid);
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxUserCgiInfoUrl, param);
|
|
|
+ if (Validator.isNotEmpty(resultString)) {
|
|
|
JSONObject userInfoJSON = null;
|
|
|
userInfoJSON = JSON.parseObject(resultString);
|
|
|
- if(userInfoJSON.containsKey("unionid")){
|
|
|
+ if (userInfoJSON.containsKey("unionid")) {
|
|
|
return String.valueOf(userInfoJSON.get("unionid"));
|
|
|
}
|
|
|
}
|
|
@@ -455,9 +463,9 @@ public class WxLoginService implements IWxLoginService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String sendSmallTpMsg(String openId,Map<String,String> paramMap) {
|
|
|
+ public String sendSmallTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
- if(Validator.isEmpty(accessToken)){
|
|
|
+ if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
|
}
|
|
|
String param = String.format(small_wxSendTpParam, accessToken);
|
|
@@ -467,7 +475,7 @@ public class WxLoginService implements IWxLoginService
|
|
|
JSONObject miniprogram = new JSONObject();
|
|
|
|
|
|
obj.put("touser", openId);
|
|
|
- paramMap.put("access_token",accessToken);
|
|
|
+ paramMap.put("access_token", accessToken);
|
|
|
mp_template_msg.put("appid", gzh_appid);
|
|
|
mp_template_msg.put("template_id", studyNoteTpId);
|
|
|
mp_template_msg.put("url", "http://weixin.qq.com/download"); //公众号模板消息所要跳转的url
|
|
@@ -504,9 +512,43 @@ public class WxLoginService implements IWxLoginService
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public Boolean subGzh(String openId){
|
|
|
+ @Override
|
|
|
+ public String getLiveEnCode(SectionWatchPerBo watchPer) {
|
|
|
+ String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
+ String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
|
|
|
+ String url = small_wxEnCodeUrl + "?" + param;
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("page", "pages/webview/index");
|
|
|
+ StringBuilder sceneParam = new StringBuilder();
|
|
|
+ sceneParam.append("gid=").append(watchPer.getGoodsId()).append("&");
|
|
|
+ sceneParam.append("cid=").append(watchPer.getCourseId()).append("&");
|
|
|
+ sceneParam.append("sid=").append(watchPer.getSectionId()).append("&");
|
|
|
+ sceneParam.append("a=1");
|
|
|
+ obj.put("scene",sceneParam.toString());
|
|
|
+ String result = HttpUtils.sendPost(url, obj);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getBackEnCode(SectionWatchPerBo watchPer) {
|
|
|
+ String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
+ String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
|
|
|
+ String url = small_wxEnCodeUrl + "?" + param;
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("page", "/pages3/live/detail");
|
|
|
+ StringBuilder sceneParam = new StringBuilder();
|
|
|
+ sceneParam.append("gid=").append(watchPer.getGoodsId()).append("&");
|
|
|
+ sceneParam.append("cid=").append(watchPer.getCourseId()).append("&");
|
|
|
+ sceneParam.append("sid=").append(watchPer.getSectionId()).append("&");
|
|
|
+ sceneParam.append("a=1");
|
|
|
+ obj.put("scene",sceneParam.toString());
|
|
|
+ String result = HttpUtils.sendPost(url, obj);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean subGzh(String openId) {
|
|
|
String unionId = getWxGzhUserCgiInfo(openId);
|
|
|
- if(Validator.isNotEmpty(unionId)){
|
|
|
+ if (Validator.isNotEmpty(unionId)) {
|
|
|
unsubGzh(openId);
|
|
|
UserWxFollowAddBo addBo = new UserWxFollowAddBo();
|
|
|
addBo.setGzhOpenId(openId);
|
|
@@ -516,36 +558,36 @@ public class WxLoginService implements IWxLoginService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public Boolean unsubGzh(String openId){
|
|
|
+ public Boolean unsubGzh(String openId) {
|
|
|
return iUserWxFollowService.unsubGzh(openId);
|
|
|
}
|
|
|
|
|
|
//公众号获取用户信息
|
|
|
public User getWxGzhUnionIdUser(WxLoginBody loginBody) {
|
|
|
String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
|
|
|
- String resultString = HttpUtils.sendGet(gzh_wxAuthUrl,param);
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
|
|
|
//解析json
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
String access_token = String.valueOf(jsonObject.get("access_token"));
|
|
|
String openId = String.valueOf(jsonObject.get("openid"));
|
|
|
|
|
|
String userInfoParam = String.format(gzh_wxUserInfoParam, access_token, openId);
|
|
|
- String userInfoResultString = HttpUtils.sendGet(gzh_wxUserInfoUrl,userInfoParam);
|
|
|
+ String userInfoResultString = HttpUtils.sendGet(gzh_wxUserInfoUrl, userInfoParam);
|
|
|
//解析json
|
|
|
JSONObject jsonObject1 = (JSONObject) JSONObject.parse(userInfoResultString);
|
|
|
String unionId = String.valueOf(jsonObject1.get("unionid"));
|
|
|
User user = iUserService.queryByUnionId(unionId);
|
|
|
- if(user==null){
|
|
|
+ if (user == null) {
|
|
|
throw new CustomException("您尚未注册,请前往小程序注册");
|
|
|
}
|
|
|
- if(!Validator.isNotNull(user.getGzhOpenId())){
|
|
|
+ if (!Validator.isNotNull(user.getGzhOpenId())) {
|
|
|
user.setGzhOpenId(openId);
|
|
|
iUserService.updateById(user);
|
|
|
}
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
- public String obtainWxPhone(String iv, String encryptedData,String session_key){
|
|
|
+ public String obtainWxPhone(String iv, String encryptedData, String session_key) {
|
|
|
String userInfo = null;
|
|
|
JSONObject userInfoJSON = null;
|
|
|
try {
|
|
@@ -555,9 +597,9 @@ public class WxLoginService implements IWxLoginService
|
|
|
|
|
|
userInfo = new String(resultByte, "UTF-8");
|
|
|
userInfoJSON = JSON.parseObject(userInfo);
|
|
|
- if(userInfoJSON.containsKey("phoneNumber")){
|
|
|
+ if (userInfoJSON.containsKey("phoneNumber")) {
|
|
|
return String.valueOf(userInfoJSON.get("phoneNumber"));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return null;
|
|
|
}
|
|
|
} catch (Exception e) {
|