|
|
|
@@ -6,17 +6,14 @@ import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
|
|
|
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig; |
|
|
|
import com.simple.common.ErrorCode; |
|
|
|
import com.simple.domain.po.WxAppinfo; |
|
|
|
import com.simple.domain.po.WxCUser; |
|
|
|
import com.simple.domain.po.WxMerchantBUser; |
|
|
|
import com.simple.exception.MallinkException; |
|
|
|
import com.simple.interceptor.AuthorizationInterceptor; |
|
|
|
import com.simple.service.WxAppinfoService; |
|
|
|
import com.simple.service.WxCUserService; |
|
|
|
import com.simple.service.WxMerchantBUserService; |
|
|
|
import com.simple.utils.MaUtil; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
import org.springframework.web.bind.annotation.InitBinder; |
|
|
|
@@ -56,20 +53,23 @@ public class BaseController { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public Long getUserId() { |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
Long bUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); |
|
|
|
return bUserId; |
|
|
|
} |
|
|
|
|
|
|
|
public WxMerchantBUser getUser() { |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
Long cUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); |
|
|
|
WxMerchantBUser user = wxMerchantBUserService.getById(cUserId); |
|
|
|
Long bUserId = getUserId(); |
|
|
|
WxMerchantBUser user = wxMerchantBUserService.getById(bUserId); |
|
|
|
if (user == null) |
|
|
|
throw new MallinkException(ErrorCode.USER_IS_EMPTY); |
|
|
|
return user; |
|
|
|
} |
|
|
|
|
|
|
|
public String getTenantId() { |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
Long cUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); |
|
|
|
WxMerchantBUser user = wxMerchantBUserService.getById(cUserId); |
|
|
|
Long bUserId = getUserId(); |
|
|
|
WxMerchantBUser user = wxMerchantBUserService.getById(bUserId); |
|
|
|
if (user == null) |
|
|
|
throw new MallinkException(ErrorCode.USER_IS_EMPTY); |
|
|
|
return user.getTenantId(); |
|
|
|
@@ -80,31 +80,13 @@ public class BaseController { |
|
|
|
} |
|
|
|
|
|
|
|
public WxMaService getWeappService(String appId) { |
|
|
|
|
|
|
|
WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); |
|
|
|
|
|
|
|
WxMaInMemoryConfig config = new WxMaInMemoryConfig(); |
|
|
|
config.setAppid(appinfo.getAppId()); |
|
|
|
config.setSecret(appinfo.getSecret()); |
|
|
|
config.setToken(appinfo.getToken()); |
|
|
|
config.setAesKey(appinfo.getAesKey()); |
|
|
|
config.setMsgDataFormat(appinfo.getMsgDataFormat()); |
|
|
|
|
|
|
|
WxMaService service = new WxMaServiceImpl(); |
|
|
|
service.setWxMaConfig(config); |
|
|
|
WxMaService service = MaUtil.getWeappService(appinfo); |
|
|
|
return service; |
|
|
|
} |
|
|
|
|
|
|
|
public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { |
|
|
|
WxMaInMemoryConfig config = new WxMaInMemoryConfig(); |
|
|
|
config.setAppid(appinfo.getAppId()); |
|
|
|
config.setSecret(appinfo.getSecret()); |
|
|
|
config.setToken(appinfo.getToken()); |
|
|
|
config.setAesKey(appinfo.getAesKey()); |
|
|
|
config.setMsgDataFormat(appinfo.getMsgDataFormat()); |
|
|
|
|
|
|
|
WxMaService service = new WxMaServiceImpl(); |
|
|
|
service.setWxMaConfig(config); |
|
|
|
WxMaService service = MaUtil.getWeappService(appinfo); |
|
|
|
return service; |
|
|
|
} |
|
|
|
} |