记得上下班打卡 | git大法好,push需谨慎

Commit ae352386 authored by Administrator's avatar Administrator 🎨

Merge branch 'pre' into 'master'

Pre

See merge request !14
parents 0f1647ea c7ab86e1
...@@ -3,8 +3,12 @@ package com.liquidnet.service.adam.config; ...@@ -3,8 +3,12 @@ package com.liquidnet.service.adam.config;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
...@@ -67,11 +71,17 @@ public class WechatMaConfigure { ...@@ -67,11 +71,17 @@ public class WechatMaConfigure {
private WxMaService wxMaAppletFiveService; private WxMaService wxMaAppletFiveService;
private WxMaService wxMaAppletMdskService; private WxMaService wxMaAppletMdskService;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@PostConstruct @PostConstruct
public void init() { public void init() {
wxMaAppletZhengzaiService = new WxMaServiceImpl() { wxMaAppletZhengzaiService = new WxMaServiceImpl() {
{ {
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl(); RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "adam:accessToken:applet:zhengzai");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidZhengzai); wxMaDefaultConfig.setAppid(appletAppidZhengzai);
wxMaDefaultConfig.setSecret(appletSecretZhengzai); wxMaDefaultConfig.setSecret(appletSecretZhengzai);
wxMaDefaultConfig.setMsgDataFormat("JSON"); wxMaDefaultConfig.setMsgDataFormat("JSON");
...@@ -81,7 +91,10 @@ public class WechatMaConfigure { ...@@ -81,7 +91,10 @@ public class WechatMaConfigure {
}; };
wxMaAppletStrawberryService = new WxMaServiceImpl() { wxMaAppletStrawberryService = new WxMaServiceImpl() {
{ {
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl(); RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:strawberry");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidStrawberry); wxMaDefaultConfig.setAppid(appletAppidStrawberry);
wxMaDefaultConfig.setSecret(appletSecretStrawberry); wxMaDefaultConfig.setSecret(appletSecretStrawberry);
wxMaDefaultConfig.setMsgDataFormat("JSON"); wxMaDefaultConfig.setMsgDataFormat("JSON");
...@@ -91,7 +104,10 @@ public class WechatMaConfigure { ...@@ -91,7 +104,10 @@ public class WechatMaConfigure {
}; };
wxMaAppletFiveService = new WxMaServiceImpl() { wxMaAppletFiveService = new WxMaServiceImpl() {
{ {
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl(); RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:five");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidFive); wxMaDefaultConfig.setAppid(appletAppidFive);
wxMaDefaultConfig.setSecret(appletSecretFive); wxMaDefaultConfig.setSecret(appletSecretFive);
wxMaDefaultConfig.setMsgDataFormat("JSON"); wxMaDefaultConfig.setMsgDataFormat("JSON");
...@@ -101,7 +117,10 @@ public class WechatMaConfigure { ...@@ -101,7 +117,10 @@ public class WechatMaConfigure {
}; };
wxMaAppletMdskService = new WxMaServiceImpl() { wxMaAppletMdskService = new WxMaServiceImpl() {
{ {
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl(); RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:mdsk");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidMdsk); wxMaDefaultConfig.setAppid(appletAppidMdsk);
wxMaDefaultConfig.setSecret(appletSecretMdsk); wxMaDefaultConfig.setSecret(appletSecretMdsk);
wxMaDefaultConfig.setMsgDataFormat("JSON"); wxMaDefaultConfig.setMsgDataFormat("JSON");
......
package com.liquidnet.service.sweet.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import javax.annotation.PostConstruct;
@Configuration
public class WechatMaConfigure {
private static String appletAppidZhengzai;
private static String appletSecretZhengzai;
private static String appletAppidStrawberry;
private static String appletSecretStrawberry;
private static String appletAppidFive;
private static String appletSecretFive;
private static String appletAppidMdsk;
private static String appletSecretMdsk;
@Value("${liquidnet.wechat.applet.zhengzai.appid}")
public void setAppletAppidZhengzai(String appletAppidZhengzai) {
WechatMaConfigure.appletAppidZhengzai = appletAppidZhengzai;
}
@Value("${liquidnet.wechat.applet.zhengzai.secret}")
public void setAppletSecretZhengzai(String appletSecretZhengzai) {
WechatMaConfigure.appletSecretZhengzai = appletSecretZhengzai;
}
@Value("${liquidnet.wechat.applet.strawberry.appid}")
public void setAppletAppidStrawberry(String appletAppidStrawberry) {
WechatMaConfigure.appletAppidStrawberry = appletAppidStrawberry;
}
@Value("${liquidnet.wechat.applet.strawberry.secret}")
public void setAppletSecretStrawberry(String appletSecretStrawberry) {
WechatMaConfigure.appletSecretStrawberry = appletSecretStrawberry;
}
@Value("${liquidnet.wechat.applet.five.appid}")
public void setAppletAppidFive(String appletAppidFive) {
WechatMaConfigure.appletAppidFive = appletAppidFive;
}
@Value("${liquidnet.wechat.applet.five.secret}")
public void setAppletSecretFive(String appletSecretFive) {
WechatMaConfigure.appletSecretFive = appletSecretFive;
}
@Value("${liquidnet.wechat.applet.mdsk.appid}")
public void setAppletAppidMdsk(String appletAppidMdsk) {
WechatMaConfigure.appletAppidMdsk = appletAppidMdsk;
}
@Value("${liquidnet.wechat.applet.mdsk.secret}")
public void setAppletSecretMdsk(String appletSecretMdsk) {
WechatMaConfigure.appletSecretMdsk = appletSecretMdsk;
}
private WxMaService wxMaAppletZhengzaiService;
private WxMaService wxMaAppletStrawberryService;
private WxMaService wxMaAppletFiveService;
private WxMaService wxMaAppletMdskService;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@PostConstruct
public void init() {
wxMaAppletZhengzaiService = new WxMaServiceImpl() {
{
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:zhengzai");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidZhengzai);
wxMaDefaultConfig.setSecret(appletSecretZhengzai);
wxMaDefaultConfig.setMsgDataFormat("JSON");
this.setWxMaConfig(wxMaDefaultConfig);
}
};
wxMaAppletStrawberryService = new WxMaServiceImpl() {
{
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:strawberry");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidStrawberry);
wxMaDefaultConfig.setSecret(appletSecretStrawberry);
wxMaDefaultConfig.setMsgDataFormat("JSON");
this.setWxMaConfig(wxMaDefaultConfig);
}
};
wxMaAppletFiveService = new WxMaServiceImpl() {
{
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:five");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidFive);
wxMaDefaultConfig.setSecret(appletSecretFive);
wxMaDefaultConfig.setMsgDataFormat("JSON");
this.setWxMaConfig(wxMaDefaultConfig);
}
};
wxMaAppletMdskService = new WxMaServiceImpl() {
{
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:mdsk");
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appletAppidMdsk);
wxMaDefaultConfig.setSecret(appletSecretMdsk);
wxMaDefaultConfig.setMsgDataFormat("JSON");
this.setWxMaConfig(wxMaDefaultConfig);
}
};
}
public WxMaService getWxMaService(Integer anum) {
switch (anum) {
case 4:
return wxMaAppletZhengzaiService;
case 1:
return wxMaAppletStrawberryService;
case 2:
return wxMaAppletFiveService;
case 3:
return wxMaAppletMdskService;
}
return null;
}
}
...@@ -12,6 +12,7 @@ import com.liquidnet.commons.lang.util.JsonUtils; ...@@ -12,6 +12,7 @@ import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -50,7 +51,46 @@ public class SweetWechatLoginServiceImpl { ...@@ -50,7 +51,46 @@ public class SweetWechatLoginServiceImpl {
@Value("${liquidnet.wechat.applet.zhengzai.secret}") @Value("${liquidnet.wechat.applet.zhengzai.secret}")
private String zhengzaiSecret; private String zhengzaiSecret;
@Autowired
private SweetWechatService sweetWechatService;
public ResponseDto userInfo(String code, String encryptedData, String iv, Integer type) { public ResponseDto userInfo(String code, String encryptedData, String iv, Integer type) {
log.info("\n参数code:[{}] ", code);
log.info("\n参数encryptedData:[{}] ", encryptedData);
log.info("\n参数iv:[{}] ", iv);
log.info("\n参数type:[{}] ", type);
try {
WxMaJscode2SessionResult sessionInfo = sweetWechatService.sessionInfo(code, type);
log.info("\nWxMaJscode2SessionResult:[{}] ", JsonUtils.toJson(sessionInfo));
if (null == sessionInfo) {
return ResponseDto.failure("login handler error");
}
// 解密手机号码信息
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = sweetWechatService.phoneNumberInfo(sessionInfo.getSessionKey(), encryptedData, iv, type);
log.info("\nWxMaPhoneNumberInfo:[{}] ", wxMaPhoneNumberInfo.toString());
if (Objects.isNull(wxMaPhoneNumberInfo) || StringUtils.isBlank(wxMaPhoneNumberInfo.getPhoneNumber())) {
return ResponseDto.failure("解密手机号码信息错误");
}
String unionId = sessionInfo.getUnionid();
String openId = sessionInfo.getOpenid();
HashMap<String,Object> userInfo = CollectionUtil.mapStringObject();
userInfo.put("unionId", unionId);
userInfo.put("openId", openId);
userInfo.put("getPhoneNumber", wxMaPhoneNumberInfo.getPhoneNumber());
userInfo.put("getPurePhoneNumber", wxMaPhoneNumberInfo.getPurePhoneNumber());
userInfo.put("getCountryCode", wxMaPhoneNumberInfo.getCountryCode());
return ResponseDto.success(userInfo);
} catch (Exception e) {
log.error("WechatUserInfoError", e);
return ResponseDto.failure();
}
}
/*public ResponseDto userInfo(String code, String encryptedData, String iv, Integer type) {
log.info("\n参数code:[{}] ", code); log.info("\n参数code:[{}] ", code);
log.info("\n参数encryptedData:[{}] ", encryptedData); log.info("\n参数encryptedData:[{}] ", encryptedData);
log.info("\n参数iv:[{}] ", iv); log.info("\n参数iv:[{}] ", iv);
...@@ -107,7 +147,7 @@ public class SweetWechatLoginServiceImpl { ...@@ -107,7 +147,7 @@ public class SweetWechatLoginServiceImpl {
e.printStackTrace(); e.printStackTrace();
return ResponseDto.failure(); return ResponseDto.failure();
} }
} }*/
private WxMaConfig wxMaConfig(String appId, String appSecret) { private WxMaConfig wxMaConfig(String appId, String appSecret) {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
......
package com.liquidnet.service.sweet.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.liquidnet.service.sweet.config.WechatMaConfigure;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class SweetWechatService {
@Autowired
WechatMaConfigure wechatMaConfigure;
public WxMaJscode2SessionResult sessionInfo(String code, Integer anum) throws WxErrorException {
WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
log.info("isAccessTokenExpired:[{}] ", wxMaService.getWxMaConfig().isAccessTokenExpired());
log.info("getAccessToken:[{}] ", wxMaService.getWxMaConfig().getAccessToken());
return wxMaService.getUserService().getSessionInfo(code);
}
public WxMaUserInfo userInfo(String sessionKey, String encryptedData, String iv, Integer anum) {
WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
return wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
}
public WxMaPhoneNumberInfo phoneNumberInfo(String sessionKey, String encryptedData, String iv, Integer anum) {
WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
return wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment