|
|
@@ -11,6 +11,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
import com.alipay.api.AlipayClient;
|
|
|
import com.alipay.api.DefaultAlipayClient;
|
|
|
+import com.alipay.api.internal.util.AlipayEncrypt;
|
|
|
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
|
|
import com.alipay.api.request.AlipayUserInfoShareRequest;
|
|
|
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
|
|
@@ -25,6 +26,7 @@ import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.enums.ClientType;
|
|
|
import com.ruoyi.common.enums.ExceptionEnum;
|
|
|
import com.ruoyi.common.enums.InviteType;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
@@ -50,6 +52,7 @@ import com.ruoyi.weixin.config.WxMaProperties;
|
|
|
import com.ruoyi.weixin.domain.WxUserDto;
|
|
|
import com.ruoyi.weixin.service.WxUserService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -67,6 +70,7 @@ import java.util.stream.Collectors;
|
|
|
* @author wuchao
|
|
|
* @date 2022-03-03
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
public class UserServiceImpl implements IUserService {
|
|
|
@@ -248,10 +252,11 @@ public class UserServiceImpl implements IUserService {
|
|
|
public User authorization(WxUserDto wxUserDto) {
|
|
|
String openId = wxUserDto.getOpenId();
|
|
|
|
|
|
- WxMaProperties.Config config = wxMaProperties.getConfigs().get(0);
|
|
|
Integer code = UserThirdType.WX_MINI_PROGRAM.getCode();
|
|
|
- if (!wxUserDto.getAppId().equals(config.getAppid())) {
|
|
|
+ if (ClientType.WECHAT_PAY_MINI_APP.getCode().equals(wxUserDto.getClientType())) {
|
|
|
code = UserThirdType.WX_CASHIER_MINI_PROGRAM.getCode();
|
|
|
+ } else if (ClientType.ALI_PAY_MINI_APP.getCode().equals(wxUserDto.getClientType())) {
|
|
|
+ code = UserThirdType.ALI_MINI_PROGRAM.getCode();
|
|
|
}
|
|
|
//查询此openid是否绑定过用户
|
|
|
UserThirdIdentity userThirdIdentity = userThirdIdentityMapper.selectOne(
|
|
|
@@ -370,20 +375,25 @@ public class UserServiceImpl implements IUserService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getOpenId(String code, String appId) {
|
|
|
- return wxUserService.getOpenIdByCode(code, appId);
|
|
|
+ public String getOpenId(String code, Integer clientType) {
|
|
|
+ if (ClientType.ALI_PAY_MINI_APP.getCode().equals(clientType)) {
|
|
|
+ //支付宝
|
|
|
+ return getAlipayIdByCode(code);
|
|
|
+ }
|
|
|
+ return wxUserService.getOpenIdByCode(code, clientType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public User loginAuthorization(String openId, String appId) {
|
|
|
+ public User loginAuthorization(String openId, Integer clientType) {
|
|
|
if (StringUtils.isEmpty(openId)) {
|
|
|
throw new ServiceException(UserExceptionEnum.USER_THIRD_ID_NOT_EXISTS);
|
|
|
}
|
|
|
//查询此openid是否绑定过用户
|
|
|
- WxMaProperties.Config config = wxMaProperties.getConfigs().get(0);
|
|
|
- Integer code = UserThirdType.WX_MINI_PROGRAM.getCode();
|
|
|
- if (!appId.equals(config.getAppid())) {
|
|
|
- code = UserThirdType.WX_CASHIER_MINI_PROGRAM.getCode();
|
|
|
+ Integer code = UserThirdType.WX_CASHIER_MINI_PROGRAM.getCode();
|
|
|
+ if (ClientType.ALI_PAY_MINI_APP.getCode().equals(clientType)) {
|
|
|
+ code = UserThirdType.ALI_MINI_PROGRAM.getCode();
|
|
|
+ } else if (ClientType.SHOP_MINI_APP.getCode().equals(clientType)) {
|
|
|
+ code = UserThirdType.WX_MINI_PROGRAM.getCode();
|
|
|
}
|
|
|
UserThirdIdentity userThirdIdentity = getUserThirdIdentity(code, openId, null);
|
|
|
if (ObjectUtil.isNull(userThirdIdentity)) {
|
|
|
@@ -674,6 +684,19 @@ public class UserServiceImpl implements IUserService {
|
|
|
return ObjectUtil.isNotNull(user) ? user.getHeadPhoto() : "";
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getPhoneByCode(String encryptedData) {
|
|
|
+ try {
|
|
|
+ String decryptContent = AlipayEncrypt.decryptContent(encryptedData, "AES", aliPayConfig.getAlipayPublicKey(), "utf-8");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(decryptContent);
|
|
|
+ String phone = jsonObject.getString("mobile");
|
|
|
+ return StringUtils.isNotEmpty(phone) ? phone : jsonObject.getString("phoneNumber");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("支付宝解密手机号异常", e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private String generateUniqueMemberCode(Long userId) {
|
|
|
//生成唯一码 用户不会重复 6-8位
|
|
|
String userIdPart = String.valueOf(userId);
|