|
@@ -24,6 +24,7 @@ import com.zhongzheng.modules.alisms.service.IAliSmsService;
|
|
|
import com.zhongzheng.modules.course.bo.SectionWatchPerBo;
|
|
|
import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
+import com.zhongzheng.modules.system.service.ISysConfigService;
|
|
|
import com.zhongzheng.modules.user.bo.UserWxFollowAddBo;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
|
import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
@@ -56,23 +57,23 @@ public class WxLoginService implements IWxLoginService {
|
|
|
@Autowired
|
|
|
private WxTokenService wxTokenService;
|
|
|
|
|
|
- @Value("${wx.small.appid}")
|
|
|
+ // @Value("${wx.small.appid}")
|
|
|
private String appid;
|
|
|
|
|
|
- @Value("${wx.small.appsecret}")
|
|
|
+ // @Value("${wx.small.appsecret}")
|
|
|
private String appsrcret;
|
|
|
|
|
|
private String wxAuthUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
|
|
|
private String wxAuthParam = "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
|
|
|
|
|
|
- @Value("${wx.gzh.appid}")
|
|
|
+ // @Value("${wx.gzh.appid}")
|
|
|
private String gzh_appid;
|
|
|
|
|
|
- @Value("${wx.scanLogin.host}")
|
|
|
+ // @Value("${wx.scanLogin.host}")
|
|
|
private String scanLoginHost;
|
|
|
|
|
|
- @Value("${wx.gzh.appsecret}")
|
|
|
+ // @Value("${wx.gzh.appsecret}")
|
|
|
private String gzh_appsrcret;
|
|
|
|
|
|
@Value("${wx.gzh.studyNoteTpId}")
|
|
@@ -149,8 +150,21 @@ public class WxLoginService implements IWxLoginService {
|
|
|
@Autowired
|
|
|
private IGoodsService iGoodsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
+ public void initData(){
|
|
|
+ appid = configService.selectConfigByKey("wx.small.appid");
|
|
|
+ appsrcret = configService.selectConfigByKey("wx.small.appsecret");
|
|
|
+ gzh_appsrcret = configService.selectConfigByKey("wx.gzh.appsecret");
|
|
|
+ gzh_appid = configService.selectConfigByKey("wx.gzh.appid");
|
|
|
+ scanLoginHost = configService.selectConfigByKey("wx.scanLogin.host");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public Map<String, String> test_login() {
|
|
|
+ initData();
|
|
|
String unionId = "oQ2yp56PgQ-PfwN4vxTZhR5eTpzk";
|
|
|
User user = iUserService.queryByUnionId(unionId);
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
@@ -163,6 +177,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> pcLoginUrl() {
|
|
|
+ initData();
|
|
|
String scanCode = ToolsUtils.getCharAndNumr(6);
|
|
|
String key = "SCAN_LOGIN_" + scanCode;
|
|
|
String keyStatus = "SCAN_LOGIN_STATUS_" + scanCode; //0未扫码 1已扫码 2已登录
|
|
@@ -196,6 +211,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, Object> checkPcLogin(String scanCode) {
|
|
|
+ initData();
|
|
|
String key = "SCAN_LOGIN_" + scanCode;
|
|
|
String keyStatus = "SCAN_LOGIN_STATUS_" + scanCode; //0未扫码 1已扫码 2已登录
|
|
|
Long userId = redisCache.getCacheObject(key);
|
|
@@ -221,6 +237,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> login(WxLoginBody loginBody) {
|
|
|
+ initData();
|
|
|
User user = getWxUnionIdUser(loginBody);
|
|
|
if (user == null) {
|
|
|
throw new CustomException("登录错误");
|
|
@@ -236,6 +253,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
|
|
|
public Map<String, String> smallTel(WxLoginBody loginBody) {
|
|
|
+ initData();
|
|
|
User user = getWxUnionIdUser(loginBody);
|
|
|
if (user == null) {
|
|
|
throw new CustomException("登录错误");
|
|
@@ -249,6 +267,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
|
|
|
public Map<String, String> gzh_login(WxLoginBody loginBody) {
|
|
|
+ initData();
|
|
|
User user = getWxGzhUnionIdUser(loginBody);
|
|
|
if (user == null) {
|
|
|
throw new CustomException("登录错误");
|
|
@@ -262,6 +281,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
|
|
|
public String refreshToken(String userAccount) {
|
|
|
+ initData();
|
|
|
User user = iUserService.queryByAccount(userAccount);
|
|
|
if (user == null) {
|
|
|
throw new CustomException("userAccount不存在");
|
|
@@ -283,6 +303,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean register_small(String openId, String unionId, String tel, String inviteCode, String shareCode) {
|
|
|
+ initData();
|
|
|
User bo = new User();
|
|
|
bo.setOpenId(openId);
|
|
|
bo.setUnionId(unionId);
|
|
@@ -319,6 +340,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
//小程序获取用户openid
|
|
|
public String getWxOpenId(WxLoginBody loginBody, Long userId) {
|
|
|
+ initData();
|
|
|
LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
|
|
|
lqw.eq(User::getUserId, userId);
|
|
|
User user = iUserService.getOne(lqw);
|
|
@@ -339,6 +361,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
//小程序获取用户信息
|
|
|
public User getWxUnionIdUser(WxLoginBody loginBody) {
|
|
|
+ initData();
|
|
|
String param = String.format(wxAuthParam, appid, appsrcret, loginBody.getCode());
|
|
|
String resultString = HttpUtils.sendGet(wxAuthUrl, param);
|
|
|
//解析json
|
|
@@ -384,6 +407,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
|
|
|
public String getWxSmallAccessToken() {
|
|
|
+ initData();
|
|
|
String key = "WX_SMALL_ACCESS_TOKEN";
|
|
|
String accessToken = redisCache.getCacheObject(key);
|
|
|
if (Validator.isEmpty(accessToken) || accessToken.equals("null")) {
|
|
@@ -404,6 +428,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
|
|
|
public String getWxGzhAccessToken() {
|
|
|
+ initData();
|
|
|
String key = "WX_GZH_ACCESS_TOKEN";
|
|
|
String accessToken = redisCache.getCacheObject(key);
|
|
|
if (Validator.isEmpty(accessToken) || accessToken.equals("null")) {
|
|
@@ -425,6 +450,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
|
|
|
public String getWxGzhUserList(String nextOpenid) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxGzhAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("accessToken 错误");
|
|
@@ -460,6 +486,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
|
|
|
public String getWxGzhUserCgiInfo(String openid) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxGzhAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("accessToken 错误");
|
|
@@ -478,6 +505,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String sendSmallTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
@@ -528,6 +556,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String getLiveEnCode(SectionWatchPerBo watchPer) {
|
|
|
+ initData();
|
|
|
String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
|
|
|
String url = small_wxEnCodeUrl + "?" + param;
|
|
@@ -559,6 +588,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String getBackEnCode(SectionWatchPerBo watchPer) {
|
|
|
+ initData();
|
|
|
String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
|
|
|
String url = small_wxEnCodeUrl + "?" + param;
|
|
@@ -576,6 +606,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String sendQdyTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
@@ -631,6 +662,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String sendQdySubTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
@@ -691,6 +723,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String sendQdySubStatusTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
@@ -745,6 +778,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String sendQdyExamTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
@@ -795,6 +829,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String sendQdyExamStatusTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
@@ -845,6 +880,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String sendSignatureTpMsg(String openId, Map<String, String> paramMap) {
|
|
|
+ initData();
|
|
|
String accessToken = getWxSmallAccessToken();
|
|
|
if (Validator.isEmpty(accessToken)) {
|
|
|
throw new CustomException("小程序accessToken 错误");
|
|
@@ -895,6 +931,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String getActivityApplyCode(Long activityId) {
|
|
|
+ initData();
|
|
|
String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
|
|
|
String url = small_wxEnCodeUrl + "?" + param;
|
|
@@ -921,6 +958,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String getTopicEnCode(Long topicId) {
|
|
|
+ initData();
|
|
|
String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
|
|
|
String url = small_wxEnCodeUrl + "?" + param;
|
|
@@ -948,6 +986,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String shareGoodsCode(WxShareGoodsBo bo) {
|
|
|
+ initData();
|
|
|
GoodsVo goodsVo = iGoodsService.queryById(bo.getGoodsId());
|
|
|
if(Validator.isEmpty(goodsVo)){
|
|
|
throw new CustomException("商品ID错误");
|
|
@@ -993,6 +1032,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public WxInfoBo getWxInfo(WxInfoQuery query) {
|
|
|
+ initData();
|
|
|
Long time = System.currentTimeMillis();
|
|
|
String nonceStr = UUID.randomUUID().toString();
|
|
|
String ticket = "";
|
|
@@ -1030,6 +1070,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String getWxSmallLink() {
|
|
|
+ initData();
|
|
|
String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
String param = String.format(small_LinkParam, wxGzhAccessToken);
|
|
|
String url = small_LinkUrl + "?" + param;
|
|
@@ -1060,6 +1101,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
@Override
|
|
|
public String getWxSmallStudyCentreLink() {
|
|
|
+ initData();
|
|
|
String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
String param = String.format(small_LinkParam, wxGzhAccessToken);
|
|
|
String url = small_LinkUrl + "?" + param;
|
|
@@ -1106,6 +1148,7 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
//公众号获取用户信息
|
|
|
public User getWxGzhUnionIdUser(WxLoginBody loginBody) {
|
|
|
+ initData();
|
|
|
String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
|
|
|
String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
|
|
|
//解析json
|