增加获取微信手机号码

This commit is contained in:
TinyAnts 2022-09-08 11:15:56 +08:00
parent e258f2097a
commit 177907dfe6
3 changed files with 25 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.mdd.front.controller;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.utils.ConfigUtil;
import com.mdd.front.LikeFrontThreadLocal;
@ -61,8 +62,9 @@ public class UserController {
*/
@PostMapping("/mnpMobile")
public Object mnpMobile(@RequestBody Map<String, String> params) {
iUserService.mnpMobile(params);
return AjaxResult.success();
Assert.notNull(params.get("code"), "code参数缺失");
Map<String, Object> map = iUserService.mnpMobile(params.get("code").trim());
return AjaxResult.success(map);
}
}

View File

@ -28,6 +28,13 @@ public interface IUserService {
*/
UserInfoVo info(Integer userId);
void mnpMobile(Map<String, String> params);
/**
* 微信手机
*
* @author fzr
* @param code 获取手机号的Code
* @return Map<String, Object>
*/
Map<String, Object> mnpMobile(String code);
}

View File

@ -10,6 +10,7 @@ import com.mdd.common.entity.system.SystemConfig;
import com.mdd.common.entity.user.User;
import com.mdd.common.entity.user.UserAuth;
import com.mdd.common.enums.ClientEnum;
import com.mdd.common.exception.OperateException;
import com.mdd.common.mapper.system.SystemConfigMapper;
import com.mdd.common.mapper.user.UserAuthMapper;
import com.mdd.common.mapper.user.UserMapper;
@ -24,6 +25,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.Map;
/**
@ -104,9 +106,13 @@ public class UserServiceImpl implements IUserService {
/**
* 微信手机号
*
* @author fzr
* @param code 获取手机号的Code
* @return Map<String, Object>
*/
@Override
public void mnpMobile(Map<String, String> params) {
public Map<String, Object> mnpMobile(String code) {
Map<String, String> config = ConfigUtil.get("mp_channel");
WxMaService wxMaService = new WxMaServiceImpl();
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
@ -115,17 +121,15 @@ public class UserServiceImpl implements IUserService {
wxMaService.setWxMaConfig(wxConfig);
try {
// String sessionKey = "";
// String encryptedData = params.get("encryptedData");
// String ivStr = params.get("iv");
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxMaService.getUserService()
.getNewPhoneNoInfo("0330FG000I3kwO1Ui81000ZRkr00FG0Y");
System.out.println(wxMaPhoneNumberInfo);
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxMaService.getUserService().getNewPhoneNoInfo(code);
Map<String, Object> response = new LinkedHashMap<>();
response.put("countryCode", wxMaPhoneNumberInfo.getCountryCode());
response.put("phoneNumber", wxMaPhoneNumberInfo.getPhoneNumber());
return response;
} catch (WxErrorException e) {
System.out.println(e.getError());
throw new OperateException(e.getError().getErrorCode() + ", " + e.getError().getErrorMsg());
}
}
}